summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs37
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!");
+}