find_markers | R Documentation |
find_markers
find acoustic markers on test (re-recorded) sound files using spectrographic cross-correlation.
find_markers(
X,
markers = c("start_marker", "end_marker"),
test.files = NULL,
path = getOption("sound.files.path", "."),
pb = getOption("pb", TRUE),
cores = getOption("mc.cores", 1),
...
)
X |
Object of class 'data.frame', 'selection_table' or 'extended_selection_table' (the last 2 classes are created by the function |
markers |
Character vector with the name of the annotations (as in the column 'sound.id') to be used as templates for cross-correlation. Default is |
test.files |
Character vector of length 1 with the name(s) of the test (re-recorded) file(s) in which to search for the marker(s). If not supplied all sound files in 'path' are used instead. |
path |
Character string containing the directory path where test (re-recorded) sound files are found. |
pb |
Logical argument to control if progress bar is shown. Default is |
cores |
Numeric vector of length 1. Controls whether parallel computing is applied by specifying the number of cores to be used. Default is 1 (i.e. no parallel computing). Can be set globally for the current R session via the "mc.cores" option (see |
... |
Additional arguments to be passed to |
The function takes a master sound file's reference data ('X') and finds the position of acoustics markers ('markers' argument, included as selections in 'X') in the re-recorded sound files. This is used to align signals found in re-recorded sound files according to a master sound file referenced in 'X'. The position of the markers is determined as the highest spectrogram cross-correlation value for each marker using the functions template_correlator
and template_detector
. Make sure the master sound file (that referred to in 'X') is found in the same folder than the re-recorded sound files. Take a look at the package vignette for information on how to incorporate this function into a sound degradation analysis workflow. In cases in which markers are not correctly detected editing test sound files to remove audio segments with no target sounds (before the start marker and after the end marker) can improve performance. Using a low 'hop.size' or window length 'wl' (used internally by template_correlator
) can help to improve precision Other spectrogram types (argument 'type' in template_correlator
) can sometimes show better performance when markers are highly degraded.
A data frame with test file names, marker id, maximum cross-correlation score for each marker and the start and end where it was detected. If two or more markers are used the function computes an additional column, 'time.mismatch', that compares the time difference between the two markers in the test-files against that in the master sound file. In a perfect detection the value must be 0.
Marcelo Araya-Salas (marcelo.araya@ucr.ac.cr)
Araya-Salas M., E. Grabarczyk, M. Quiroz-Oliva, A. Garcia-Rodriguez, A. Rico-Guevara. (2023), baRulho: an R package to quantify degradation in animal acoustic signals .bioRxiv 2023.11.22.568305.
manual_realign
; auto_realign
; align_test_files
; master_sound_file
Other test sound alignment:
align_test_files()
,
auto_realign()
,
manual_realign()
,
plot_aligned_sounds()
{
# set temporary directory
td <- tempdir()
# load example data
data("master_est")
# save example files in working director to recreate a case in which working
# with sound files instead of extended selection tables.
# This doesn't have to be done with your own data as you will
# have them as sound files already.
for (i in unique(test_sounds_est$sound.files)[1:2]) {
writeWave(object = attr(test_sounds_est, "wave.objects")[[i]], file.path(td, i))
}
# save master file
writeWave(object = attr(master_est, "wave.objects")[[1]], file.path(td, "master.wav"))
# set path and no progress bar in global options
options(sound.files.path = td, pb = FALSE)
# get marker position
markers <- find_markers(X = master_est, test.files = unique(test_sounds_est$sound.files)[2])
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.