1 个不稳定版本
0.0.1-alpha.2 | 2023年2月11日 |
---|
#689 in 音频
20KB
496 行
通过样本数、字节数和时间持续时间在表示之间编码和转换音频时间范围。
#
// 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());
依赖项
~0.4–1MB
~20K SLoC