reset examples
This commit is contained in:
parent
935fa280d3
commit
cf1a928b84
|
@ -22,7 +22,6 @@ hound = "3.4"
|
||||||
ringbuf = "0.1.6"
|
ringbuf = "0.1.6"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
# winapi = { path = "../winapi-rs", version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "errhandlingapi", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "std", "synchapi", "winbase", "winuser"] }
|
|
||||||
winapi = { version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "profileapi", "std", "synchapi", "winbase", "winuser"] }
|
winapi = { version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "profileapi", "std", "synchapi", "winbase", "winuser"] }
|
||||||
asio-sys = { version = "0.1", path = "asio-sys", optional = true }
|
asio-sys = { version = "0.1", path = "asio-sys", optional = true }
|
||||||
parking_lot = "0.9"
|
parking_lot = "0.9"
|
||||||
|
|
|
@ -5,13 +5,11 @@ use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
|
|
||||||
fn main() -> Result<(), anyhow::Error> {
|
fn main() -> Result<(), anyhow::Error> {
|
||||||
let host = cpal::default_host();
|
let host = cpal::default_host();
|
||||||
//let host =
|
|
||||||
// cpal::host_from_id(cpal::platform::HostId::Asio).expect("failed to initialise ASIO host");
|
|
||||||
let device = host
|
let device = host
|
||||||
.default_output_device()
|
.default_output_device()
|
||||||
.expect("failed to find a default output device");
|
.expect("failed to find a default output device");
|
||||||
let config = device.default_output_config()?;
|
let config = device.default_output_config()?;
|
||||||
println!("{:#?}", &config);
|
|
||||||
match config.sample_format() {
|
match config.sample_format() {
|
||||||
cpal::SampleFormat::F32 => run::<f32>(&device, &config.into())?,
|
cpal::SampleFormat::F32 => run::<f32>(&device, &config.into())?,
|
||||||
cpal::SampleFormat::I16 => run::<i16>(&device, &config.into())?,
|
cpal::SampleFormat::I16 => run::<i16>(&device, &config.into())?,
|
||||||
|
@ -25,9 +23,6 @@ fn run<T>(device: &cpal::Device, config: &cpal::StreamConfig) -> Result<(), anyh
|
||||||
where
|
where
|
||||||
T: cpal::Sample,
|
T: cpal::Sample,
|
||||||
{
|
{
|
||||||
let mut config: cpal::StreamConfig = config.clone();
|
|
||||||
config.buffer_size = cpal::BufferSize::Fixed(16);
|
|
||||||
|
|
||||||
let sample_rate = config.sample_rate.0 as f32;
|
let sample_rate = config.sample_rate.0 as f32;
|
||||||
let channels = config.channels as usize;
|
let channels = config.channels as usize;
|
||||||
|
|
||||||
|
@ -41,9 +36,8 @@ where
|
||||||
let err_fn = |err| eprintln!("an error occurred on stream: {}", err);
|
let err_fn = |err| eprintln!("an error occurred on stream: {}", err);
|
||||||
|
|
||||||
let stream = device.build_output_stream(
|
let stream = device.build_output_stream(
|
||||||
&config,
|
config,
|
||||||
move |data: &mut [T], _: &cpal::OutputCallbackInfo| {
|
move |data: &mut [T], _: &cpal::OutputCallbackInfo| {
|
||||||
println!("data len = {}", data.len());
|
|
||||||
write_data(data, channels, &mut next_value)
|
write_data(data, channels, &mut next_value)
|
||||||
},
|
},
|
||||||
err_fn,
|
err_fn,
|
||||||
|
|
|
@ -16,9 +16,8 @@ use ringbuf::RingBuffer;
|
||||||
const LATENCY_MS: f32 = 150.0;
|
const LATENCY_MS: f32 = 150.0;
|
||||||
|
|
||||||
fn main() -> Result<(), anyhow::Error> {
|
fn main() -> Result<(), anyhow::Error> {
|
||||||
//let host = cpal::default_host();
|
let host = cpal::default_host();
|
||||||
let host =
|
|
||||||
cpal::host_from_id(cpal::platform::HostId::Asio).expect("failed to initialise ASIO host");
|
|
||||||
// Default devices.
|
// Default devices.
|
||||||
let input_device = host
|
let input_device = host
|
||||||
.default_input_device()
|
.default_input_device()
|
||||||
|
@ -30,8 +29,7 @@ fn main() -> Result<(), anyhow::Error> {
|
||||||
println!("Using default output device: \"{}\"", output_device.name()?);
|
println!("Using default output device: \"{}\"", output_device.name()?);
|
||||||
|
|
||||||
// We'll try and use the same configuration between streams to keep it simple.
|
// We'll try and use the same configuration between streams to keep it simple.
|
||||||
let mut config: cpal::StreamConfig = input_device.default_input_config()?.into();
|
let config: cpal::StreamConfig = input_device.default_input_config()?.into();
|
||||||
//config.buffer_size = cpal::BufferSize::Fixed(1024);
|
|
||||||
|
|
||||||
// Create a delay in case the input and output devices aren't synced.
|
// Create a delay in case the input and output devices aren't synced.
|
||||||
let latency_frames = (LATENCY_MS / 1_000.0) * config.sample_rate.0 as f32;
|
let latency_frames = (LATENCY_MS / 1_000.0) * config.sample_rate.0 as f32;
|
||||||
|
@ -45,11 +43,10 @@ fn main() -> Result<(), anyhow::Error> {
|
||||||
for _ in 0..latency_samples {
|
for _ in 0..latency_samples {
|
||||||
// The ring buffer has twice as much space as necessary to add latency here,
|
// The ring buffer has twice as much space as necessary to add latency here,
|
||||||
// so this should never fail
|
// so this should never fail
|
||||||
producer.push(0).unwrap();
|
producer.push(0.0).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let input_data_fn = move |data: &[i16], _: &cpal::InputCallbackInfo| {
|
let input_data_fn = move |data: &[f32], _: &cpal::InputCallbackInfo| {
|
||||||
println!("data len = {}", data.len());
|
|
||||||
let mut output_fell_behind = false;
|
let mut output_fell_behind = false;
|
||||||
for &sample in data {
|
for &sample in data {
|
||||||
if producer.push(sample).is_err() {
|
if producer.push(sample).is_err() {
|
||||||
|
@ -61,14 +58,14 @@ fn main() -> Result<(), anyhow::Error> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let output_data_fn = move |data: &mut [i16], _: &cpal::OutputCallbackInfo| {
|
let output_data_fn = move |data: &mut [f32], _: &cpal::OutputCallbackInfo| {
|
||||||
let mut input_fell_behind = None;
|
let mut input_fell_behind = None;
|
||||||
for sample in data {
|
for sample in data {
|
||||||
*sample = match consumer.pop() {
|
*sample = match consumer.pop() {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
input_fell_behind = Some(err);
|
input_fell_behind = Some(err);
|
||||||
0
|
0.0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue