Skip to content

Commit

Permalink
Add basic implementation of audio buffer and sample
Browse files Browse the repository at this point in the history
  • Loading branch information
regexident committed Jul 26, 2021
1 parent 0acd4a6 commit 960bba3
Show file tree
Hide file tree
Showing 8 changed files with 1,009 additions and 6 deletions.
17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,20 @@ repository = "https://github.com/webrtc-rs/media"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
util = { package = "webrtc-util", version = "0.3.0", default-features = false, features = [
"marshal",
] }

anyhow = "1.0.41"
byteorder = "1.4.3"
bytes = "1.0.1"
displaydoc = "0.2.1"
thiserror = "1.0.25"

[dev-dependencies]
criterion = { version = "0.3.4", features = ["html_reports"] }
nearly_eq = "0.2.4"

[[bench]]
name = "audio_buffer"
harness = false
39 changes: 39 additions & 0 deletions benches/audio_buffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};

use webrtc_media::audio::buffer::{
layout::{Deinterleaved, Interleaved},
Buffer,
};

fn benchmark_from(c: &mut Criterion) {
type Sample = i32;
let channels = 4;
let frames = 100_000;
let deinterleaved_buffer: Buffer<Sample, Deinterleaved> = {
let samples = (0..(channels * frames)).map(|i| i as i32).collect();
Buffer::new(samples, channels)
};
let interleaved_buffer: Buffer<Sample, Interleaved> = {
let samples = (0..(channels * frames)).map(|i| i as i32).collect();
Buffer::new(samples, channels)
};

c.bench_function("Buffer<T, Interleaved> => Buffer<T, Deinterleaved>", |b| {
b.iter(|| {
black_box(Buffer::<Sample, Interleaved>::from(
deinterleaved_buffer.as_ref(),
));
})
});

c.bench_function("Buffer<T, Deinterleaved> => Buffer<T, Interleaved>", |b| {
b.iter(|| {
black_box(Buffer::<Sample, Deinterleaved>::from(
interleaved_buffer.as_ref(),
));
})
});
}

criterion_group!(benches, benchmark_from);
criterion_main!(benches);
4 changes: 4 additions & 0 deletions src/audio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod buffer;
mod sample;

pub use sample::Sample;
Loading

0 comments on commit 960bba3

Please sign in to comment.