diff options
| author | Alejandro Sior <aho@sior.be> | 2022-10-30 19:03:34 +0100 |
|---|---|---|
| committer | Alejandro Sior <aho@sior.be> | 2022-10-30 19:03:34 +0100 |
| commit | c1a28c918e4b7625356a3bd221c2f43cd5973af9 (patch) | |
| tree | 0328ef480f33a26835e9aacd5164b5a486f33932 /src/main.rs | |
initial commit
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..799496b --- /dev/null +++ b/src/main.rs @@ -0,0 +1,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!"); +} |
