Skip to content

Commit 11ada42

Browse files
committed
Add benchmark for HRTF panners
1 parent 87f6dae commit 11ada42

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

benches/my_benchmark.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use iai::black_box;
22

33
use web_audio_api::context::BaseAudioContext;
44
use web_audio_api::context::OfflineAudioContext;
5-
use web_audio_api::node::AudioNode;
6-
use web_audio_api::node::AudioScheduledSourceNode;
5+
use web_audio_api::node::{AudioNode, AudioScheduledSourceNode, PanningModelType};
76

87
const SAMPLE_RATE: f32 = 48000.;
98
const DURATION: usize = 10;
@@ -197,6 +196,27 @@ pub fn bench_analyser_node() {
197196
assert_eq!(ctx.start_rendering_sync().length(), SAMPLES);
198197
}
199198

199+
pub fn bench_hrtf_panners() {
200+
let ctx = OfflineAudioContext::new(2, black_box(SAMPLES), SAMPLE_RATE);
201+
202+
let mut panner1 = ctx.create_panner();
203+
panner1.set_panning_model(PanningModelType::HRTF);
204+
panner1.position_x().set_value(10.0);
205+
panner1.connect(&ctx.destination());
206+
207+
let mut panner2 = ctx.create_panner();
208+
panner2.set_panning_model(PanningModelType::HRTF);
209+
panner2.position_x().set_value(-10.0);
210+
panner2.connect(&ctx.destination());
211+
212+
let mut osc = ctx.create_oscillator();
213+
osc.connect(&panner1);
214+
osc.connect(&panner2);
215+
osc.start();
216+
217+
assert_eq!(ctx.start_rendering_sync().length(), SAMPLES);
218+
}
219+
200220
iai::main!(
201221
bench_ctor,
202222
bench_sine,
@@ -209,4 +229,5 @@ iai::main!(
209229
bench_stereo_positional,
210230
bench_stereo_panning_automation,
211231
bench_analyser_node,
232+
bench_hrtf_panners,
212233
);

0 commit comments

Comments
 (0)