[−][src]Module cala::audio
API for recording / playing audio. Enable with the audio
feature.
Usage
The following example shows how to play audio as it's being recorded. Headphones recommended.
use std::collections::VecDeque; // The program data context. struct Data { buffer: VecDeque<(i16, i16)>, } // Set the home loop to `run()`. cala::init!(run, Data { buffer: VecDeque::new(), }); fn run(data: &mut Data) -> cala::Loop<Data> { // Record some sound. cala::record(&mut |_whichmic, l, r| { data.buffer.push_back((l, r)); }); // Play that sound. cala::play(&mut || { if let Some((lsample, rsample)) = data.buffer.pop_front() { cala::AudioSample::stereo(lsample, rsample) } else { // Play silence if not enough has been recorded yet. cala::AudioSample::stereo(0, 0) } }); cala::Continue }
Structs
AudioSample | An AudioSample (with surround sound 5.1 support). |
Enums
SampleRate | 3 sample rates which are supported by this crate. |
Functions
play | Play Audio. Callback generates audio samples sent directly to speakers. |
record | Record Audio. Callback's parameters are (microphone ID, left sample, right sample). |
set_play_hz | Set the |
set_record_hz | Set the |