reset examples
This commit is contained in:
parent
935fa280d3
commit
cf1a928b84
3 changed files with 11 additions and 21 deletions
|
|
@ -5,13 +5,11 @@ use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
|||
|
||||
fn main() -> Result<(), anyhow::Error> {
|
||||
let host = cpal::default_host();
|
||||
//let host =
|
||||
// cpal::host_from_id(cpal::platform::HostId::Asio).expect("failed to initialise ASIO host");
|
||||
let device = host
|
||||
.default_output_device()
|
||||
.expect("failed to find a default output device");
|
||||
let config = device.default_output_config()?;
|
||||
println!("{:#?}", &config);
|
||||
|
||||
match config.sample_format() {
|
||||
cpal::SampleFormat::F32 => run::<f32>(&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
|
||||
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 channels = config.channels as usize;
|
||||
|
||||
|
|
@ -41,9 +36,8 @@ where
|
|||
let err_fn = |err| eprintln!("an error occurred on stream: {}", err);
|
||||
|
||||
let stream = device.build_output_stream(
|
||||
&config,
|
||||
config,
|
||||
move |data: &mut [T], _: &cpal::OutputCallbackInfo| {
|
||||
println!("data len = {}", data.len());
|
||||
write_data(data, channels, &mut next_value)
|
||||
},
|
||||
err_fn,
|
||||
|
|
@ -65,4 +59,4 @@ where
|
|||
*sample = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue