Expand description
Rust audio types and conversions.
An audio buffer can be cheaply converted to and from raw samples (i16, u8, f32, and f64) buffers, enabling interoperability with other crates.
Many audio formats are supported:
- Any integer sample rate (32 bits needed to support at least 96_000 Hz)
- Common bit depths (you can use 16-bit to fake 12-/10-/8-bit, as well as
fake unsigned by XOR’ing the top bit)
- 16-bit Signed Integer PCM (Listening/publishing standard)
- 24-bit Signed Integer PCM (Older recording/processing standard)
- 32-bit Float PCM (Newer recording/processing standard)
- 64-bit Float PCM (Ultra high-quality audio standard)
- Up to 8 channels (following FLAC/SMPTE/ITU-R recommendations):
- 1 Channel: Mono (Mono)
- 2 Channels: Stereo (Left, Right)
- 3 Channels: Surround 3.0 (Left, Right, Center)
- 4 Channels: Surround 4.0 (FrontL, FrontR, SurroundL, SurroundR)
- 5 Channels: Surround 5.0 (FrontL, FrontR, Front, SurroundL, SurroundR)
- 6 Channels: Surround 5.1 (FrontL, FrontR, Front, Lfe, SurroundL, SurroundR)
- 7 Channels: Surround 6.1 (FrontL, FrontR, Front, Lfe, Back, Left, Right)
- 8 Channels: Surround 7.1 (FrontL, FrontR, Front, Lfe, BackL, BackR, Left, Right)
§Getting Started
To understand some of the concepts used in this library, this MDN article is a good read (although the stuff about compression isn’t relevant to this crate’s functionality). This crate uses the MDN definitions for what an audio frame and audio channel are.
§8-Bit Sawtooth Wave Example
use fon::chan::{Ch16, Ch32};
use fon::pos::Mono;
use fon::Audio;
let mut a = Audio::<Ch32, 1>::with_silence(48_000, 256);
let mut counter = 0.0;
for f in a.iter_mut() {
f[Mono] = counter.into();
counter += 0.05;
counter %= 1.0;
}
let mut audio = Audio::<Ch16, 1>::with_audio(48_000, &a);
Modules§
- Audio channels (left, right, etc.). Each channel contains a single sample.
- Speaker/channel positions within a speaker configuration.
Structs§
- Audio buffer (fixed-size array of audio
Frame
s at sample rate specified in hertz). - Returned from
Audio::sink()
. - Frame - A number of interleaved sample channels.
- Sink that converts to a different audio format before passing to another
Sink
. - Stream resampler.
Traits§
- Audio sink - a type that consumes audio samples.