Module sdl2::audio
[−]
[src]
Audio Functions
Example
use sdl2::audio::{AudioCallback, AudioDevice, AudioSpecDesired}; struct SquareWave { phase_inc: f32, phase: f32, volume: f32 } impl AudioCallback for SquareWave { type Channel = f32; fn callback(&mut self, out: &mut [f32]) { // Generate a square wave for x in out.iter_mut() { *x = match self.phase { 0.0...0.5 => self.volume, _ => -self.volume }; self.phase = (self.phase + self.phase_inc) % 1.0; } } } let _sdl_context = sdl2::init().audio().unwrap(); let desired_spec = AudioSpecDesired { freq: Some(44100), channels: Some(1), // mono samples: None // default sample size }; let device = AudioDevice::open_playback(None, desired_spec, |spec| { // initialize the audio callback SquareWave { phase_inc: 440.0 / spec.freq as f32, phase: 0.0, volume: 0.25 } }).unwrap(); // Start playback device.resume(); // Play for 2 seconds sdl2::timer::delay(2000);
Structs
AudioCVT | |
AudioDevice |
Wraps SDL_AudioDeviceID and owns the callback data used by the audio device. |
AudioDeviceLockGuard |
Similar to |
AudioSpec | |
AudioSpecDesired | |
AudioSpecWAV |
Enums
AudioFormat | |
AudioStatus |
Traits
AudioCallback | |
AudioFormatNum |
A phantom type for retreiving the SDL_AudioFormat of a given generic type. All format types are returned as native-endian. |
Functions
audio_init | |
audio_quit | |
get_audio_device_name | |
get_audio_driver | |
get_current_audio_driver | |
get_num_audio_devices | |
get_num_audio_drivers |