Read an SSFF or audio file into an AsspDataObj
read_ssff.RdA user-facing wrapper around the internal ASSP C-level reader.
Interface is identical to the legacy read.AsspDataObj.
Usage
read_ssff(
fname,
begin = 0,
end = 0,
samples = FALSE,
zero_to_na = FALSE,
tracks = NULL,
threads = 1L,
snap = c("none", "nearest")
)Arguments
- fname
Path to an SSFF or native ASSP audio file (WAV, AU, NIST, etc.).
- begin
Start of region to read (seconds, or samples if
samples=TRUE). Default 0 = file start.- end
End of region to read (seconds, or samples if
samples=TRUE). Default 0 = file end.- samples
Logical. If
TRUE,begin/endare in samples; otherwise in seconds.- zero_to_na
Logical. If
TRUE, stored values that are exactly0are returned asNAfor every track that is not sampled audio (SSFF has no NA encoding;0is its substitute). DefaultFALSE, i.e. the values exactly as stored.read_trackpassesTRUEfor SSFF files.- tracks
Optional character vector of track names to read.
NULL(default) reads every track; other tracks are skipped without being converted, which is considerably faster for files that store more than one track.- threads
Number of threads used to convert large files (default 1, serial). Values above 1 need a build with OpenMP support; the results are identical either way.
- snap
One of
"none"(default) or"nearest". A single time point (begin == end, both non-zero) that does not fall exactly on an analysis-frame boundary errors by default — this matcheswrassp::read.AsspDataObj()exactly, since faithfulness to the reference implementation is the priority. Pass"nearest"to instead round such a request to the nearest frame and return it. No effect whensamples = TRUE, when reading a range (begin != end), or forbegin == end == 0(whole file).
Value
An AsspDataObj. For audio files, contains an audio
track (n_samples x n_channels). For SSFF tracks, contains one matrix per
stored track (e.g. F0, fm, bw, rms) at the
analysis frame rate. Standard attributes include sampleRate,
startTime, startRecord, endRecord, trackFormats
and filePath.
See also
read_audio for universal format support including MP3/MP4.
Examples
if (FALSE) { # \dontrun{
# Read an audio file from the bundled samples
wav <- system.file("samples", "sustained", "a1.wav", package = "superassp")
au <- read_ssff(wav)
names(au) # "audio"
attr(au, "sampleRate") # native sample rate
# Read an SSFF parameter track produced earlier by a trk_* function
f0_path <- tempfile(fileext = ".f0")
trk_pitch_rapt(wav, toFile = TRUE, outputDirectory = dirname(f0_path),
explicitExt = "f0")
f0_obj <- read_ssff(file.path(dirname(f0_path),
paste0(tools::file_path_sans_ext(basename(wav)), ".f0")))
names(f0_obj)
} # }