Crate web_audio_api[−][src]
Expand description
A high-level API for processing and synthesizing audio.
Example
use std::fs::File; use web_audio_api::context::{AsBaseAudioContext, AudioContext}; use web_audio_api::media::{MediaElement, OggVorbisDecoder}; use web_audio_api::node::{AudioNode, AudioControllableSourceNode, AudioScheduledSourceNode}; let context = AudioContext::new(); // setup background music: // read from local file let file = File::open("sample.ogg").unwrap(); // decode file to media stream let stream = OggVorbisDecoder::try_new(file).unwrap(); // wrap stream in MediaElement, so we can control it (loop, play/pause) let mut media = MediaElement::new(stream); // register as media element in the audio context let background = context.create_media_element_source(media); // use a gain node to control volume let gain = context.create_gain(); // play at low volume gain.gain().set_value(0.5); // connect the media node to the gain node background.connect(&gain); // connect the gain node to the destination node (speakers) gain.connect(&context.destination()); // start playback background.set_loop(true); background.start(); // mix in an oscillator sound let osc = context.create_oscillator(); osc.connect(&context.destination()); osc.start(); // enjoy listening //std::thread::sleep(std::time::Duration::from_secs(4));
Modules
alloc | Optimized audio signal data structures, used in AudioProcessors |
buffer | General purpose audio signal data structures |
context | The BaseAudioContext interface and the AudioContext and OfflineAudioContext types |
control | User controls for audio playback (play/pause/loop) |
media | Microphone input and OGG, WAV and MP3 decoding |
node | The AudioNode interface and concrete types |
param | AudioParam interface |
process | Audio processing code that runs on the audio rendering thread |
spatial | Spatialization/Panning primitives |
Structs
BufferDepletedError | Media stream buffering lags behind |
IndexSizeError | Input/output with this index does not exist |
SampleRate | Number of samples processed per second (Hertz) for a single channel of audio |
Constants
BUFFER_SIZE | Render quantum size (audio graph is rendered in blocks of this size) |
MAX_CHANNELS | Maximum number of channels for audio processing |