Crate audio_time

source ·
Expand description

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());

Re-exports

pub use ChannelLayout::Mono;
pub use ChannelLayout::Stereo;

Macros

Macro for easily creating a System.

Structs

An audio time span, measured in the number of bytes required for its representation.
Audio sampling rate, the number of samples in a single second (i.e. measured in hertz).
A type used to encode a single sample, created from a type that implements audio_core::Sample.
An audio time span, measured by the number of samples contained in it.
A struct that encodes all parameters that are needed to interpret an audio time span as number of samples and/or the number of bytes needed to represent it.

Enums

Constants

Audio CD encoding system.