-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from klangner/audio_sink
Audio sink
- Loading branch information
Showing
29 changed files
with
213 additions
and
214 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
[package] | ||
name = "dsp" | ||
version = "0.10.2" | ||
version = "0.11.0" | ||
authors = ["Krzysztof Langner <[email protected]>"] | ||
description = "Digital Signal Processing" | ||
keywords = ["dsp"] | ||
license = "MIT OR Apache-2.0" | ||
license = "Apache-2.0" | ||
repository = "https://github.com/klangner/dsp" | ||
homepage = "https://github.com/klangner/dsp" | ||
documentation = "https://docs.rs/dsp" | ||
edition = "2018" | ||
edition = "2021" | ||
|
||
[features] | ||
default = ["audio"] | ||
|
@@ -17,31 +17,35 @@ random = ["rand", "rand_distr"] | |
|
||
[dependencies] | ||
anyhow = "1.0" | ||
arraydeque = "^0.4" | ||
byteorder = "1" | ||
itertools = "^0.10" | ||
num-complex = "^0.4" | ||
rustfft = "^6" | ||
cpal = { version = "0.13.4", optional = true } | ||
audrey = { version = "^0.3", optional = true } | ||
rand = { version = "^0.8", optional = true } | ||
rand_distr = {version = "^0.4", optional = true } | ||
arraydeque = "0.5" | ||
byteorder = "1.5" | ||
itertools = "0.12" | ||
num-complex = "0.4" | ||
rustfft = "6.2" | ||
cpal = { version = "0.15", optional = true } | ||
audrey = { version = "0.3", optional = true } | ||
rand = { version = "0.8", optional = true } | ||
rand_distr = {version = "0.4", optional = true } | ||
|
||
[dev-dependencies] | ||
assert_approx_eq = "^1.1" | ||
gnuplot = "^0.0.37" | ||
clap = "^2" | ||
lewton = "^0.10" | ||
criterion = "^0.3.5" | ||
matfile = "0.3" | ||
transpose = "^0.2" | ||
pitch_calc = "^0.12" | ||
assert_approx_eq = "1.1" | ||
gnuplot = "0.0.41" | ||
clap = { version = "4", features = ["derive"] } | ||
lewton = "0.10" | ||
criterion = "0.5" | ||
matfile = "0.4" | ||
transpose = "0.2" | ||
pitch_calc = "0.12" | ||
crossbeam-deque = "0.8" | ||
|
||
[[bench]] | ||
name = "gen_bench" | ||
harness = false | ||
|
||
[[example]] | ||
name = "play" | ||
required-features = ["audio"] | ||
|
||
[[example]] | ||
name = "tuner" | ||
required-features = ["audio"] | ||
|
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
use dsp::core::generator::Sine; | ||
use dsp::node::SourceNode; | ||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; | ||
|
||
|
||
const SAMPLE_RATE: u32 = 44100; | ||
const BUFFER_SIZE: u32 = 1024; | ||
|
||
|
||
fn main() { | ||
let mut generator = Sine::new(440., SAMPLE_RATE as usize); | ||
|
||
// Init output device | ||
let host = cpal::default_host(); | ||
|
||
let device = host | ||
.default_output_device() | ||
.ok_or_else(|| anyhow::Error::msg("Default output device is not available")).unwrap(); | ||
|
||
let config = cpal::StreamConfig { | ||
channels: 1, | ||
sample_rate: cpal::SampleRate(SAMPLE_RATE), | ||
buffer_size: cpal::BufferSize::Fixed(BUFFER_SIZE), | ||
}; | ||
|
||
let stream = device.build_output_stream( | ||
&config, | ||
move |data: &mut [f32], _: &cpal::OutputCallbackInfo| { | ||
generator.write_buffer(data).unwrap(); | ||
}, | ||
move |err| {panic!("cpal stream error {:?}", err);}, | ||
None | ||
).unwrap(); | ||
|
||
stream.play().unwrap(); | ||
|
||
std::thread::sleep(std::time::Duration::from_millis(1_000)); | ||
} |
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.