R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("tuneR-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('tuneR') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "MonoStereo" > > ### * MonoStereo > > flush(stderr()); flush(stdout()) > > ### Name: Mono-Stereo > ### Title: Converting (extracting, joining) stereo to mono and vice versa > ### Aliases: mono stereo > ### Keywords: manip utilities > > ### ** Examples > > x <- seq(0, 2*pi, length = 44100) > Wobj <- Wave(left = round(32000 * sin(440 * x))) Warning in .local(left, ...) : 'samp.rate' not specified, assuming 44100Hz Warning in .local(left, ...) : 'bit' not specified, assuming 16bit > Wobj Wave Object Number of Samples: 44100 Duration (seconds): 1 Samplingrate (Hertz): 44100 Channels (Mono/Stereo): Mono Bit (8/16): 16 > Wobj2 <- stereo(Wobj, Wobj) > Wobj2 Wave Object Number of Samples: 44100 Duration (seconds): 1 Samplingrate (Hertz): 44100 Channels (Mono/Stereo): Stereo Bit (8/16): 16 > mono(Wobj2, "right") Wave Object Number of Samples: 44100 Duration (seconds): 1 Samplingrate (Hertz): 44100 Channels (Mono/Stereo): Mono Bit (8/16): 16 > > > > cleanEx(); ..nameEx <- "Wave" > > ### * Wave > > flush(stderr()); flush(stdout()) > > ### Name: Wave-class > ### Title: Class Wave and constructors > ### Aliases: Wave Wave-methods Wave,ANY-method Wave,numeric-method > ### Wave,matrix-method Wave,data.frame-method Wave,list-method Wave-class > ### [,Wave-method coerce,matrix,Wave-method coerce,data.frame,Wave-method > ### coerce,list,Wave-method coerce,numeric,Wave-method > ### coerce,Wave,data.frame-method coerce,Wave,matrix-method > ### coerce,Wave,list-method > ### Keywords: classes methods > > ### ** Examples > > # 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) Warning in .local(left, ...) : 'samp.rate' not specified, assuming 44100Hz Warning in .local(left, ...) : 'bit' not specified, assuming 16bit > Wobj Wave Object Number of Samples: 44100 Duration (seconds): 1 Samplingrate (Hertz): 44100 Channels (Mono/Stereo): Mono Bit (8/16): 16 > > > > cleanEx(); ..nameEx <- "WaveIO" > > ### * WaveIO > > flush(stderr()); flush(stdout()) > > ### Name: WaveIO > ### Title: Reading and writing Wave files > ### Aliases: readWave writeWave > ### Keywords: IO file > > ### ** Examples > > x <- seq(0, 2*pi, length = 44100) > Wobj <- Wave(left = round(32000 * sin(440 * x))) Warning in .local(left, ...) : 'samp.rate' not specified, assuming 44100Hz Warning in .local(left, ...) : 'bit' not specified, assuming 16bit > Wobj Wave Object Number of Samples: 44100 Duration (seconds): 1 Samplingrate (Hertz): 44100 Channels (Mono/Stereo): Mono Bit (8/16): 16 > > tdir <- tempdir() > tfile <- file.path(tdir, "myWave.wav") > writeWave(Wobj, filename = tfile) > list.files(tdir, pattern = "\.wav$") [1] "myWave.wav" > newWobj <- readWave(tfile) > newWobj Wave Object Number of Samples: 44100 Duration (seconds): 1 Samplingrate (Hertz): 44100 Channels (Mono/Stereo): Mono Bit (8/16): 16 > file.remove(tfile) [1] TRUE > > > > cleanEx(); ..nameEx <- "extractWave" > > ### * extractWave > > flush(stderr()); flush(stdout()) > > ### Name: extractWave > ### Title: Extractor for Wave objects > ### Aliases: extractWave > ### Keywords: manip utilities iplot > > ### ** Examples > > x <- seq(0, 2*pi, length = 44100) > Wobj <- Wave(left = round(32000 * sin(440 * x))) Warning in .local(left, ...) : 'samp.rate' not specified, assuming 44100Hz Warning in .local(left, ...) : 'bit' not specified, assuming 16bit > # extracting the middle 0.5 seconds of that 1 sec. sound: > Wobj2 <- extractWave(Wobj, from = 0.25, to = 0.75, xunit = "time") > Wobj2 Wave Object Number of Samples: 22051 Duration (seconds): 0.5 Samplingrate (Hertz): 44100 Channels (Mono/Stereo): Mono Bit (8/16): 16 > > ## Not run: > ##D # or interactively: > ##D Wobj2 <- extractWave(Wobj) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "lilyinput" > > ### * lilyinput > > flush(stderr()); flush(stdout()) > > ### Encoding: latin1 > > ### Name: lilyinput > ### Title: Providing LilyPond compatible input > ### Aliases: lilyinput > ### Keywords: file interface > > ### ** Examples > > # Not yet available ... > > > > cleanEx(); ..nameEx <- "periodogram" > > ### * periodogram > > flush(stderr()); flush(stdout()) > > ### Name: periodogram > ### Title: Periodogram (Spectral Density) Estimation on Wave objects > ### Aliases: periodogram > ### Keywords: ts > > ### ** Examples > > # 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) Warning in .local(left, ...) : 'samp.rate' not specified, assuming 44100Hz Warning in .local(left, ...) : 'bit' not specified, assuming 16bit > Wobj Wave Object Number of Samples: 44100 Duration (seconds): 1 Samplingrate (Hertz): 44100 Channels (Mono/Stereo): Mono Bit (8/16): 16 > > # 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 Wspec Object (use summary() for more details) Number of Periodograms: 11 Estimated at 2048 Frequencies: 10.76660 ... 22050 Further parameters: width: 4096 overlap: 0 normal.: TRUE > > # 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") > > FF(Wspecobj) # all ~ 440 Hertz [1] 440.6187 440.6039 440.6074 440.6216 440.6156 440.6025 440.6107 440.6224 [9] 440.6121 440.6023 439.1613 > noteFromFF(FF(Wspecobj)) # all diapason a [1] 0 0 0 0 0 0 0 0 0 0 0 > > > > cleanEx(); ..nameEx <- "tuneR" > > ### * tuneR > > flush(stderr()); flush(stdout()) > > ### Name: tuneR > ### Title: tuneR > ### Aliases: tuneR > ### Keywords: documentation > > ### ** Examples > > ## Not run: > ##D # library(tuneR) # in a regular session, we are loading tuneR > ##D > ##D # constructing a mono Wave object (2 sec.) containing sinus > ##D # sound with 440Hz and folled by 220Hz: > ##D x <- seq(0, 2*pi, length = 44100) > ##D channel <- round(32000 * c(sin(440 * x), sin(220 * x))) > ##D Wobj <- Wave(left = channel) > ##D show(Wobj) > ##D plot(Wobj) # it does not make sense to plot the whole stuff > ##D plot(extractWave(Wobj, from = 1, to = 500)) > ##D play(Wobj) # listen to the sound > ##D > ##D # write the Wave object into a Wave file (can be played with any player): > ##D writeWave(Wobj, "testfile.wav") > ##D # reading it in again: > ##D Wobj2 <- readWave("testfile.wav") > ##D identical(Wobj2, Wobj) # it is still the same > ##D > ##D Wobjm <- mono(Wobj, "left") # extract the left channel > ##D # and downsample to 11025 samples/sec.: > ##D Wobjm11 <- downsample(Wobjm, 11025) > ##D # extract a part of the signal interactively (click for left/right limits): > ##D Wobjm11s <- extractWave(Wobjm11) > ##D > ##D # calculating periodograms of sections each consisting of 1024 observations, > ##D # overlapping by 512 observations: > ##D WspecObject <- periodogram(Wobjm11s, normalize = TRUE, width = 1024, overlap = 512) > ##D # Let's look at the first periodogram: > ##D plot(WspecObject, xlim = c(0, 2000), which = 1) > ##D # calculate the fundamental frequency: > ##D ff <- FF(WspecObject) > ##D print(ff) > ##D # derive note from FF given diapason a'=440 > ##D notes <- noteFromFF(ff, 440) > ##D # smooth the notes: > ##D snotes <- smoother(notes) > ##D # outcome should be 0 for diapason "a'" and -12 (12 halftones lower) for "a" > ##D print(snotes) > ##D # plot melody and energy of the sound: > ##D melodyplot(WspecObject, snotes) > ## End(Not run) > > > > ### *