align.wave: Automatic placement of calls at beggining of sound window

View source: R/align.wave.R

align.waveR Documentation

Automatic placement of calls at beggining of sound window


Recreate each ".wav" file on a given folder while placing calls at the beginning of sound window. New ".wav" files will be stored on a new folder, which is automatically created.


align.wave( = NULL, = "Aligned",
  time.length = 1,
  time.perc = 0.005,
  flim = NULL,
  dBlevel = 25,
  f = 44100,
  wl = 512,
  ovlp = 70


filepath to the folder where ".wav" files are stored. Should be presented between quotation marks. By default: = NULL (i.e. user must specify the filepath to ".wav" files)

name of the folder where new ".wav" files will be stored. Should be presented between quotation marks. By default: = "Aligned"


intended length for the time (X-axis) in seconds. Should be a value that encompasses all sounds in the study. By default: time.length = 1


slight time gap (in percentage) relative to the intended length that encompass all sounds in the study (i.e. time.length). Intervals are added before and after the minimum and maximum time coordinates (X-values) from the selected curve of relative amplitude (dBlevel). By default: time.perc = 0.005 (i.e. 0.5%)


modifications of the frequency limits (Y-axis) to focus on acoustic units. Useful for recordings with low signal-to-noise ratio. Vector with two values in kHz. By default: flim = NULL


absolute amplitude value to be used as relative amplitude contour, which will serve as reference for call placement. By default: dBlevel = 25


sampling frequency of ".wav" files (in Hz). By default: f = 44100


length of the window for the analysis. By default: wl = 512


overlap between two successive windows (in %) for increased spectrogram resolution. By default: ovlp = 70


Pedro Rocha


MacLeod, N., Krieger, J. & Jones, K. E. (2013). Geometric morphometric approaches to acoustic signal analysis in mammalian biology. Hystrix, the Italian Journal of Mammalogy, 24(1), 110-125.

Rocha, P. & Romano, P. (2021) The shape of sound: A new R package that crosses the bridge between Bioacoustics and Geometric Morphometrics. Methods in Ecology and Evolution, 12(6), 1115-1121.

See Also


Useful links:



# Create temporary folder to store ".wav" files <- file.path(base::tempdir(), "align.wave")
if(!dir.exists( dir.create(

# Create temporary folder to store results <- file.path(base::tempdir(), "align.wave-output")
if(!dir.exists( dir.create(

# Select acoustic units to be analyzed
spectro(cuvieri, flim = c(0,3)) # Visualize sound data that will be used

# Cut acoustic units from original Wave
cut.cuvieri1 <- cutw(cuvieri, f=44100, from=0, to=0.5, output = "Wave")
cut.cuvieri2 <- cutw(cuvieri, f=44100, from=0.7, to=1.2, output = "Wave")
cut.cuvieri3 <- cutw(cuvieri, f=44100, from=1.4, to=1.9, output = "Wave")

# Export ".wav" files containing selected acoustic units and store on previosly created folder
writeWave(cut.cuvieri1, filename = file.path(, "cut.cuvieri1.wav"), extensible = FALSE)
writeWave(cut.cuvieri2, filename = file.path(, "cut.cuvieri2.wav"), extensible = FALSE)
writeWave(cut.cuvieri3, filename = file.path(, "cut.cuvieri3.wav"), extensible = FALSE)

# Align acoustic units selected at 1% of time lenght
align.wave( =, = "Aligned",
           time.length = 0.5, time.perc = 0.01, dBlevel = 25)

# Verify alignment using eigensound function featuring analysis.type = "twoDshape"
eigensound(analysis.type = "twoDshape", = file.path(, "Aligned"), =,
           flim=c(0, 3), tlim=c(0,0.5), dBlevel = 25, plot.exp = TRUE, = "jpeg")
# To see jpeg files created, check folder specified by

p-rocha/SoundShape documentation built on Aug. 29, 2023, 10:57 p.m.