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

// 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

Optimized audio signal data structures, used in AudioProcessors

General purpose audio signal data structures

The BaseAudioContext interface and the AudioContext and OfflineAudioContext types

User controls for audio playback (play/pause/loop)

Microphone input and OGG, WAV and MP3 decoding

The AudioNode interface and concrete types

AudioParam interface

Audio processing code that runs on the audio rendering thread

Spatialization/Panning primitives

Structs

Media stream buffering lags behind

Input/output with this index does not exist

Number of samples processed per second (Hertz) for a single channel of audio

Constants

Render quantum size (audio graph is rendered in blocks of this size)

Maximum number of channels for audio processing