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, MediaDecoder};
use web_audio_api::node::{AudioNode, AudioControllableSourceNode, AudioScheduledSourceNode};

let context = AudioContext::new(None);

// setup background music:
// read from local file
let file = File::open("samples/major-scale.ogg").unwrap();
// decode file to media stream
let stream = MediaDecoder::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

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 media decoding (OGG, WAV, FLAC, ..)

The AudioNode interface and concrete types

AudioParam interface

Primitives related to audio graph rendering

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

Maximum number of channels for audio processing

Render quantum size, the audio graph is rendered in blocks of RENDER_QUANTUM_SIZE samples see. https://webaudio.github.io/web-audio-api/#render-quantum