Title: | Analysis of Music and Speech |
---|---|
Description: | Analyze music and speech, extract features like MFCCs, handle wave files and their representation in various ways, read mp3, read midi, perform steps of a transcription, ... Also contains functions ported from the 'rastamat' 'Matlab' package. |
Authors: | Uwe Ligges [aut, cre, cph] , Sebastian Krey [aut, cph], Olaf Mersmann [aut, cph], Sarah Schnackenberg [aut, cph], Guillaume Guénard [aut, cph] (for the 'pulse' functionality), Daniel P. W. Ellis [aut, cph] (functions ported from 'rastamat'), Underbit Technologies [aut, cph] (for the included 'libmad MPEG audio decoder library'), Andrea Preusser [ctb], Anita Thieler [ctb], Johanna Mielke [ctb], Claus Weihs [ctb], Brian D. Ripley [ctb], Matthias Heymann [ctb] (for ideas from the former 'sound' package) |
Maintainer: | Uwe Ligges <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 1.4.7 |
Built: | 2024-11-17 04:39:32 UTC |
Source: | https://github.com/r-forge/tuner |
Operators act on objects to extract or replace subsets.
Extract for the S3 generic.
Methods for arithmetics on Wave and WaveMC objects
An object of class Wave
.
An object of class WaveMC
.
For, e.g., adding a number to the whole Wave, e.g. useful for demeaning.
For unary Wave operations.
Uwe Ligges [email protected]
For the S3 generic: groupGeneric
, Wave-class, Wave
, WaveMC-class, WaveMC
Perform critical band analysis (see PLP), which means the reduction of the fourier frequencies of a signal's powerspectrum to a reduced number of frequency bands in an auditory frequency scale.
audspec(pspectrum, sr = 16000, nfilts = ceiling(hz2bark(sr/2)) + 1, fbtype = c("bark", "mel", "htkmel", "fcmel"), minfreq = 0, maxfreq = sr/2, sumpower = TRUE, bwidth = 1)
audspec(pspectrum, sr = 16000, nfilts = ceiling(hz2bark(sr/2)) + 1, fbtype = c("bark", "mel", "htkmel", "fcmel"), minfreq = 0, maxfreq = sr/2, sumpower = TRUE, bwidth = 1)
pspectrum |
Output of |
sr |
Sample rate of the original recording. |
nfilts |
Number of filters/frequency bins in the auditory frequency scale. |
fbtype |
Used auditory frequency scale. |
minfreq |
Lowest frequency. |
maxfreq |
Highest frequency. |
sumpower |
If |
bwidth |
Modify the width of the frequency bands. |
aspectrum |
Matrix with the auditory spectrum of each time frame in its columns. |
wts |
Weight matrix for the frequency band conversion. |
Sebastian Krey [email protected]
Daniel P. W. Ellis: https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, [email protected]) aspectrum <- audspec(pspectrum, [email protected])
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, testsound@samp.rate) aspectrum <- audspec(pspectrum, testsound@samp.rate)
Generic function for concatenating objects of class Wave
or WaveMC
.
bind(object, ...) ## S4 method for signature 'Wave' bind(object, ...) ## S4 method for signature 'WaveMC' bind(object, ...)
bind(object, ...) ## S4 method for signature 'Wave' bind(object, ...) ## S4 method for signature 'WaveMC' bind(object, ...)
object , ...
|
Objects of class |
An object of class Wave
or class WaveMC
that corresponds to the class of the input.
Uwe Ligges [email protected], Sarah Schnackenberg
prepComb
for preparing the concatenation, Wave-class,
Wave
, WaveMC-class, WaveMC
, extractWave
, stereo
Convenient wrapper to extract one or more channels (or mirror channels) from an object of class Wave
.
channel(object, which = c("both", "left", "right", "mirror"))
channel(object, which = c("both", "left", "right", "mirror"))
object |
Object of class |
which |
Character indicating which channel(s) should be returned. |
For objects of WaveMC-class, channel selection can be performed by simple matrix indexing, e.g. WaveMCobject[,2]
selects the second channel.
Wave
object including channels specified by which
.
Uwe Ligges [email protected]
Wave
, Wave-class, mono
, extractWave
Calculate the deltas (derivatives) of a sequence of features using a w-point window with a simple linear slope.
deltas(x, w = 9)
deltas(x, w = 9)
x |
Matrix of features. Every column represents one time frame. Each row is filtered separately. |
w |
Window width (usually odd). |
This function mirrors the delta calculation performed in HTKs ‘feacalc’.
Returns a matrix of the delta features (one column per frame).
Sebastian Krey [email protected]
Daniel P. W. Ellis: https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") m <- melfcc(testsound, frames_in_rows=FALSE) d <- deltas(m)
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") m <- melfcc(testsound, frames_in_rows=FALSE) d <- deltas(m)
Compute autoregressive model from spectral magnitude samples via Levinson-Durbin recursion.
dolpc(x, modelorder = 8)
dolpc(x, modelorder = 8)
x |
Matrix of spectral magnitude samples (each sample/time frame in one column). |
modelorder |
Lag of the AR model. |
Returns a matrix of the normalized AR coefficients (depending on the input spectrum: LPC or PLP coefficients). Every column represents one time frame.
Sebastian Krey [email protected]
Daniel P. W. Ellis: https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, [email protected]) aspectrum <- audspec(pspectrum, [email protected])$aspectrum lpcas <- dolpc(aspectrum, 10)
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, testsound@samp.rate) aspectrum <- audspec(pspectrum, testsound@samp.rate)$aspectrum lpcas <- dolpc(aspectrum, 10)
Downsampling an object of class Wave
or class WaveMC
.
downsample(object, samp.rate)
downsample(object, samp.rate)
object |
|
samp.rate |
Sampling rate the object is to be downsampled to.
|
An object of class Wave
or class WaveMC
.
Uwe Ligges [email protected]
Wave-class, Wave
, WaveMC-class, WaveMC
Internal S4 generic function that checks for some kind of equality of objects of class Wave
or class WaveMC
.
equalWave(object1, object2)
equalWave(object1, object2)
object1 , object2
|
Object(s) of class |
Does not return anything.
It stop
s code execution with an error message indicating the problem
if the objects are not of the same class (either Wave
oder WaveMC
) or if
the two objects don't have the same properties, i.e.
identical sampling rate, resolution (bit), and number of channels (for WaveMC
, resp. stereo/mono for Wave
).
Uwe Ligges [email protected], Sarah Schnackenberg
Wave-class, Wave
, WaveMC-class, WaveMC
Extractor function that allows to extract inner parts for Wave
or WaveMC
objects (interactively).
extractWave(object, from = 1, to = length(object), interact = interactive(), xunit = c("samples", "time"), ...)
extractWave(object, from = 1, to = length(object), interact = interactive(), xunit = c("samples", "time"), ...)
object |
|
from |
Sample number or time in seconds (see |
to |
Sample number or time in seconds (see |
interact |
Logical indicating whether to choose the range to be extracted interactively (if |
xunit |
Character indicating which units are used to specify the range to be extracted
(both in arguments |
... |
Parameters to be passed to the underlying plot function ( |
This function allows interactive selection of a range to be extracted from an object of class Wave
or class WaveMC
.
The default is to use interactive selection if the current R session is interactive
.
In case of interactive selection, plot-methods
plot the Wave
or WaveMC
object,
and the user may click on the starting and ending points of his selection (given neither from
nor to
have been specified, see below).
The cut-points are drawn and the corresponding selection will be returned in form of a Wave
or WaveMC
object.
Setting interact = TRUE
in a non-interactive session does not work.
Setting arguments from
or to
explicitly means that the specified one
does not need to be selected interactively, hence only the non-specified one will be selected interactively.
Moreover, setting both from
or to
implies interact = FALSE
.
An object of class Wave
or class WaveMC
.
Uwe Ligges [email protected], Sarah Schnackenberg
Wave-class, Wave
, WaveMC-class, WaveMC
, bind
, channel
, mono
Wobj <- sine(440) # extracting the middle 0.5 seconds of that 1 sec. sound: Wobj2 <- extractWave(Wobj, from = 0.25, to = 0.75, xunit = "time") Wobj2 ## Not run: # or interactively: Wobj2 <- extractWave(Wobj) ## End(Not run)
Wobj <- sine(440) # extracting the middle 0.5 seconds of that 1 sec. sound: Wobj2 <- extractWave(Wobj, from = 0.25, to = 0.75, xunit = "time") Wobj2 ## Not run: # or interactively: Wobj2 <- extractWave(Wobj) ## End(Not run)
Estimation of Fundamental Frequencies from an object of class Wspec
.
Additionally, some heuristics are used to distinguish silence, noise (and breathing for singers)
from real tones.
FF(object, peakheight = 0.01, silence = 0.2, minpeak = 9, diapason = 440, notes = NULL, interest.frqs = seq(along = object@freq), search.par = c(0.8, 10, 1.3, 1.7)) FFpure(object, peakheight = 0.01, diapason = 440, notes = NULL, interest.frqs = seq(along = object@freq), search.par = c(0.8, 10, 1.3, 1.7))
FF(object, peakheight = 0.01, silence = 0.2, minpeak = 9, diapason = 440, notes = NULL, interest.frqs = seq(along = object@freq), search.par = c(0.8, 10, 1.3, 1.7)) FFpure(object, peakheight = 0.01, diapason = 440, notes = NULL, interest.frqs = seq(along = object@freq), search.par = c(0.8, 10, 1.3, 1.7))
object |
An object of class |
peakheight |
The peak's proportion of the maximal peak height to be considered for fundamental frequency detection. The default (0.01) means peaks smaller than 0.02 times the maximal peak height are omitted. |
silence |
The maximum proportion of periodograms to be considered as silence or noise (such as breathing). The default (0.2) means that less than 20 out of 100 periodograms represent silence or noise. |
minpeak |
If more than |
diapason |
Frequency of diapason a, default is 440 (Hertz). |
notes |
Optional, a vector of integers indicating the notes (in halftones from diapason a) that are expected. By applying this restriction, the “detection error” might be reduced in some cases. |
interest.frqs |
Optional, either a vector of integers indicating the
indices of (fundamental) frequencies in By applying this restriction, the “detection error” might be reduced in some cases. |
search.par |
Parameters to look for peaks:
|
FFpure
just estimates the fundamental frequencies for all periodograms contained in the
object
(of class Wspec
).
FF
additionally uses some heuristics to distinguish silence, noise (and breathing for singers)
from real tones. It is recommended to use the wrapper function FF
rather than FFpure
.
If silence detecion can be omitted by specifying silence = 0
.
Vector of estimated fundamental frequencies (in Hertz) for each periodogram conatined in object
.
These functions are still in development and may be changed in due course.
Uwe Ligges [email protected]
Wspec
, periodogram
(including an example), noteFromFF
,
and tuneR for a very complete example.
Perform frequency scale conversions between Hertz, Bark- and different variants von the Melscale.
bark2hz(z) hz2bark(f) hz2mel(f, htk = FALSE) mel2hz(z, htk = FALSE)
bark2hz(z) hz2bark(f) hz2mel(f, htk = FALSE) mel2hz(z, htk = FALSE)
f |
Frequency in Hertz |
z |
Frequency in the auditory frequency scale |
htk |
Use the HTK-Melscale ( |
The value of the input in the target frequency scale.
Sebastian Krey [email protected]
Daniel P. W. Ellis: https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/, Malcolm Slaney: Auditory Toolbox
hz2bark(440) bark2hz(hz2bark(440)) hz2mel(440, htk = TRUE) mel2hz(hz2mel(440, htk = TRUE), htk = TRUE) hz2mel(440, htk = FALSE) mel2hz(hz2mel(440, htk = FALSE), htk = FALSE)
hz2bark(440) bark2hz(hz2bark(440)) hz2mel(440, htk = TRUE) mel2hz(hz2mel(440, htk = TRUE), htk = TRUE) hz2mel(440, htk = FALSE) mel2hz(hz2mel(440, htk = FALSE), htk = FALSE)
Extract only note events from an object returned by the readMidi
function.
getMidiNotes(x, ...)
getMidiNotes(x, ...)
x |
A data.frame returned by the |
... |
Further arguments are passed to the |
A data frame with columns
time |
start time |
length |
length |
track |
track number |
channel |
channel number |
note |
note |
notename |
notename |
velocity |
note velocity |
Uwe Ligges and Johanna Mielke
content <- readMidi(system.file("example_files", "Bass_sample.mid", package="tuneR")) getMidiNotes(content)
content <- readMidi(system.file("example_files", "Bass_sample.mid", package="tuneR")) getMidiNotes(content)
S4 generic for length.
The length of the left channel (in samples) of this object of class Wave
will be returned.
The length for each of the time series in the WaveMC
will be returned.
For compatibility.
For the primitive: length
Apply liftering to a matrix of cepstra.
lifter(x, lift = 0.6, inv = FALSE, htk = FALSE)
lifter(x, lift = 0.6, inv = FALSE, htk = FALSE)
x |
Matrix of cepstra, one sample/time frame per column. |
lift |
Liftering exponent/length. |
inv |
Invert the liftering (undo a previous liftering). |
htk |
Switch liftering type. |
If htk = FALSE
, then perform ,
nrow(x)
liftering. If htk = TRUE
, then perform HTK-style sin-curve
liftering with length lift
.
Matrix of the liftered cepstra.
Sebastian Krey [email protected]
Daniel P. W. Ellis: https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") m <- melfcc(testsound, frames_in_rows=FALSE) unlm <- lifter(m, inv=TRUE)
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") m <- melfcc(testsound, frames_in_rows=FALSE) unlm <- lifter(m, inv=TRUE)
A function (in development!) that writes a file to be processed by LilyPond by extracting the relevant information (e.g. pitch, length, ...) from columns of a data frame. The music notation software LilyPond can “transcribe” such an input file into sheet music.
lilyinput(X, file = "Rsong.ly", Major = TRUE, key = "c", clef = c("treble", "bass", "alto", "tenor"), time = "4/4", endbar = TRUE, midi = TRUE, tempo = "2 = 60", textheight = 220, linewidth = 150, indent = 0, fontsize = 14)
lilyinput(X, file = "Rsong.ly", Major = TRUE, key = "c", clef = c("treble", "bass", "alto", "tenor"), time = "4/4", endbar = TRUE, midi = TRUE, tempo = "2 = 60", textheight = 220, linewidth = 150, indent = 0, fontsize = 14)
X |
A data frame containing 4 named components (columns):
|
file |
The file to be written for LilyPond's input. |
Major |
Logical indicating major key (if |
key |
Keynote, necessary to set sharps/flats. |
clef |
Integer indicating the kind of clef, supported are |
time |
Character indicating which meter to use, examples are: |
endbar |
Logical indicating whether to set an ending bar at the end of the sheet music. |
midi |
Logical indicating whether Midi output (by LilyPond) is desirable. |
tempo |
Character specifying the tempo to be used for the Midi file if |
textheight |
Textheight of the sheet music to be written by LilyPond. |
linewidth |
Linewidth of the sheet music to be written by LilyPond. |
indent |
Indentation of the sheet music to be written by LilyPond. |
fontsize |
Fontsize of the sheet music to be written by LilyPond. |
Details will be given when development has reached a stable stage ...!
Nothing is returned, but a file
is written.
This function is in development!!!
Everything (and in particular its user interface) is subject to change!!!
Andrea Preußer and Uwe Ligges [email protected]
The LilyPond development team (2005): LilyPond - The music typesetter. https://lilypond.org/, Version 2.7.20.
Preußer, A., Ligges, U. und Weihs, C. (2002): Ein R Exportfilter für das Notations- und Midi-Programm LilyPond. Arbeitsbericht 35. Fachbereich Statistik, Universität Dortmund. (german)
quantMerge
prepares the data to be written into the LilyPond format;
quantize
and quantplot
generate another kind of plot;
and exhaustive example is given in tuneR.
Convert the LPC coefficients in each column of a
into frames of cepstra.
lpc2cep(a, nout = nrow(a))
lpc2cep(a, nout = nrow(a))
a |
Matrix of LPC coefficients. |
nout |
Number of cepstra to produce. |
Matrix of cepstra (one column per time frame).
Sebastian Krey [email protected]
Daniel P. W. Ellis: https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, [email protected]) aspectrum <- audspec(pspectrum, [email protected]) lpcas <- dolpc(aspectrum$aspectrum, 8) cepstra <- lpc2cep(lpcas)
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, testsound@samp.rate) aspectrum <- audspec(pspectrum, testsound@samp.rate) lpcas <- dolpc(aspectrum$aspectrum, 8) cepstra <- lpc2cep(lpcas)
A data frame representing the default channel ordering with id, descriptive label, and abbreviated name for multi channel wave files.
A data frame with 18 observations on the following 3 variables:
id
id of the channel
label
full label for the channel
name
abbreviated name for the channel
Data derived from the technical documentation given at https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ksmedia/ns-ksmedia-waveformatextensible.
Microsoft Corporation (2018): WAVEFORMATEXTENSIBLE structure, https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ksmedia/ns-ksmedia-waveformatextensible.
MCnames # the 18 predefined channels in a multi channel Wave file (WaveMC object)
MCnames # the 18 predefined channels in a multi channel Wave file (WaveMC object)
Calculate Mel-frequency cepstral coefficients.
melfcc(samples, sr = [email protected], wintime = 0.025, hoptime = 0.01, numcep = 12, lifterexp = 0.6, htklifter = FALSE, sumpower = TRUE, preemph = 0.97, dither = FALSE, minfreq = 0, maxfreq = sr/2, nbands = 40, bwidth = 1, dcttype = c("t2", "t1", "t3", "t4"), fbtype = c("mel", "htkmel", "fcmel", "bark"), usecmp = FALSE, modelorder = NULL, spec_out = FALSE, frames_in_rows = TRUE)
melfcc(samples, sr = samples@samp.rate, wintime = 0.025, hoptime = 0.01, numcep = 12, lifterexp = 0.6, htklifter = FALSE, sumpower = TRUE, preemph = 0.97, dither = FALSE, minfreq = 0, maxfreq = sr/2, nbands = 40, bwidth = 1, dcttype = c("t2", "t1", "t3", "t4"), fbtype = c("mel", "htkmel", "fcmel", "bark"), usecmp = FALSE, modelorder = NULL, spec_out = FALSE, frames_in_rows = TRUE)
samples |
Object of Wave-class or WaveMC-class. Only the first channel will be used. |
sr |
Sampling rate of the signal. |
wintime |
Window length in sec. |
hoptime |
Step between successive windows in sec. |
numcep |
Number of cepstra to return. |
lifterexp |
Exponent for liftering; 0 = none. |
htklifter |
Use HTK sin lifter. |
sumpower |
If |
preemph |
Apply pre-emphasis filter [1 -preemph] (0 = none). |
dither |
Add offset to spectrum as if dither noise. |
minfreq |
Lowest band edge of mel filters (Hz). |
maxfreq |
Highest band edge of mel filters (Hz). |
nbands |
Number of warped spectral bands to use. |
bwidth |
Width of spectral bands in Bark/Mel. |
dcttype |
Type of DCT used - 1 or 2 (or 3 for HTK or 4 for feacalc). |
fbtype |
Auditory frequency scale to use: |
usecmp |
Apply equal-loudness weighting and cube-root compression (PLP instead of LPC). |
modelorder |
If |
spec_out |
Should matrices of the power- and the auditory-spectrum be returned. |
frames_in_rows |
Return time frames in rows instead of columns (original Matlab code). |
Calculation of the MFCCs imlcudes the following steps:
Preemphasis filtering
Take the absolute value of the STFT (usage of Hamming window)
Warp to auditory frequency scale (Mel/Bark)
Take the DCT of the log-auditory-spectrum
Return the first ‘ncep’ components
cepstra |
Cepstral coefficients of the input signal (one time frame per row/column) |
aspectrum |
Auditory spectrum (spectrum after transformation to Mel/Bark scale) of the signal |
pspectrum |
Power spectrum of the input signal. |
lpcas |
If |
The following non-default values nearly duplicate Malcolm Slaney's mfcc (i.e.
melfcc(d, 16000, wintime=0.016, lifterexp=0, minfreq=133.33, maxfreq=6855.6, sumpower=FALSE)
=~= log(10) * 2 * mfcc(d, 16000)
in the Auditory toolbox for Matlab).
The following non-default values nearly duplicate HTK's MFCC (i.e.
melfcc(d, 16000, lifterexp=22, htklifter=TRUE, nbands=20, maxfreq=8000, sumpower=FALSE, fbtype="htkmel", dcttype="t3")
=~= 2 * htkmelfcc(:,[13,[1:12]])
where HTK config has ‘PREEMCOEF = 0.97’, ‘NUMCHANS = 20’,
‘CEPLIFTER = 22’, ‘NUMCEPS = 12’, ‘WINDOWSIZE = 250000.0’, ‘USEHAMMING = T’,
‘TARGETKIND = MFCC_0’).
For more detail on reproducing other programs' outputs, see https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/mfccs.html
Sebastian Krey [email protected]
Daniel P. W. Ellis: https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") m1 <- melfcc(testsound) #Use PLP features to calculate cepstra and output the matrices like the #original Matlab code (note: modelorder limits the number of cepstra) m2 <- melfcc(testsound, numcep=9, usecmp=TRUE, modelorder=8, spec_out=TRUE, frames_in_rows=FALSE)
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") m1 <- melfcc(testsound) #Use PLP features to calculate cepstra and output the matrices like the #original Matlab code (note: modelorder limits the number of cepstra) m2 <- melfcc(testsound, numcep=9, usecmp=TRUE, modelorder=8, spec_out=TRUE, frames_in_rows=FALSE)
Plot a observed melody and (optional) an expected melody, as well as corresponding energy values (corresponding to the loudness of the sound).
melodyplot(object, observed, expected = NULL, bars = NULL, main = NULL, xlab = NULL, ylab = "note", xlim = NULL, ylim = NULL, observedtype = "l", observedcol = "red", expectedcol = "grey", gridcol = "grey", lwd = 2, las = 1, cex.axis = 0.9, mar = c(5, 4, 4, 4) + 0.1, notenames = NULL, thin = 1, silence = "silence", plotenergy = TRUE, ..., axispar = list(ax1 = list(side=1), ax2 = list(side=2), ax4 = list(side=4)), boxpar = list(), energylabel = list(text="energy", side=4, line=2.5, at=rg.s-0.25, las=3), energypar = list(), expectedpar = list(), gridpar = list(col=gridcol), observedpar = list(col=observedcol, type=observedtype, lwd=2, pch=15))
melodyplot(object, observed, expected = NULL, bars = NULL, main = NULL, xlab = NULL, ylab = "note", xlim = NULL, ylim = NULL, observedtype = "l", observedcol = "red", expectedcol = "grey", gridcol = "grey", lwd = 2, las = 1, cex.axis = 0.9, mar = c(5, 4, 4, 4) + 0.1, notenames = NULL, thin = 1, silence = "silence", plotenergy = TRUE, ..., axispar = list(ax1 = list(side=1), ax2 = list(side=2), ax4 = list(side=4)), boxpar = list(), energylabel = list(text="energy", side=4, line=2.5, at=rg.s-0.25, las=3), energypar = list(), expectedpar = list(), gridpar = list(col=gridcol), observedpar = list(col=observedcol, type=observedtype, lwd=2, pch=15))
object |
An object of class |
observed |
Observed notes, probably as a result from |
expected |
Expected notes (optional; in order to compare results), same format as |
bars |
Number of bars to be plotted (a virtual static segmentation takes place).
If |
main |
Main title of the plot. |
xlab , ylab
|
Annotation of -/y-axes. |
xlim , ylim
|
Range of x-/y-axis, where |
observedtype |
Type (either |
observedcol |
Colour for the observed melody. |
expectedcol |
Colour for the expected melody. |
gridcol |
Colour of the grid. |
lwd |
Line width, see |
las |
Orientation of axis labels, see |
cex.axis |
Size of tick mark labels, see |
mar |
Margins of the plot, see |
notenames |
Optionally specify other notenames (character) for the y axis. |
thin |
Amount of thinning of notenames, i.e. only each |
silence |
Character string for label of the ‘silence’ (default) axis. |
plotenergy |
Logical (default: |
... |
Additional graphical parameters to be passed to underlying |
axispar |
A named list of three other lists ( |
boxpar |
A list of parameters to be passed to the box generating functions. |
energylabel |
A list of parameters to be passed to the energy-label
generating |
energypar |
A list of parameters to be passed to the |
expectedpar |
A list of parameters to be passed to the |
gridpar |
A list of parameters to be passed to the |
observedpar |
A list of parameters to be passed to the |
Uwe Ligges [email protected]
noteFromFF
, FF
, quantplot
;
for an example, see the help in tuneR.
Functions to extract a channel from a stereo Wave
object,
and to join channels of two monophonic Wave
objects to a stereophonic one.
mono(object, which = c("left", "right", "both")) stereo(left, right)
mono(object, which = c("left", "right", "both")) stereo(left, right)
object |
Object of class |
which |
Character, indicating whether the “left” or “right” channel should be extracted, or whether “both” channels should be averaged. |
left |
Object of class |
right |
Object of class |
For objects of WaveMC-class, a mono channel can be created by simple matrix indexing, e.g. WaveMCobject[,2]
selects the second channel.
An object of class Wave
.
If argument right
is missing in stereo
, a logical values is returned
that indicates whether left
is stereo (TRUE
) or mono (FALSE
).
Uwe Ligges [email protected]
Wobj <- sine(440) Wobj Wobj2 <- stereo(Wobj, Wobj) Wobj2 mono(Wobj2, "right")
Wobj <- sine(440) Wobj Wobj2 <- stereo(Wobj, Wobj) Wobj2 mono(Wobj2, "right")
Get the number of channels from a Wave or WaveMC object
nchannel(object) ## S4 method for signature 'Wave' nchannel(object) ## S4 method for signature 'WaveMC' nchannel(object)
nchannel(object) ## S4 method for signature 'Wave' nchannel(object) ## S4 method for signature 'WaveMC' nchannel(object)
object |
An integer, the number of channels given in the object.
Centering and rescaling the waveform of a Wave
or WaveMC
object to a canonical interval
corresponding to the Wave format (e.g. [-1, 1], [0, 254],
[-32767, 32767], [-8388607, 8388607], or [-2147483647, 2147483647]).
normalize(object, unit = c("1", "8", "16", "24", "32", "64", "0"), center = TRUE, level = 1, rescale = TRUE, pcm = object@pcm)
normalize(object, unit = c("1", "8", "16", "24", "32", "64", "0"), center = TRUE, level = 1, rescale = TRUE, pcm = object@pcm)
object |
|
unit |
Unit to rescale to. |
center |
If |
level |
Maximal percentage of the amplitude used for normalizing (default is 1). |
rescale |
Logical, whether to rescale to the maximal possible dynamic range. |
pcm |
Logical. By default, the |
An object containing the normalized data of the same class as the input object
,
i.e. either Wave
or WaveMC
.
Uwe Ligges [email protected], Sarah Schnackenberg, based on code from Matthias Heymann's former package ‘sound’.
writeWave
, Wave-class, Wave
, WaveMC-class, WaveMC
Generic function to cut off silence or low noise at the beginning and/or at the end of an object of class Wave
or class WaveMC
.
noSilence(object, zero = 0, level = 0, where = c("both", "start", "end"))
noSilence(object, zero = 0, level = 0, where = c("both", "start", "end"))
object |
|
zero |
The zero level (default: 0) at which ideal cut points are determined (see Details).
A typical alternative would be 127 for 8 bit |
level |
Values in the interval between |
where |
One of |
Silcence is removed at the locations given by where
of the Wave
or WaveMC
object,
where silence is defined such that (in both channels if stereo, in all channels if multichannel for WaveMC
) all values are in
the interval between zero - level
and zero + level
.
All values before (or after, respectively) the first non-silent value are removed from the object.
An object of class Wave
or WaveMC
.
Uwe Ligges [email protected], Sarah Schnackenberg, based on code from Matthias Heymann's former package ‘sound’.
silence
, Wave-class, Wave
, WaveMC-class, WaveMC
, extractWave
Deriving notes from given (fundamental) frequencies.
noteFromFF(x, diapason = 440, roundshift = 0)
noteFromFF(x, diapason = 440, roundshift = 0)
x |
Fundamental frequency. |
diapason |
Frequency of diapason a, default is 440 (Hertz). |
roundshift |
Shift that indicates from here to round to the next integer (note).
The default (0) is “classical” rounding as described in Example: if |
The formula used is simply round(12 * log(x / diapason, 2) + roundshift)
.
An integer representing the (rounded) difference in halftones from diapason a,
i.e. indicating the note that corresponds to fundamental frequency x
given the value of diapason
.
For example: 0 indicates diapason a, 3: c', 12: a', ...
Uwe Ligges [email protected]
FF
, periodogram
, and tuneR for a very complete example.
A function that generates note names from numbers
notenames(notes, language = c("english", "german"))
notenames(notes, language = c("english", "german"))
notes |
An interger values vector, where 0 corresponds to a', notes below and above have to be specified in the corresponding halftone distance. |
language |
Language of the note names. Currently only english and german are supported. |
A character vector of note names.
Uwe Ligges [email protected]
notenames(c(-24, -12, 0, 12)) # octaves of a notenames(3:15) # chromaticism ## same in german: notenames(3:15, language = "german")
notenames(c(-24, -12, 0, 12)) # octaves of a notenames(3:15) # chromaticism ## same in german: notenames(3:15, language = "german")
Generic function to narrow the panorama of a stereo Wave
or WaveMC
object.
panorama(object, pan = 1)
panorama(object, pan = 1)
object |
|
pan |
Value in [-1,1] to narrow the panorama, see the Details below. The default (1) does not change anything. |
If abs(pan) < 1
, mixtures of the two channels of the Wave
or WaveMC
objects
are used for the left and the right channel of the returned Sample object if the object is of class Wave
, resp.
for the first and second channel of the returned Sample object if the object is of class WaveMC
,
so that they appear closer to the center.
For pan = 0
, both sounds are completely in the center (i.e. averaged).
If pan < 0
, the left and the right channel (for Wave
objects, the first and the second channel for WaveMC
objects) are interchanged.
An object of class Wave
or class WaveMC
with the transformed panorama.
Uwe Ligges [email protected], Sarah Schnackenberg, based on code by Matthias Heymann
Wave-class, Wave
, WaveMC-class, WaveMC
This function estimates one or more periodograms (spectral densities)
of the time series contained in an object of class Wave
or WaveMC
(or directly in a Wave file)
using a window running through the time series (possibly with overlapping).
It returns an object of class Wspec
.
periodogram(object, ...) ## S4 method for signature 'WaveGeneral' periodogram(object, width = length(object), overlap = 0, starts = NULL, ends = NULL, taper = 0, normalize = TRUE, frqRange = c(-Inf, Inf), ...) ## S4 method for signature 'character' periodogram(object, width, overlap = 0, from = 1, to = Inf, units = c("samples", "seconds", "minutes", "hours"), downsample = NA, channel = c("left", "right"), pieces = 1, ...)
periodogram(object, ...) ## S4 method for signature 'WaveGeneral' periodogram(object, width = length(object), overlap = 0, starts = NULL, ends = NULL, taper = 0, normalize = TRUE, frqRange = c(-Inf, Inf), ...) ## S4 method for signature 'character' periodogram(object, width, overlap = 0, from = 1, to = Inf, units = c("samples", "seconds", "minutes", "hours"), downsample = NA, channel = c("left", "right"), pieces = 1, ...)
object |
An object of class |
width |
A window of width ‘ |
overlap |
The window can be applied by each overlapping |
starts |
Start number (in samples) for a window.
If not given, this value is derived from argument |
ends |
End number (in samples) for a window.
If not given, this value is derived from argument |
taper |
proportion of data to taper. See |
normalize |
Logical; if |
frqRange |
Numeric vector of two elements indicating minimum and maximum of the frequency range that is to be stored in the resulting object. This is useful to reduce memory consumption. |
from |
Where to start reading in the Wave file, in |
to |
Where to stop reading in the Wave file, in |
units |
Units in which |
downsample |
Sampling rate the object is to be downsampled to.
If |
channel |
Character, indicating whether the “left” or “right” channel should be extracted
(see |
pieces |
The Wave file will be read in in |
... |
Further arguments to be passed to the underlying function |
An object of class Wspec
is returned containing the following slots.
freq |
Vector of frequencies at which the spectral density is estimated.
See |
spec |
List of vectors or matrices of the |
kernel |
The kernel argument, or the kernel constructed from spans returned by |
df |
The distribution of the spectral density estimate can be approximated by a chi square distribution with
|
taper |
The value of the |
width |
The value of the |
overlap |
The value of the |
normalize |
The value of the |
starts |
If the argument |
stereo |
Always |
samp.rate |
|
variance |
The variance of samples in each window, corresponding to amplitude / loudness of sound. |
energy |
The “energy”
where |
Those slots marked with “(1)” contain the information once, because it is unique for all periodograms of estimated by the function call.
Support for processing more than one channel of Wave
or WaveMC
objects has not yet been implemented.
Uwe Ligges [email protected]
for the resulting objects' class: Wspec
,
for plotting: plot-Wspec
,
for the underlying periodogram calculations: spec.pgram
,
for the input data class: Wave-class, Wave
, WaveMC-class, WaveMC
.
# constructing a Wave object (1 sec.) containing sinus sound with 440Hz: Wobj <- sine(440) Wobj # Calculate periodograms in windows of 4096 samples each - without # any overlap - resulting in an Wspec object that is printed: Wspecobj <- periodogram(Wobj, width = 4096) Wspecobj # Plot the first periodogram from Wspecobj: plot(Wspecobj) # Plot the third one and choose a reasonable xlim: plot(Wspecobj, which = 3, xlim = c(0, 1000)) # Mark frequency that has been generated before: abline(v = 440, col="red") # plot the spectrogram image(Wspecobj, ylim=c(0, 2000)) # same again with normalize = FALSE and with logarithmic y-axis plotted: Wspecobj2 <- periodogram(Wobj, width = 4096, normalize = FALSE) Wspecobj2 plot(Wspecobj2, which = 3, xlim = c(0, 1000), log="y") abline(v = 440, col="red") image(Wspecobj2, ylim=c(0, 2000), log="z") FF(Wspecobj) # all ~ 440 Hertz noteFromFF(FF(Wspecobj)) # all diapason a
# constructing a Wave object (1 sec.) containing sinus sound with 440Hz: Wobj <- sine(440) Wobj # Calculate periodograms in windows of 4096 samples each - without # any overlap - resulting in an Wspec object that is printed: Wspecobj <- periodogram(Wobj, width = 4096) Wspecobj # Plot the first periodogram from Wspecobj: plot(Wspecobj) # Plot the third one and choose a reasonable xlim: plot(Wspecobj, which = 3, xlim = c(0, 1000)) # Mark frequency that has been generated before: abline(v = 440, col="red") # plot the spectrogram image(Wspecobj, ylim=c(0, 2000)) # same again with normalize = FALSE and with logarithmic y-axis plotted: Wspecobj2 <- periodogram(Wobj, width = 4096, normalize = FALSE) Wspecobj2 plot(Wspecobj2, which = 3, xlim = c(0, 1000), log="y") abline(v = 440, col="red") image(Wspecobj2, ylim=c(0, 2000), log="z") FF(Wspecobj) # all ~ 440 Hertz noteFromFF(FF(Wspecobj)) # all diapason a
Plays wave files and objects of class Wave
.
play(object, player, ...)
play(object, player, ...)
object |
Either a filename pointing to a Wave file,
or an object of class |
player |
(Path to) a program capable of playing a wave file by invocation from the command line. If under Windows and no player is given, “mplay32.exe” or “wmplayer.exe” (if the former does not exists as under Windows 7) will be chosen as the default. |
... |
Further arguments passed to the Wave file |
Uwe Ligges [email protected]
Wave-class, WaveMC-class, Wave
, WaveMC
, writeWave
, setWavPlayer
Plotting objects of class Wave
.
## S4 method for signature 'Wave,missing' plot(x, info = FALSE, xunit = c("time", "samples"), ylim = NULL, main = NULL, sub = NULL, xlab = NULL, ylab = NULL, simplify = TRUE, nr = 2500, axes = TRUE, yaxt = par("yaxt"), las = 1, center = TRUE, ...) ## S4 method for signature 'WaveMC,missing' plot(x, info = FALSE, xunit = c("time", "samples"), ylim = NULL, main = NULL, sub = NULL, xlab = NULL, ylab = colnames(x), simplify = TRUE, nr = 2500, axes = TRUE, yaxt = par("yaxt"), las = 1, center = TRUE, mfrow = NULL, ...) plot_Wave_channel(x, xunit, ylim, xlab, ylab, main, nr, simplify, axes = TRUE, yaxt = par("yaxt"), las = 1, center = TRUE, ...)
## S4 method for signature 'Wave,missing' plot(x, info = FALSE, xunit = c("time", "samples"), ylim = NULL, main = NULL, sub = NULL, xlab = NULL, ylab = NULL, simplify = TRUE, nr = 2500, axes = TRUE, yaxt = par("yaxt"), las = 1, center = TRUE, ...) ## S4 method for signature 'WaveMC,missing' plot(x, info = FALSE, xunit = c("time", "samples"), ylim = NULL, main = NULL, sub = NULL, xlab = NULL, ylab = colnames(x), simplify = TRUE, nr = 2500, axes = TRUE, yaxt = par("yaxt"), las = 1, center = TRUE, mfrow = NULL, ...) plot_Wave_channel(x, xunit, ylim, xlab, ylab, main, nr, simplify, axes = TRUE, yaxt = par("yaxt"), las = 1, center = TRUE, ...)
x |
|
info |
Logical, whether to include (written) information on the |
xunit |
Character indicating which units are used for setting up user coordinates (see |
ylim |
The |
main , sub
|
A title / subtitle for the plot. |
xlab |
Label for x-axis. |
ylab |
Label for y-axis (on the right side of the plot). For |
simplify |
Logical, whether the plot should be “simplified”.
If Plotting with |
nr |
Number of windows (segments) to be used approximately
(an appropriate number close to |
axes |
Whether to plot axes, default is |
yaxt |
How to plot the y-axis ( |
las |
The style of the axis labels, default is |
center |
Whether to plot with y-axes centered around 0 (or 127 if 8-bit), default is |
mfrow |
A vector indicating the arrangement of the figures, see |
... |
Further arguments to be passed to the underlying plot functions. |
Function plot_Wave_channel
is a helper function
to plot a single channel (left for a Wave
object, first channel / first column of data slot of a WaveMC
object);
in particular it is not intended to be called by the user directly.
Uwe Ligges [email protected], Sarah Schnackenberg
Wave-class, Wave
, WaveMC-class, WaveMC
and tuneR
Plotting a periodogram contained in an object of class Wspec
.
## S4 method for signature 'Wspec,missing' plot(x, which = 1, type = "h", xlab = "frequency", ylab = NULL, log = "", ...)
## S4 method for signature 'Wspec,missing' plot(x, which = 1, type = "h", xlab = "frequency", ylab = NULL, log = "", ...)
x |
Object of class |
which |
Integer indicating which of the periodograms contained in object |
type |
The default is to plot horizontal lines, rather than points. See |
xlab , ylab
|
Label for x-/y-axis. |
log |
Character - |
... |
Further arguments to be passed to the underlying plot functions.
See |
Uwe Ligges [email protected]
see Wspec
, periodogram
and tuneR
for the constructor function and some examples.
Plotting a spectogram (image) of an object of class Wspec
or WspecMat
.
## S4 method for signature 'WspecMat,missing' plot(x, xlab = "time", ylab = "frequency", xunit = c("samples", "time"), log = "", ...) ## S4 method for signature 'Wspec' image(x, xlab = "time", ylab = "frequency", xunit = c("samples", "time"), log = "", ...)
## S4 method for signature 'WspecMat,missing' plot(x, xlab = "time", ylab = "frequency", xunit = c("samples", "time"), log = "", ...) ## S4 method for signature 'Wspec' image(x, xlab = "time", ylab = "frequency", xunit = c("samples", "time"), log = "", ...)
x |
|
xlab , ylab
|
Label for x-/y-axis. |
xunit |
Character indicating which units are used to annotate the x-axis.
If |
log |
Character - |
... |
Further arguments to be passed to the underlying |
Calling image
on a Wspec
object converts it to class
WspecMat
and calls the corresponding plot
function.
Calling plot
on a WspecMat
object
generates an image
with correct annotated axes.
Uwe Ligges [email protected]
see image
, Wspec
, WspecMat
, periodogram
and tuneR
for the constructor function and some examples.
Do loudness equalization and cube root compression
postaud(x, fmax, fbtype = c("bark", "mel", "htkmel", "fcmel"), broaden = FALSE)
postaud(x, fmax, fbtype = c("bark", "mel", "htkmel", "fcmel"), broaden = FALSE)
x |
Matrix of spectra (output of |
fmax |
Maximum frequency im Hertz. |
fbtype |
Auditory frequency scale. |
broaden |
Use two additional frequency bands for calculation. |
x |
Matrix of the per sample/frame (columns) spectra after applying the frequency dependant loudness equalization and compression. |
eql |
Vector of the equal loudness curve. |
Sebastian Krey [email protected]
Daniel P. W. Ellis https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/, Hynek Hermansky
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, [email protected]) aspectrum <- audspec(pspectrum, [email protected]) paspectrum <- postaud(x = aspectrum$aspectrum, fmax = 5000, fbtype = "mel")
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, testsound@samp.rate) aspectrum <- audspec(pspectrum, testsound@samp.rate) paspectrum <- postaud(x = aspectrum$aspectrum, fmax = 5000, fbtype = "mel")
Compute the powerspectrum of the input signal. Basically output a power spectrogram using a Hamming window.
powspec(x, sr = 8000, wintime = 0.025, steptime = 0.01, dither = FALSE)
powspec(x, sr = 8000, wintime = 0.025, steptime = 0.01, dither = FALSE)
x |
Vector of samples. |
sr |
Sampling rate of the signal. |
wintime |
Window length in sec. |
steptime |
Step between successive windows in sec. |
dither |
Add offset to spectrum as if dither noise. |
Matrix, where each column represents a power spectrum for a given frame and each row represents a frequency.
Sebastian Krey [email protected]
Daniel P. W. Ellis: https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, [email protected])
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, testsound@samp.rate)
Preparing objects of class Wave
or class WaveMC
for binding/combination/concatenation by
removing small amounts at the beginning/end of the Wave
or WaveMC
in order to make the transition smooth by avoiding clicks.
prepComb(object, zero = 0, where = c("both", "start", "end"))
prepComb(object, zero = 0, where = c("both", "start", "end"))
object |
|
zero |
The zero level (default: 0) at which ideal cut points are determined (see Details).
A typical alternative would be 127 for 8 bit |
where |
One of |
This function is useful to prepare objects of class Wave
or class WaveMC
for binding/combination/concatenation.
At the side(s) indicated by where
small amounts of the Wave
or WaveMC
are removed
in order to make the transition between two Wave
s or WaveMC
s smooth (avoiding clicks).
This is done by dropping all values at the beginning of a Wave
or WaveMC
before the first positive point
after the zero
level is crossed from negative to positive.
Analogously, at the end of a Wave
or WaveMC
all points are cut after the last negative value
before the last zero
level crossing from negative to positive.
An object of class Wave
or class WaveMC
.
If stereo (for Wave
), only the left channel is analyzed while the right channel will simply be cut at the same locations.
If multi channel (for WaveMC
), only the first channel is analyzed while all other channels will simply be cut at the same locations.
Uwe Ligges [email protected], Sarah Schnackenberg, based on code from Matthias Heymann's former package ‘sound’.
bind
, Wave-class, Wave
, WaveMC-class,
WaveMC
, extractWave
, and noSilence
to cut off silence
Wobj1 <- sine(440, duration = 520) Wobj2 <- extractWave(sine(330, duration = 500), from = 110, to = 500) par(mfrow = c(2,1)) plot(bind(Wobj1, Wobj2), xunit = "samples") abline(v = 520, col = "red") # here is a "click"! # now remove the "click" by deleting a minimal amount of information: Wobj1 <- prepComb(Wobj1, where = "end") Wobj2 <- prepComb(Wobj2, where = "start") plot(bind(Wobj1, Wobj2), xunit = "samples")
Wobj1 <- sine(440, duration = 520) Wobj2 <- extractWave(sine(330, duration = 500), from = 110, to = 500) par(mfrow = c(2,1)) plot(bind(Wobj1, Wobj2), xunit = "samples") abline(v = 520, col = "red") # here is a "click"! # now remove the "click" by deleting a minimal amount of information: Wobj1 <- prepComb(Wobj1, where = "end") Wobj2 <- prepComb(Wobj2, where = "start") plot(bind(Wobj1, Wobj2), xunit = "samples")
These functions apply (static) quantization of notes in order to produce sheet music by pressing the notes into bars.
quantize(notes, energy, parts) quantMerge(notes, minlength, barsize, bars)
quantize(notes, energy, parts) quantMerge(notes, minlength, barsize, bars)
notes |
Series of notes, a vector of integers such as returned by |
energy |
Series of energy values, a vector of numerics such as corresponding components of a
|
parts |
Number of outcoming parts. The |
minlength |
1/(length of the shortest note). |
barsize |
One bar contains |
bars |
We expect |
quantize
returns a list with components:
notes |
Vector of length |
energy |
Same as |
quantMerge
returns a data.frame with components:
note |
integer representation of a note (see Arguments). |
duration |
1/duration of a note (see |
punctuation |
Whether the note should be punctuated. If |
slur |
currently always |
Uwe Ligges [email protected]
to get the input: noteFromFF
,
for plotting: quantplot
,
for further processing: lilyinput
,
to get notenames: notenames
;
for an example, see the help in tuneR.
Plot an observed melody and (optional) an expected melody, as well as corresponding energy values (corresponding to the loudness of the sound) within a quantization grid.
quantplot(observed, energy = NULL, expected = NULL, bars, barseg = round(length(observed) / bars), main = NULL, xlab = NULL, ylab = "note", xlim = NULL, ylim = NULL, observedcol = "red", expectedcol = "grey", gridcol = "grey", lwd = 2, las = 1, cex.axis = 0.9, mar = c(5, 4, 4, 4) + 0.1, notenames = NULL, silence = "silence", plotenergy = TRUE, ..., axispar = list(ax1 = list(side=1), ax2 = list(side=2), ax4 = list(side=4)), boxpar = list(), energylabel = list(text="energy", side=4, line=2.5, at=rg.s-0.25, las=3), energypar = list(pch=20), expectedpar = list(), gridpar = list(gridbar = list(col = 1), gridinner = list(col=gridcol)), observedpar = list(col=observedcol, pch=15))
quantplot(observed, energy = NULL, expected = NULL, bars, barseg = round(length(observed) / bars), main = NULL, xlab = NULL, ylab = "note", xlim = NULL, ylim = NULL, observedcol = "red", expectedcol = "grey", gridcol = "grey", lwd = 2, las = 1, cex.axis = 0.9, mar = c(5, 4, 4, 4) + 0.1, notenames = NULL, silence = "silence", plotenergy = TRUE, ..., axispar = list(ax1 = list(side=1), ax2 = list(side=2), ax4 = list(side=4)), boxpar = list(), energylabel = list(text="energy", side=4, line=2.5, at=rg.s-0.25, las=3), energypar = list(pch=20), expectedpar = list(), gridpar = list(gridbar = list(col = 1), gridinner = list(col=gridcol)), observedpar = list(col=observedcol, pch=15))
observed |
Either a vector of observed notes resulting from some quantization,
or a list with components |
energy |
A vector of energy values with same quantization as |
expected |
Expected notes (optional; in order to compare results). |
bars |
Number of bars to be plotted (e.g. corresponding to |
barseg |
Number of segments (minimal length notes) in each bar. |
main |
Main title of the plot. |
xlab , ylab
|
Annotation of x-/y-axes. |
xlim , ylim
|
Range of x-/y-axis. |
observedcol |
Colour for the observed notes. |
expectedcol |
Colour for the expected notes. |
gridcol |
Colour of the inner-bar grid. |
lwd |
Line width, see |
las |
Orientation of axis labels, see |
cex.axis |
Size of tick mark labels, see |
mar |
Margins of the plot, see |
notenames |
Optionally specify other notenames (character) for the y-axis. |
silence |
Character string for label of the ‘silence’ (default) axis. |
plotenergy |
Logical indicating whether to plot energy values in the bottom part of the plot (default is |
... |
Additional graphical parameters to be passed to underlying |
axispar |
A named list of three other lists ( |
boxpar |
A list of parameters to be passed to the box generating functions. |
energylabel |
A list of parameters to be passed to the energy-label
generating |
energypar |
A list of parameters to be passed to the |
expectedpar |
A list of parameters to be passed to the |
gridpar |
A named list of two other lists ( |
observedpar |
A list of parameters to be passed to the |
Uwe Ligges [email protected]
noteFromFF
, FF
, melodyplot
, quantize
;
for an example, see the help in tuneR.
A MIDI file is read and returned in form of a structured data frame containing most event information (minus some meta events and minus all system events). For details about the represented information see the reference given below.
readMidi(file)
readMidi(file)
file |
Filename of MIDI file. |
A data frame consisting of columns
time |
Time or delta-time of the events, depending on the MIDI format. |
event |
A factor indicating the event. |
type |
An integer indicating the type of a “meta event”, otherwise |
channel |
The channel number or |
parameter1 |
First parameter of an event, e.g. a representation for a note in a “note event”. |
parameter2 |
Second parameter of an event. |
parameterMetaSystem |
Information in a “meta event”, currently all meta events are converted to a character representation (of hex, if all fails), but future versions may have more appropriate representations. |
track |
The track number. |
Please see the given reference about the MIDI file format about details.
The data structure may be changed or extended in future versions.
Uwe Ligges and Johanna Mielke
A good reference about the Midi file format can be found at http://www.music.mcgill.ca/~ich/classes/mumt306/StandardMIDIfileformat.html.
The function getMidiNotes
extracts a more readable representation of note events only.
You may also want to read Wave (readWave
) or MP3 (readMP3
).
content <- readMidi(system.file("example_files", "Bass_sample.mid", package="tuneR")) str(content) content
content <- readMidi(system.file("example_files", "Bass_sample.mid", package="tuneR")) str(content) content
A bare bones MPEG-2 layer 3 (MP3) file reader that returns the results as 16bit PCM data stored in a Wave object.
readMP3(filename)
readMP3(filename)
filename |
Filename of MP3 file. |
A Wave
object.
The decoder can currently only handle files which are either mono or stereo. This is a limitation of the Wave object and the underlying MAD decoder.
Olaf Mersmann [email protected]
The decoder source code is taken from the MAD library, see http://www.underbit.com/products/mad/.
## Not run: ## Requires an mp3 file named sample.mp3 in the current directory. mpt <- readMP3("sample.mp3") summary(mpt) ## End(Not run)
## Not run: ## Requires an mp3 file named sample.mp3 in the current directory. mpt <- readMP3("sample.mp3") summary(mpt) ## End(Not run)
Reading Wave files.
readWave(filename, from = 1, to = Inf, units = c("samples", "seconds", "minutes", "hours"), header = FALSE, toWaveMC = NULL)
readWave(filename, from = 1, to = Inf, units = c("samples", "seconds", "minutes", "hours"), header = FALSE, toWaveMC = NULL)
filename |
Filename of the file to be read. |
from |
Where to start reading (in order to save memory by reading wave file piecewise), in |
to |
Where to stop reading (in order to save memory by reading wave file piecewise), in |
units |
Units in which |
header |
If |
toWaveMC |
If |
An object of class Wave
or WaveMC
or a list containing just the header information if header = TRUE
.
If the latter, some experimental support for reading bext
chunks in
Broadcast Wave Format files is implemented, and the content is returned as an unprocessed string (character).
Uwe Ligges [email protected], Sarah Schnackenberg
Wave-class, Wave
, WaveMC-class, WaveMC
, writeWave
Wobj <- sine(440) tdir <- tempdir() tfile <- file.path(tdir, "myWave.wav") writeWave(Wobj, filename = tfile) list.files(tdir, pattern = "\\.wav$") newWobj <- readWave(tfile) newWobj file.remove(tfile)
Wobj <- sine(440) tdir <- tempdir() tfile <- file.path(tdir, "myWave.wav") writeWave(Wobj, filename = tfile) list.files(tdir, pattern = "\\.wav$") newWobj <- readWave(tfile) newWobj file.remove(tfile)
Showing Wave
, Wspec
, and WspecMat
objects.
The Wave
object is being show
n.
The number of samples, duration in seconds, Samplingrate (Hertz),
Stereo / Mono, PCM / IEEE, and the resolution in bits are printed.
Note that it does not make sense to print the whole channels
containing several thousands or millions of samples.
The WaveMC
object is being show
n.
The number of samples, duration in seconds, Samplingrate (Hertz),
number of channels, PCM / IEEE, and the resolution in bits are printed.
Note that it does not make sense to print the whole channels
containing several thousands or millions of samples.
The number of periodograms, Fourier frequencies, window width (used amount of data), amount of overlap of neighboring windows, and whether the periodogram(s) has/have been normalized will be printed.
The number of periodograms, Fourier frequencies, window width (used amount of data), amount of overlap of neighboring windows, and whether the periodogram(s) has/have been normalized will be printed.
Uwe Ligges [email protected]
Wave-class, Wave
, WaveMC-class, WaveMC
, Wspec
, WspecMat
,
plot-methods
, summary-methods
,
and periodogram
for the constructor function and some examples
Apply a smoother to estimated notes.
Currently, only a running median (using decmedian
in package pastecs) is available.
smoother(notes, method = "median", order = 4, times = 2)
smoother(notes, method = "median", order = 4, times = 2)
notes |
Series of notes, a vector of integers such as returned by |
method |
Currently, only a running |
order |
The window used for the running median corresponds to 2*order + 1. |
times |
The number of times the running median is applied (default: 2). |
The smoothed series of notes.
Uwe Ligges [email protected]
Calculate cepstra from spectral samples (in columns of spec) through Discrete Cosine Transformation.
spec2cep(spec, ncep = 12, type = c("t2", "t1", "t3", "t4"))
spec2cep(spec, ncep = 12, type = c("t2", "t1", "t3", "t4"))
spec |
Input spectra (samples/time frames in columns). |
ncep |
Number of cepstra to return. |
type |
DCT Type. |
cep |
Matrix of resulting cepstra. |
dctm |
Returns the DCT matrix that spec was multiplied by to give cep. |
Sebastian Krey [email protected]
Daniel P. W. Ellis: https://www.ee.columbia.edu/~dpwe/resources/matlab/rastamat/
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, [email protected]) aspectrum <- audspec(pspectrum, [email protected]) cepstra <- spec2cep(aspectrum$aspectrum)
testsound <- normalize(sine(400) + sine(1000) + square(250), "16") pspectrum <- powspec(testsound@left, testsound@samp.rate) aspectrum <- audspec(pspectrum, testsound@samp.rate) cepstra <- spec2cep(aspectrum$aspectrum)
summary is a generic function used to produce result summaries of the results of various model fitting functions. The function invokes particular methods which depend on the class of the first argument.
Any object for which a summary is desired, dispatches to the S3 generic.
The Wave
object is being show
n and an additional summary of the
Wave
-object's (one or two) channels is given.
The WaveMC
object is being show
n and an additional summary of the
WaveMC
-object's channels is given.
The Wspec
object is being show
n and as an additional output is given:
df
, taper
(see spectrum
)
and for the underlying Wave
object the number of channels and its sampling rate.
The WspecMat
object is being show
n and as an additional output is given:
df
, taper
(see spectrum
)
and for the underlying Wave
object the number of channels and its sampling rate.
Uwe Ligges [email protected]
For the S3 generic: summary.default
, plot-methods
,
Wave-class, Wave
, WaveMC-class, WaveMC
, Wspec
, WspecMat
, show
tuneR, a collection of examples
tuneR consists of several functions to work with and to analyze Wave files.
In the following examples, some of the functions
to generate some data (such as sine
),
to read and write Wave files (readWave
, writeWave
),
to represent or construct (multi channel) Wave files (Wave
, WaveMC
),
to transform Wave objects (bind
, channel
,
downsample
, extractWave
, mono
, stereo
),
and to play
Wave objects are used.
Other functions and classes are available to
calculate several periodograms of a signal (periodogram
, Wspec
),
to estimate the corresponding fundamental frequencies (FF
, FFpure
),
to derive the corresponding notes (noteFromFF
),
and to apply a smoother
.
Now, the melody and corresponding energy values can be plotted using the function
melodyplot
.
A next step is the quantization (quantize
) and a corresponding plot
(quantplot
) showing the note values for binned data.
Moreover, a function called lilyinput
(and a data-preprocessing function quantMerge
)
can prepare a data frame to be presented as sheet music by
postprocessing with the music typesetting software LilyPond.
Of course, print (show), plot and summary methods are available for most classes.
Uwe Ligges <[email protected]> with contributions from Sebastian Krey, Olaf Mersmann, Sarah Schnackenberg, Andrea Preusser, Anita Thieler, and Claus Weihs, as well as code fragments and ideas from the former package sound by Matthias Heymann and functions from ‘rastamat’ by Daniel P. W. Ellis. The included parts of the libmad MPEG audio decoder library are authored by Underbit Technologies.
library("tuneR") # in a regular session, we are loading tuneR # constructing a mono Wave object (2 sec.) containing sinus # sound with 440Hz and folled by 220Hz: Wobj <- bind(sine(440), sine(220)) show(Wobj) plot(Wobj) # it does not make sense to plot the whole stuff plot(extractWave(Wobj, from = 1, to = 500)) ## Not run: play(Wobj) # listen to the sound ## End(Not run) tmpfile <- file.path(tempdir(), "testfile.wav") # write the Wave object into a Wave file (can be played with any player): writeWave(Wobj, tmpfile) # reading it in again: Wobj2 <- readWave(tmpfile) Wobjm <- mono(Wobj, "left") # extract the left channel # and downsample to 11025 samples/sec.: Wobjm11 <- downsample(Wobjm, 11025) # extract a part of the signal interactively (click for left/right limits): ## Not run: Wobjm11s <- extractWave(Wobjm11) ## End(Not run) # or extract some values reproducibly Wobjm11s <- extractWave(Wobjm11, from=1000, to=17000) # calculating periodograms of sections each consisting of 1024 observations, # overlapping by 512 observations: WspecObject <- periodogram(Wobjm11s, normalize = TRUE, width = 1024, overlap = 512) # Let's look at the first periodogram: plot(WspecObject, xlim = c(0, 2000), which = 1) # or a spectrogram image(WspecObject, ylim = c(0, 1000)) # calculate the fundamental frequency: ff <- FF(WspecObject) print(ff) # derive note from FF given diapason a'=440 notes <- noteFromFF(ff, 440) # smooth the notes: snotes <- smoother(notes) # outcome should be 0 for diapason "a'" and -12 (12 halftones lower) for "a" print(snotes) # plot melody and energy of the sound: melodyplot(WspecObject, snotes) # apply some quantization (into 8 parts): qnotes <- quantize(snotes, WspecObject@energy, parts = 8) # an plot it, 4 parts a bar (including expected values): quantplot(qnotes, expected = rep(c(0, -12), each = 4), bars = 2) # now prepare for LilyPond qlily <- quantMerge(snotes, 4, 4, 2) qlily
library("tuneR") # in a regular session, we are loading tuneR # constructing a mono Wave object (2 sec.) containing sinus # sound with 440Hz and folled by 220Hz: Wobj <- bind(sine(440), sine(220)) show(Wobj) plot(Wobj) # it does not make sense to plot the whole stuff plot(extractWave(Wobj, from = 1, to = 500)) ## Not run: play(Wobj) # listen to the sound ## End(Not run) tmpfile <- file.path(tempdir(), "testfile.wav") # write the Wave object into a Wave file (can be played with any player): writeWave(Wobj, tmpfile) # reading it in again: Wobj2 <- readWave(tmpfile) Wobjm <- mono(Wobj, "left") # extract the left channel # and downsample to 11025 samples/sec.: Wobjm11 <- downsample(Wobjm, 11025) # extract a part of the signal interactively (click for left/right limits): ## Not run: Wobjm11s <- extractWave(Wobjm11) ## End(Not run) # or extract some values reproducibly Wobjm11s <- extractWave(Wobjm11, from=1000, to=17000) # calculating periodograms of sections each consisting of 1024 observations, # overlapping by 512 observations: WspecObject <- periodogram(Wobjm11s, normalize = TRUE, width = 1024, overlap = 512) # Let's look at the first periodogram: plot(WspecObject, xlim = c(0, 2000), which = 1) # or a spectrogram image(WspecObject, ylim = c(0, 1000)) # calculate the fundamental frequency: ff <- FF(WspecObject) print(ff) # derive note from FF given diapason a'=440 notes <- noteFromFF(ff, 440) # smooth the notes: snotes <- smoother(notes) # outcome should be 0 for diapason "a'" and -12 (12 halftones lower) for "a" print(snotes) # plot melody and energy of the sound: melodyplot(WspecObject, snotes) # apply some quantization (into 8 parts): qnotes <- quantize(snotes, WspecObject@energy, parts = 8) # an plot it, 4 parts a bar (including expected values): quantplot(qnotes, expected = rep(c(0, -12), each = 4), bars = 2) # now prepare for LilyPond qlily <- quantMerge(snotes, 4, 4, 2) qlily
Update old Wave objects generated with tuneR < 1.0.0 to the new class definition for use with new versions of the package.
updateWave(object)
updateWave(object)
object |
An object of Wave-class. |
This function is only needed to convert Wave-class objects that have been saved with tuneR versions prior to 1.0-0 to match the new class definition.
An object of Wave-class as implemented in tuneR versions >= 1.0-0.
Uwe Ligges [email protected], Sarah Schnackenberg
x <- sine(440) updateWave(x)
x <- sine(440) updateWave(x)
Constructors and coercion for class Wave
objects
Wave(left, ...) ## S4 method for signature 'numeric' Wave(left, right = numeric(0), samp.rate = 44100, bit = 16, pcm = TRUE, ...)
Wave(left, ...) ## S4 method for signature 'numeric' Wave(left, right = numeric(0), samp.rate = 44100, bit = 16, pcm = TRUE, ...)
left , right , samp.rate , bit , pcm
|
See Section “Slots” on the help page Wave-class.
Except for numeric, the argument |
... |
Further arguments to be passed to the numeric method. |
The class definition has been extended in tuneR version 1.0-0. Saved objects of class Wave
generated with former versions can be
updated with updateWave
to match the new definition.
An object of Wave-class.
Uwe Ligges [email protected]
Wave-class, WaveMC-class, writeWave
, readWave
, updateWave
# constructing a Wave object (1 sec.) containing sinus sound with 440Hz: x <- seq(0, 2*pi, length = 44100) channel <- round(32000 * sin(440 * x)) Wobj <- Wave(left = channel) Wobj # or more easily: Wobj <- sine(440)
# constructing a Wave object (1 sec.) containing sinus sound with 440Hz: x <- seq(0, 2*pi, length = 44100) channel <- round(32000 * sin(440 * x)) Wobj <- Wave(left = channel) Wobj # or more easily: Wobj <- sine(440)
Class “Wave”.
The class definition has been extended in tuneR version 1.0-0. Saved objects of class Wave generated with former versions can be
updated with updateWave
to match the new definition.
Objects can be created by calls of the form new("Wave", ...)
,
or more conveniently using the function Wave
.
left
:Object of class "numeric"
representing the left channel.
right
:Object of class "numeric"
representing the right channel,
NULL
if mono.
stereo
:Object of class "logical"
indicating whether this
is a stereo (two channels) or mono representation.
samp.rate
:Object of class "numeric"
- the sampling rate, e.g. 44100 for CD quality.
bit
:Object of class "numeric"
, common is 16 for CD quality, or
8 for a rather rough representation.
pcm
:Object of class "logical"
indicating whether this is a
PCM or IEEE_FLOAT Wave format.
Uwe Ligges [email protected]
Wave
, updateWave
, and for multi channel Wave files see WaveMC-class
Create a Wave
object of special waveform such as
silcence, power law (white, red, pink, ...) noise, sawtooth, sine, square, and pulse.
noise(kind = c("white", "pink", "power", "red"), duration = samp.rate, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), alpha = 1, ...) pulse(freq, duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), width = 0.1, plateau = 0.2, interval = 0.5, ...) sawtooth(freq, duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), reverse = FALSE, ...) silence(duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), ...) sine(freq, duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), ...) square(freq, duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), up = 0.5, ...)
noise(kind = c("white", "pink", "power", "red"), duration = samp.rate, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), alpha = 1, ...) pulse(freq, duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), width = 0.1, plateau = 0.2, interval = 0.5, ...) sawtooth(freq, duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), reverse = FALSE, ...) silence(duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), ...) sine(freq, duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), ...) square(freq, duration = samp.rate, from = 0, samp.rate = 44100, bit = 1, stereo = FALSE, xunit = c("samples", "time"), up = 0.5, ...)
kind |
The kind of noise, “white”, “pink”, “power”, or “red” (these are not dB adjusted (!) but all except for “white” are linear decreasing on a log-log scale). Algorithm for generating power law noise is taken from Timmer and König (1995). |
freq |
The frequency (in Hertz) to be generated. |
duration |
Duration of the |
from |
Starting value of the |
samp.rate |
Sampling rate of the |
bit |
Resolution of the The |
stereo |
Logical, if |
xunit |
Character indicating which units are used
(both in arguments |
alpha |
The power for the power law noise (defaults are 1 for pink and 1.5 for red noise)
|
reverse |
Logical, if |
up |
A number between 0 and 1 giving the percentage of the waveform at max value (= 1 - percentage of min value). |
width |
Relative pulses width: the proportion of time the amplitude is non-zero. |
plateau |
Relative plateau width: the proportion of the pulse width where amplitude is ±1. |
interval |
Relative interval between the up-going and down-going pulses with respect to the center of the wave period (0: immediatly after up-going, 1: center of the wave period). |
... |
Further arguments to be passed to |
A Wave
object.
Uwe Ligges [email protected], partly based on code from Matthias Heymann's former package ‘sound’, Anita Thieler, Guillaume Guénard
J. Timmer and M. König (1995): On generating power law noise. Astron. Astrophys. 300, 707-710.
Wave-class, Wave
, normalize
, noSilence
Wobj <- sine(440, duration = 1000) Wobj2 <- noise(duration = 1000) Wobj3 <- pulse(220, duration = 1000) plot(Wobj) plot(Wobj2) plot(Wobj3)
Wobj <- sine(440, duration = 1000) Wobj2 <- noise(duration = 1000) Wobj3 <- pulse(220, duration = 1000) plot(Wobj) plot(Wobj2) plot(Wobj3)
Constructors and coercion for class WaveMC
objects
WaveMC(data, ...) ## S4 method for signature 'matrix' WaveMC(data = matrix(numeric(0), 0, 0), samp.rate = 44100, bit = 16, pcm = TRUE, ...)
WaveMC(data, ...) ## S4 method for signature 'matrix' WaveMC(data = matrix(numeric(0), 0, 0), samp.rate = 44100, bit = 16, pcm = TRUE, ...)
data |
Except for a numeric matrix, the argument |
samp.rate , bit , pcm
|
See Section “Slots” on the help page WaveMC-class. |
... |
Further arguments to be passed to the matrix method. |
An object of WaveMC-class.
Uwe Ligges [email protected], Sarah Schnackenberg
WaveMC-class, Wave-class, writeWave
, readWave
# constructing a WaveMC object (1 sec.) containing sinus sound with 440Hz: x <- seq(0, 2*pi, length = 44100) channel <- round(32000 * sin(440 * x)) WMCobj <- WaveMC(data = channel) WMCobj
# constructing a WaveMC object (1 sec.) containing sinus sound with 440Hz: x <- seq(0, 2*pi, length = 44100) channel <- round(32000 * sin(440 * x)) WMCobj <- WaveMC(data = channel) WMCobj
Class “WaveMC”.
This class has been added in tuneR version 1.0-0 for representation and construction
of multi channel Wave files. Objects of class Wave
can be transformed to the new class definition
by calls of the form as(..., "WaveMC")
. Coercion from the WaveMC
class to the Wave-class
works via as(..., "Wave")
if there are no more than 2 channels.
Coercing back to the Wave-class can be useful since some (very few) functions cannot yet deal with multi channel Wave objects.
Note that also the Wave-class definition has been extended in tuneR version 1.0-0. For more details see Wave-class.
Objects can be created by calls of the form new("WaveMC", ...)
,
or more conveniently using the function WaveMC
.
.Data
:Object of class "matrix"
containing numeric data, where each column is representing one channel.
Column names are the appropriate way to name different channels.
The data object MCnames
contains a data frame of standard names for channels in multi channel Wave files.
samp.rate
:Object of class "numeric"
- the sampling rate, e.g. 44100 for CD quality.
bit
:Object of class "numeric"
, common is 16 for CD quality, or
8 for a rather rough representation.
pcm
:Object of class "logical"
indicating whether this is a
PCM or IEEE_FLOAT Wave format.
Uwe Ligges [email protected], Sarah Schnackenberg
Getting and setting the default player for Wave files
setWavPlayer(player) getWavPlayer()
setWavPlayer(player) getWavPlayer()
player |
Set the character string to call a Wave file player (including optional arguments)
using |
getWavPlayer
returns the character string that has been set by setWavPlayer
.
Uwe Ligges [email protected]
Writing Wave files.
writeWave(object, filename, extensible = TRUE)
writeWave(object, filename, extensible = TRUE)
object |
Object of class |
filename |
Filename of the file to be written. |
extensible |
If |
It is only possible to write a non-extensible Wave format file for objects of class Wave
or
for objects of class WaveMC
with one or two channels (mono or stereo).
If the argument object
is a Wave-class object, the channels are automatically chosen to be
“FL” (for mono) or “FL” and “FR” (for stereo).
The channel mask used to arrange the channel ordering in multi channel Wave files is written
according to Microsoft standards as given in the data frame MCnames
containing the first 18 standard channels.
In the case of writing a multi channel Wave file, the column names of the object object
(colnames(object)
) must be specified and
must uniquely identify the channel ordering for WaveMC objects.
The column names of the object of class WaveMC
have to be a subset of the 18 standard channels
and have to match the corresponding abbreviated names.
(See MCnames
for possible channels and the abbreviated names:
“FL”, “FR”, “FC”, “LF”, “BL”, “BR”,
“FLC”, “FRC”, “BC”, “SL”, “SR”, “TC”,
“TFL”, “TFC”, “TFR”, “TBL”, “TBC” and “TBR”).
The function normalize
can be used to transform and rescale data to an appropriate amplitude range for
various Wave file formats (either pcm with 8-, 16-, 24- or 32-bit or IEEE_FLOAT with 32- or 64-bit).
writeWave
creates a Wave file, but returns nothing.
Uwe Ligges [email protected], Sarah Schnackenberg
Wave-class, Wave
, WaveMC-class, WaveMC
, normalize
, MCnames
, readWave
Wobj <- sine(440) tdir <- tempdir() tfile <- file.path(tdir, "myWave.wav") writeWave(Wobj, filename = tfile) list.files(tdir, pattern = "\\.wav$") newWobj <- readWave(tfile) newWobj file.remove(tfile)
Wobj <- sine(440) tdir <- tempdir() tfile <- file.path(tdir, "myWave.wav") writeWave(Wobj, filename = tfile) list.files(tdir, pattern = "\\.wav$") newWobj <- readWave(tfile) newWobj file.remove(tfile)
Class “Wspec” (Wave spectrums).
Objects of this class represent a bunch of periodograms
(see periodogram
, each generated by spectrum
)
corresponding to one or several windows of one Wave
or WaveMC
object.
Redundancy (e.g. same frequencies in each of the periodograms) will be omitted,
hence reducing memory consumption.
The subset function “[
” extracts the selected
elements of slots spec
, starts
, variance
and energy
and returns the other slots unchanged.
Objects can be created by calls of the form new("Wspec", ...)
,
but regularly they will be created by calls to the function periodogram
.
The following slots are defined. For details see the constructor function periodogram
.
freq
:Object of class "numeric"
.
spec
:Object of class "list"
.
kernel
:Object of class "ANY"
.
df
:Object of class "numeric"
.
taper
:Object of class "numeric"
.
width
:Object of class "numeric"
.
overlap
:Object of class "numeric"
.
normalize
:Object of class "logical"
.
starts
:Object of class "numeric"
.
stereo
:Object of class "logical"
.
samp.rate
:Object of class "numeric"
.
variance
:Object of class "numeric"
.
energy
:Object of class "numeric"
.
Uwe Ligges [email protected]
the show
, plot
and summary
methods,
for the constructor function and some examples: periodogram
(and hence also spec.pgram
, Wave-class, Wave
, WaveMC-class, and WaveMC
)
WspecMat
for a similar class that represents the spectrum in form of a matrix.
Class “WspecMat” (Wave spectrums as Matrix).
Objects of this class represent a bunch of periodograms
(see periodogram
, each generated by spectrum
)
corresponding to one or several windows of one Wave
or WaveMC
object.
Redundancy (e.g. same frequencies in each of the periodograms) will be omitted,
hence reducing memory consumption.
The subset function “[
” extracts the selected
elements of slots spec
, starts
, variance
and energy
and returns the other slots unchanged.
Objects can be created by calls of the form new("WspecMat", ...)
,
but regularly they will be created from a Wspec
object
by calls such as as(Wspec_Object, "WspecMat")
.
The following slots are defined. For details see the constructor function periodogram
.
freq
:Object of class "numeric"
.
spec
:Object of class "matrix"
.
kernel
:Object of class "ANY"
.
df
:Object of class "numeric"
.
taper
:Object of class "numeric"
.
width
:Object of class "numeric"
.
overlap
:Object of class "numeric"
.
normalize
:Object of class "logical"
.
starts
:Object of class "numeric"
.
stereo
:Object of class "logical"
.
samp.rate
:Object of class "numeric"
.
variance
:Object of class "numeric"
.
energy
:Object of class "numeric"
.
Uwe Ligges [email protected]
the show
, plot
and summary
methods