Babycat is a library that makes it easy to decode and manipulate many audio files at once.
Babycat is built on top of a lot of other Rust and C libraries, such as:
- Symphonia for audio decoding
- libsamplerate for audio resampling
- Hound for encoding to WAV
Babycat provides a consistent audio API for performing many tasks. You are viewing Babycat's Rust documentation, but Babycat also has bindings for C, Python, and WebAssembly.
Terminology
Babycat uses the same audio terminology as the Apple Core Audio API:
- A channel is a discrete track of monophonic audio. A monophonic stream has one channel. A stereo stream has two channels. An audio stream that contains 5.1 surround sound will have five normal channels and one Low Frequency Enhancement (LFE) channel.
- A sample is single numerical value in a single audio channel in an audio stream.
- A frame is a collection of samples from the same point in time--one sample for each channel.
- The frame rate (or sample rate) for a stream is the number of frames per second (hertz) of uncompressed audio.
Babycat stores audio as a single array of interleaved samples from channels. A waveform with two channels (e.g. left and right) are stored as:
Resampling backends
Babycat has the ability to resample audio from one frame rate to another. There are several resampling backends available: Current valid values include:
-
RESAMPLE_MODE_LIBSAMPLERATE
: This uses libsamplerate at theSRC_SINC_BEST_QUALITY
setting. This is the highest-quality resampler currently offered by Babycat, although it is slightly slower than the other resamplers. This resampler is only available when Babycat is compiled with the Cargo featureenable-libsamplerate
enabled. This feature is enabled by default in Babycat's C, Python, and Rust frontends. The libsamplerate resampler is currently unavailable in Babycat's WebAssembly frontend because libsamplerate's dependency on libc makes it hard to compile it to thewasm32-unknown-unknown
target. -
RESAMPLE_MODE_BABYCAT_LANCZOS
: A Lanczos resampler to use when compiling to targets likewasm32-unknown-unknown
where libsamplerate cannot be compiled to. This is a simple impmenentation of a Lanczos resampler. This is the fastest (and lowest-quality) resampler available in Babycat. -
RESAMPLE_MODE_BABYCAT_SINC
: This is an implementation of a sinc resampler as described by Stanford professor Julius O. Smith. The speed and quality of this resampler is in between the above two.
Examples
Decode multiple audio files in parallel.
use ;
use waveforms_from_files;
// These are test files in the Babycat Git repository.
let filenames = &;
// Perform the following transformations on EACH track.
let waveform_args = WaveformArgs ;
let batch_args = Default default;
// Read and decode the tracks in parallel.
let batch = waveforms_from_files;
// Iterate over the results.
for named_result in batch