Crate web_audio_api

source ·
Expand description

A high-level API for processing and synthesizing audio.

Example

use std::fs::File;
use web_audio_api::context::{BaseAudioContext, AudioContext};
use web_audio_api::node::{AudioNode, AudioScheduledSourceNode};

// set up AudioContext with optimized settings for your hardware
let context = AudioContext::default();

// create an audio buffer from a given file
let file = File::open("samples/sample.wav").unwrap();
let buffer = context.decode_audio_data_sync(file).unwrap();

// play the buffer at given volume
let volume = context.create_gain();
volume.connect(&context.destination());
volume.gain().set_value(0.5);

let mut buffer_source = context.create_buffer_source();
buffer_source.connect(&volume);
buffer_source.set_buffer(buffer);

// create oscillator branch
let mut osc = context.create_oscillator();
osc.connect(&context.destination());

// start the sources
buffer_source.start();
osc.start();

// enjoy listening
std::thread::sleep(std::time::Duration::from_secs(4));

Modules

  • The BaseAudioContext interface and the AudioContext and OfflineAudioContext types
  • Primitives of the MediaDevices API
  • Primitives of the Media Recorder API
  • Primitives of the Media Capture and Streams API
  • The AudioNode interface and concrete types
  • Primitives related to audio graph rendering
  • User-defined audio nodes and processors

Structs

Enums

  • Precision of AudioParam value calculation per render quantum

Constants