blob: 799496bcba3bc6c5bf07f33e63d1edeb0b9f104e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
use cpal::traits::HostTrait;
use cpal::traits::DeviceTrait;
use cpal::traits::StreamTrait;
fn main() {
let host = cpal::default_host();
let dev = host.default_output_device().expect("no audio device found");
let cfg: cpal::StreamConfig = dev.supported_output_configs()
.expect("couldn't find configs")
.next()
.expect("bogus device")
.with_max_sample_rate().into();
println!("sample rate {:?}", &cfg.sample_rate);
let mut i: f32 = 0.0;
let stream = dev.build_output_stream(
&cfg,
move |data: &mut [f32], _: &cpal::OutputCallbackInfo| {
println!("{}", &data.len());
for sample in data.iter_mut() {
*sample = cpal::Sample::from(&(i/384000.0*2.0*3.141592 * 340.0).sin());
i += 1.0;
}
},
move |err| {
println!("err: {}", err);
}
).expect("could not build stream");
stream.play().unwrap();
loop {}
println!("Hello, world!");
}
|