-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check for empty buffers when dequeuing into host
- Loading branch information
Nico Chatzi
committed
Sep 23, 2023
1 parent
4637a2c
commit 3163919
Showing
6 changed files
with
73 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,57 @@ | ||
#[cfg(feature = "bench")] | ||
mod bench { | ||
use aud_lib::audio::*; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use crossbeam::channel::unbounded; | ||
use rand::random; | ||
use std::iter::repeat_with; | ||
use aud_lib::audio::*; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rand::random; | ||
use std::iter::repeat_with; | ||
|
||
fn bench_enqueue(c: &mut Criterion) { | ||
for buffer_size in [128, 256, 512, 1024] { | ||
let mut group = c.benchmark_group(format!("Enqueue Mono Buffer Size {}", buffer_size)); | ||
group.bench_function("Mono", |b| { | ||
let (sender, _receiver) = unbounded(); | ||
let input_channels = 1; | ||
let selected_channels = vec![0]; | ||
let enqueue_fn = test_make_audio_buffer_enqueueing_function( | ||
sender, | ||
input_channels, | ||
selected_channels, | ||
); | ||
let audio_buffer: Vec<f32> = repeat_with(|| random::<f32>()) | ||
.take(buffer_size * input_channels) | ||
.collect(); | ||
b.iter(|| { | ||
enqueue_fn(&audio_buffer); | ||
}); | ||
fn bench_enqueue(c: &mut Criterion) { | ||
for buffer_size in [128, 256, 512, 1024] { | ||
let mut group = c.benchmark_group(format!("Enqueue Mono Buffer Size {}", buffer_size)); | ||
group.bench_function("Mono", |b| { | ||
let (sender, _receiver) = crossbeam::channel::unbounded(); | ||
let input_channels = 1; | ||
let selected_channels = vec![0]; | ||
let enqueue_fn = test_make_audio_buffer_enqueueing_function( | ||
sender, | ||
input_channels, | ||
selected_channels, | ||
); | ||
let audio_buffer: Vec<f32> = repeat_with(|| random::<f32>()) | ||
.take(buffer_size * input_channels) | ||
.collect(); | ||
b.iter(|| { | ||
enqueue_fn(&audio_buffer); | ||
}); | ||
group.finish(); | ||
} | ||
}); | ||
group.finish(); | ||
} | ||
} | ||
|
||
fn bench_dequeue(c: &mut Criterion) { | ||
for buffer_size in [128, 256, 512, 1024] { | ||
let mut group = c.benchmark_group(format!("Dequeue Stereo Buffer Size {}", buffer_size)); | ||
group.bench_function("Stereo", |b| { | ||
let (sender, receiver) = crossbeam::channel::unbounded(); | ||
let total_channels = 2; | ||
let selected_channels = vec![0, 1]; | ||
let dequeue_fn = test_make_audio_dequeing_function( | ||
receiver.clone(), | ||
total_channels, | ||
selected_channels, | ||
); | ||
let mut audio_buffer: Vec<f32> = vec![0.0; buffer_size * total_channels]; | ||
|
||
fn bench_dequeue(c: &mut Criterion) { | ||
for buffer_size in [128, 256, 512, 1024] { | ||
let mut group = | ||
c.benchmark_group(format!("Dequeue Stereo Buffer Size {}", buffer_size)); | ||
group.bench_function("Stereo", |b| { | ||
let (_sender, receiver) = unbounded(); | ||
let total_channels = 2; | ||
let selected_channels = vec![0, 1]; | ||
let dequeue_fn = | ||
test_make_audio_dequeing_function(receiver, total_channels, selected_channels); | ||
let mut audio_buffer: Vec<f32> = vec![0.0; buffer_size * total_channels]; | ||
b.iter(|| { | ||
dequeue_fn(&mut audio_buffer); | ||
}); | ||
b.iter(|| { | ||
let mock_data = AudioBuffer::with_length( | ||
(buffer_size * total_channels) as u32, | ||
total_channels as u32, | ||
); | ||
sender.send(mock_data.clone()).unwrap(); // Clone the mock data | ||
dequeue_fn(&mut audio_buffer); | ||
}); | ||
group.finish(); | ||
} | ||
}); | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(host_audio_io, bench_enqueue, bench_dequeue); | ||
criterion_main!(host_audio_io); | ||
} | ||
|
||
criterion_group!(host_audio_io, bench_enqueue, bench_dequeue); | ||
criterion_main!(host_audio_io); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters