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

Audio nodes: don't use atomics for interior mutability #350

Merged
merged 12 commits into from
Sep 21, 2023
Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let file = std::fs::File::open("samples/major-scale.ogg").unwrap();
let buffer = context.decode_audio_data_sync(file).unwrap();

// setup an AudioBufferSourceNode
let src = context.create_buffer_source();
let mut src = context.create_buffer_source();
src.set_buffer(buffer);
src.set_loop(true);

Expand Down
20 changes: 10 additions & 10 deletions benches/my_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn bench_ctor() {

pub fn bench_sine() {
let ctx = OfflineAudioContext::new(2, black_box(SAMPLES), SAMPLE_RATE);
let osc = ctx.create_oscillator();
let mut osc = ctx.create_oscillator();

osc.connect(&ctx.destination());
osc.start();
Expand All @@ -26,7 +26,7 @@ pub fn bench_sine() {

pub fn bench_sine_gain() {
let ctx = OfflineAudioContext::new(2, black_box(SAMPLES), SAMPLE_RATE);
let osc = ctx.create_oscillator();
let mut osc = ctx.create_oscillator();
let gain = ctx.create_gain();

osc.connect(&gain);
Expand All @@ -40,7 +40,7 @@ pub fn bench_sine_gain() {
pub fn bench_sine_gain_delay() {
let ctx = OfflineAudioContext::new(2, black_box(SAMPLES), SAMPLE_RATE);

let osc = ctx.create_oscillator();
let mut osc = ctx.create_oscillator();
let gain = ctx.create_gain();

let delay = ctx.create_delay(0.3);
Expand All @@ -61,7 +61,7 @@ pub fn bench_buffer_src() {
let file = std::fs::File::open("samples/think-stereo-48000.wav").unwrap();
let buffer = ctx.decode_audio_data_sync(file).unwrap();

let src = ctx.create_buffer_source();
let mut src = ctx.create_buffer_source();
src.connect(&ctx.destination());
src.set_buffer(buffer);
src.start();
Expand All @@ -78,7 +78,7 @@ pub fn bench_buffer_src_delay() {
let delay = ctx.create_delay(0.3);
delay.delay_time().set_value(0.2);

let src = ctx.create_buffer_source();
let mut src = ctx.create_buffer_source();
src.set_buffer(buffer);
src.start();

Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn bench_buffer_src_iir() {
iir.connect(&ctx.destination());

// Play buffer and pipe to filter
let src = ctx.create_buffer_source();
let mut src = ctx.create_buffer_source();
src.connect(&iir);
src.set_buffer(buffer);
src.start();
Expand All @@ -126,7 +126,7 @@ pub fn bench_buffer_src_biquad() {
biquad.frequency().set_value(200.);

// Play buffer and pipe to filter
let src = ctx.create_buffer_source();
let mut src = ctx.create_buffer_source();
src.connect(&biquad);
src.set_buffer(buffer);
src.start();
Expand All @@ -150,7 +150,7 @@ pub fn bench_stereo_positional() {
panner.orientation_z().set_value(3.);

// Play buffer and pipe to filter
let src = ctx.create_buffer_source();
let mut src = ctx.create_buffer_source();
src.connect(&panner);
src.set_buffer(buffer);
src.start();
Expand All @@ -168,7 +168,7 @@ pub fn bench_stereo_panning_automation() {
panner.pan().set_value_at_time(-1., 0.);
panner.pan().set_value_at_time(0.2, 0.5);

let src = ctx.create_buffer_source();
let mut src = ctx.create_buffer_source();
src.connect(&panner);
src.set_buffer(buffer);
src.set_loop(true);
Expand All @@ -188,7 +188,7 @@ pub fn bench_analyser_node() {
let analyser = ctx.create_analyser();
analyser.connect(&ctx.destination());

let src = ctx.create_buffer_source();
let mut src = ctx.create_buffer_source();
src.connect(&analyser);
src.set_buffer(buffer);
src.set_loop(true);
Expand Down
4 changes: 2 additions & 2 deletions examples/amplitude_modulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
modulated.gain().set_value(0.5);
modulated.connect(&context.destination());

let carrier = context.create_oscillator();
let mut carrier = context.create_oscillator();
carrier.connect(&modulated);
carrier.frequency().set_value(300.);

Expand All @@ -38,7 +38,7 @@ fn main() {
depth.gain().set_value(0.5);
depth.connect(modulated.gain());

let modulator = context.create_oscillator();
let mut modulator = context.create_oscillator();
modulator.connect(&depth);
modulator.frequency().set_value(1.);

Expand Down
4 changes: 2 additions & 2 deletions examples/analyser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ fn main() {
..AudioContextOptions::default()
});

let analyser = context.create_analyser();
let mut analyser = context.create_analyser();
analyser.connect(&context.destination());

let osc = context.create_oscillator();
let mut osc = context.create_oscillator();
osc.frequency().set_value(200.);
osc.connect(&analyser);
osc.start();
Expand Down
4 changes: 2 additions & 2 deletions examples/audio_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() {
buffer.copy_to_channel(&sine, 0);

// play the buffer in a loop
let src = context.create_buffer_source();
let mut src = context.create_buffer_source();
src.set_buffer(buffer.clone());
src.set_loop(true);
src.connect(&context.destination());
Expand All @@ -55,7 +55,7 @@ fn main() {
// play a sine at 200Hz
println!("> Play sine at 200Hz from an OscillatorNode");

let osc = context.create_oscillator();
let mut osc = context.create_oscillator();
osc.frequency().set_value(200.);
osc.connect(&context.destination());
osc.start_at(context.current_time());
Expand Down
2 changes: 1 addition & 1 deletion examples/audio_buffer_source_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {
let file = File::open("samples/sample.wav").unwrap();
let buffer = context.decode_audio_data_sync(file).unwrap();

let src = context.create_buffer_source();
let mut src = context.create_buffer_source();
src.connect(&context.destination());
src.set_buffer(buffer);

Expand Down
6 changes: 3 additions & 3 deletions examples/audio_buffer_source_pitching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() {
buffer.copy_to_channel(&sine, 0);

// play the buffer in a loop
let src = context.create_buffer_source();
let mut src = context.create_buffer_source();
src.set_buffer(buffer.clone());
src.connect(&context.destination());
src.start();
Expand All @@ -52,7 +52,7 @@ fn main() {

println!("> Play sine at 440Hz w/ playback rate at 0.5");

let src = context.create_buffer_source();
let mut src = context.create_buffer_source();
src.set_buffer(buffer.clone());
src.playback_rate().set_value(0.5);
src.connect(&context.destination());
Expand All @@ -62,7 +62,7 @@ fn main() {

println!("> Play sine at 440Hz w/ detune at -1200.");

let src = context.create_buffer_source();
let mut src = context.create_buffer_source();
src.set_buffer(buffer.clone());
src.detune().set_value(-1200.);
src.connect(&context.destination());
Expand Down
Loading