-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/RustAudio/rodio into synt…
…h-waveforms
- Loading branch information
Showing
26 changed files
with
299 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use cpal::FromSample; | ||
use divan::Bencher; | ||
use rodio::Source; | ||
|
||
mod shared; | ||
use shared::TestSource; | ||
|
||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
#[divan::bench(types = [i16, u16, f32])] | ||
fn from_i16_to<T: rodio::Sample + FromSample<i16>>(bencher: Bencher) { | ||
bencher | ||
.with_inputs(|| TestSource::music_wav()) | ||
.bench_values(|source| { | ||
source | ||
.convert_samples::<T>() | ||
.for_each(divan::black_box_drop) | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::time::Duration; | ||
|
||
use divan::Bencher; | ||
use rodio::Source; | ||
|
||
mod shared; | ||
use shared::TestSource; | ||
|
||
fn main() { | ||
divan::main(); | ||
} | ||
|
||
#[divan::bench] | ||
fn reverb(bencher: Bencher) { | ||
bencher | ||
.with_inputs(|| TestSource::music_wav()) | ||
.bench_values(|source| { | ||
source | ||
.buffered() | ||
.reverb(Duration::from_secs_f32(0.05), 0.3) | ||
.for_each(divan::black_box_drop) | ||
}) | ||
} | ||
|
||
#[divan::bench] | ||
fn high_pass(bencher: Bencher) { | ||
bencher | ||
.with_inputs(|| TestSource::music_wav().to_f32s()) | ||
.bench_values(|source| source.high_pass(200).for_each(divan::black_box_drop)) | ||
} | ||
|
||
#[divan::bench] | ||
fn fade_out(bencher: Bencher) { | ||
bencher | ||
.with_inputs(|| TestSource::music_wav()) | ||
.bench_values(|source| { | ||
source | ||
.fade_out(Duration::from_secs(5)) | ||
.for_each(divan::black_box_drop) | ||
}) | ||
} | ||
|
||
#[divan::bench] | ||
fn amplify(bencher: Bencher) { | ||
bencher | ||
.with_inputs(|| TestSource::music_wav().to_f32s()) | ||
.bench_values(|source| source.amplify(0.8).for_each(divan::black_box_drop)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use std::io::Cursor; | ||
use std::time::Duration; | ||
use std::vec; | ||
|
||
use rodio::Source; | ||
|
||
pub struct TestSource<T> { | ||
samples: vec::IntoIter<T>, | ||
channels: u16, | ||
sample_rate: u32, | ||
total_duration: Duration, | ||
} | ||
|
||
impl<T> Iterator for TestSource<T> { | ||
type Item = T; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
self.samples.next() | ||
} | ||
} | ||
|
||
impl<T> ExactSizeIterator for TestSource<T> { | ||
fn len(&self) -> usize { | ||
self.samples.len() | ||
} | ||
} | ||
|
||
impl<T: rodio::Sample> Source for TestSource<T> { | ||
fn current_frame_len(&self) -> Option<usize> { | ||
None // forever | ||
} | ||
|
||
fn channels(&self) -> u16 { | ||
self.channels | ||
} | ||
|
||
fn sample_rate(&self) -> u32 { | ||
self.sample_rate | ||
} | ||
|
||
fn total_duration(&self) -> Option<Duration> { | ||
Some(self.total_duration) | ||
} | ||
} | ||
|
||
impl TestSource<i16> { | ||
pub fn music_wav() -> Self { | ||
let data = include_bytes!("../assets/music.wav"); | ||
let cursor = Cursor::new(data); | ||
|
||
let duration = Duration::from_secs(10); | ||
let sound = rodio::Decoder::new(cursor) | ||
.expect("music.wav is correctly encoded & wav is supported") | ||
.take_duration(duration); | ||
|
||
TestSource { | ||
channels: sound.channels(), | ||
sample_rate: sound.sample_rate(), | ||
total_duration: duration, | ||
samples: sound.into_iter().collect::<Vec<_>>().into_iter(), | ||
} | ||
} | ||
|
||
#[allow(unused, reason = "not everything from shared is used in all libs")] | ||
pub fn to_f32s(self) -> TestSource<f32> { | ||
let TestSource { | ||
samples, | ||
channels, | ||
sample_rate, | ||
total_duration, | ||
} = self; | ||
let samples = samples | ||
.map(|s| cpal::Sample::from_sample(s)) | ||
.collect::<Vec<_>>() | ||
.into_iter(); | ||
TestSource { | ||
samples, | ||
channels, | ||
sample_rate, | ||
total_duration, | ||
} | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.