Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add AudioContextOptions to AudioContext #36

Merged
merged 18 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/biquad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use web_audio_api::node::{AudioControllableSourceNode, AudioNode, AudioScheduled

fn main() {
env_logger::init();
let context = AudioContext::new();
let context = AudioContext::new(None);

// setup background music:
// read from local file
Expand Down
43 changes: 43 additions & 0 deletions examples/merger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use web_audio_api::context::{AsBaseAudioContext, AudioContext, AudioContextOptions, LatencyHint};
use web_audio_api::node::{AudioNode, AudioScheduledSourceNode};

fn main() {
let options = AudioContextOptions {
sample_rate: Some(48_000),
channels: Some(2),
latency_hint: Some(LatencyHint::Playback),
};

let context = AudioContext::new(Some(options));

println!("Sample rate: {:?}", context.sample_rate());
println!("Channels: {}", context.destination().max_channels_count());

// Create an oscillator
let left = context.create_oscillator();

//Create an oscillator
let right = context.create_oscillator();
// set a different frequency to distinguish left from right osc
right.frequency().set_value(1000.);

// Create a merger
let merger = context.create_channel_merger(2);

// connect left osc to left input of the merger
left.connect_at(&merger, 0, 0).unwrap();
// connect right osc to left input of the merger
right.connect_at(&merger, 0, 1).unwrap();

// Connect the merger to speakers
merger.connect(&context.destination());

// Start the oscillators
left.start();
right.start();

// connect left osc to splitter

// enjoy listening
std::thread::sleep(std::time::Duration::from_secs(4));
}
2 changes: 1 addition & 1 deletion examples/microphone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use web_audio_api::node::AudioNode;

fn main() {
env_logger::init();
let context = AudioContext::new();
let context = AudioContext::new(None);

let stream = Microphone::new();
// register as media element in the audio context
Expand Down
2 changes: 1 addition & 1 deletion examples/oscillators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
env_logger::init();

// Create an audio context where all audio nodes lives
let context = AudioContext::new();
let context = AudioContext::new(None);

// Create an oscillator node with sine (default) type
let mut osc = context.create_oscillator();
Expand Down
2 changes: 1 addition & 1 deletion examples/shaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn make_distortion_curve(amount: usize) -> Vec<f32> {

fn main() {
env_logger::init();
let context = AudioContext::new();
let context = AudioContext::new(None);

// setup background music:
// read from local file
Expand Down
2 changes: 1 addition & 1 deletion examples/showcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use web_audio_api::node::{AudioControllableSourceNode, AudioNode, AudioScheduled

fn main() {
env_logger::init();
let context = AudioContext::new();
let context = AudioContext::new(None);

// setup background music:
// read from local file
Expand Down
2 changes: 1 addition & 1 deletion examples/spatial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use web_audio_api::node::AudioScheduledSourceNode;

fn main() {
env_logger::init();
let context = AudioContext::new();
let context = AudioContext::new(None);

// Create a friendly tone
let tone = context.create_oscillator();
Expand Down
2 changes: 1 addition & 1 deletion examples/stereo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use web_audio_api::node::{AudioNode, AudioScheduledSourceNode};

fn main() {
env_logger::init();
let context = AudioContext::new();
let context = AudioContext::new(None);

// Create an oscillator
let osc = context.create_oscillator();
Expand Down
2 changes: 1 addition & 1 deletion examples/worklet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl AudioProcessor for WhiteNoiseProcessor {

fn main() {
env_logger::init();
let context = AudioContext::new();
let context = AudioContext::new(None);

// construct new node in this context
let noise = WhiteNoiseNode::new(&context);
Expand Down
5 changes: 2 additions & 3 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ impl AudioBuffer {
}

/// Split an AudioBuffer in two at the given index.
pub fn split_off(&mut self, index: u32) -> AudioBuffer {
let index = index as usize;
pub fn split_off(&mut self, index: usize) -> AudioBuffer {
let sample_rate = self.sample_rate();

let channels: Vec<_> = self
Expand Down Expand Up @@ -467,7 +466,7 @@ impl<M: MediaStream> Iterator for Resampler<M> {
return Some(Ok(buffer));
}

self.buffer = Some(buffer.split_off(self.sample_len));
self.buffer = Some(buffer.split_off(self.sample_len as usize));

Some(Ok(buffer))
}
Expand Down