1 unstable release
0.0.1-alpha.2 | Feb 11, 2023 |
---|
#719 in Audio
20KB
496 lines
Encode and convert audio time spans between representations in number of samples, number of bytes and time duration.
#
// the Audio CD standard defines the encoding system as follows:
// 2 channels of LPCM audio, each signed 16-bit values sampled at 44100 Hz
let samples = Samples::<AUDIO_CD>::from_duration(Duration::from_secs(1));
assert_eq!(44_100, samples.get());
let bytes = samples.into_bytes();
assert_eq!(176_400, bytes.get());
// both `Samples` and `Bytes` can be converted back into `Duration`s:
assert_eq!(bytes.into_duration(), Duration::from_secs(1));
assert_eq!((samples * 2).into_duration(), Duration::from_secs(2));
// let's define our own `System`
const SYSTEM: System = system!(8_000, Mono, i16);
let samples = Samples::<SYSTEM>::from_duration(Duration::from_secs(1));
assert_eq!(8_000, samples.get());
let bytes = samples.into_bytes();
assert_eq!(16_000, bytes.get());
Dependencies
~0.4–0.8MB
~18K SLoC