Expand description
Stem intake: decoding, mono, resampling and the Stem.
A file decodes at its native rate. A consumer that needs another rate
resamples. The Stem adds the beat grid, the band edge, the flat-top
flag and the stereo screen.
Samples are f64 from the decoder on. Every channel is kept, because the
stereo statistics need both. Mono is the mean of the first two channels,
the pair the stereo statistics read, with no gain normalisation. Only a consumer with a fixed input rate, such as the
transcription model, resamples; analysis stays at the native rate.
use sound_to_patch::audio::{self, SampleRate};
let stem = audio::decode("bass.wav".as_ref())?.into_audio();
let mono = stem.mono();
let model_rate = SampleRate::new(22_050)?;
let resampled = audio::resample(&mono, stem.sample_rate(), model_rate)?;Structs§
- Audio
- Decoded audio: one or more channels of equal length at one sample rate. Every sample is finite.
- Beat
Grid - The beat grid from the BPM. The BPM gives the beat period, not where the first beat falls, so the offset is given, never estimated; it defaults to 0.
- Decode
Error - A file that does not decode: the path and the cause.
- Decoded
- A decoded file: its audio and the packets that became silence.
- Division
- A note division, such as a dotted eighth, that an LFO rate can lock to.
- Resample
Error - A resampling that failed: both rates and rubato’s message.
- Sample
Rate - A sample rate in samples per second: a whole number above zero.
- Skipped
Packet - A packet that failed to decode and became silence.
- Stem
- The stem: native-rate samples with mid and side, the beat grid, the band edge, the flat-top flag and the stereo screen.
- Stereo
Screen - The stereo screen of a stem or of a sample range.
- Stereo
Stats - The statistics of one band. A value is
Nonewhen it does not exist: a silent channel, a zero mid or side, or no f0. - Tempo
- The tempo of a stem: the given one, the refined one and the one used.
Enums§
- Audio
Error - A rule that decoded audio breaks.
- Band
- The bands of the screen.
- Feel
- The feel of a note division.
- Note
Value - The length of a note division in beats, before its feel.
Constants§
- BAND_
EDGE_ CONVENTION - The convention of the band edge.
- BAND_
EDGE_ MARGIN_ DB - The margin above the noise floor that the fallback band-edge rule needs.
- BAND_
EDGE_ PLATEAU_ DB - The plateau allowance of a steep fall in the band-edge rule.
- BAND_
EDGE_ STEEP_ DROP_ DB - A fall of at least this much over one semitone marks a cutoff, and the band edge sits at its half-depth point. Synthetic cuts fall 57 to 91 dB there, a 2-pole roll-off about 1.3 dB.
- BPM_
STEP - The step of the tempo search, in BPM.
- CEILING_
TOLERANCE - Samples within this share of the peak count as at the ceiling.
- CLIP_
APPROACH - The approach share of a flat-top run.
- FLAT_
TOP_ MIN_ RUN_ S - The shortest run at the ceiling that counts as a flat top.
- FLAT_
TOP_ MIN_ SHARE - The share of samples in flat-top runs that marks a stem hard-limited.
- HARD_
LIMITED_ CONVENTION - The convention of the flat-top flag.
- HIGH_
EDGE_ HZ - The edge between the low-mid and the high band. The descriptors use it as a band edge too.
- LONG_
FRAME_ BELOW_ HZ - The median f0 below which harmonic analysis uses its long frame.
- MAX_
BEAT_ LAGS - The most beat lags the score sums.
- MAX_
SAMPLE_ RATE - The highest sample rate the analysis reads, the top of the standard export rates. The cost of the analysis grows faster than the rate.
- MAX_
SKIPPED_ PACKETS - The most packets a file may lose to decode errors.
- MIN_
BEAT_ LAGS - The fewest beat lags that refine a tempo; a shorter stem keeps the given tempo.
- MIN_
SAMPLE_ RATE - The lowest sample rate the analysis reads: the band-edge rule looks for its fall above 2 kHz, so it needs a Nyquist frequency well above that.
- OVERLAP_
BEATS - Beats of the stem that every lag keeps in its overlap, so the longest lag still averages several beats.
- PEAK_
RATIO_ MIN - The lowest ratio of the best score to the median score over the search that the refined tempo needs before it replaces the given one.
- PERIODICITY_
MIN - The lowest share of the onset strength that repeats at the refined beat.
- SCREEN_
FRAME_ LEN - The STFT frame length of the screen, for every f0.
- SCREEN_
HARMONICS - The harmonics whose cross-spectrum phase the screen averages.
- SEARCH_
SHARE - How far the given tempo may lie from the true one: the search covers
every tempo
twith|given / t - 1| <= SEARCH_SHARE. - SHARPNESS_
MIN - The lowest onset sharpness that trusts a refined tempo.
- SPARSE_
ONSETS_ MAX - The most onsets per beat for which the sparse periodicity trusts a tempo.
- SPARSE_
PERIODICITY_ MIN - The lowest share of the onset strength that repeats every 2 or every 4 refined beats, for a part whose beat periodicity is too low.
- STEREO_
CONVENTION - The convention of the screen.
- SUB_
EDGE_ HZ - The upper edge of the sub band.
- TEMPO_
CONVENTION - The convention of the refined tempo in
layers.json.
Functions§
- band_
edge - The band edge of a mono signal: see
BAND_EDGE_CONVENTION. - decode
- Decodes the default audio track of a file at its native rate, with every channel kept: the audio track the container flags as default, else the first one with a known codec.
- is_
flat_ topped - Whether a channel is flat-topped: see
HARD_LIMITED_CONVENTION. - mono_
mean - Mixes channels to mono as their mean. Mixing
L = xwithR = -xgives silence, andL = R = xgivesx. - resample
- Resamples a mono signal from one rate to another in
f64. - stereo_
screen - Runs the screen on two channels of equal length, or on a sample range
of them.
f0is the fundamental from the caller; without it everyipd_degisNone. - write_
wav - Writes
audiotopathas a WAV file of 32-bit float samples. Each sample rounds to the nearestf32. - write_
wav_ to - Writes
audiotooutaswrite_wavwrites it to a file.