cpal/examples/beep.rs

23 lines
577 B
Rust
Raw Normal View History

2014-12-11 15:28:26 +00:00
extern crate cpal;
fn main() {
2014-12-17 08:16:26 +00:00
let mut channel = cpal::Voice::new();
2014-12-11 16:23:33 +00:00
2015-04-27 15:33:02 +00:00
// Produce a sinusoid of maximum amplitude.
let max = std::u16::MAX as f32;
let mut data_source = (0u64..).map(|t| t as f32 * 0.03)
.map(|t| ((t.sin() * 0.5 + 0.5) * max) as u16);
2014-12-11 16:23:33 +00:00
loop {
2014-12-22 13:16:47 +00:00
{
let mut buffer = channel.append_data(1, cpal::SamplesRate(44100), 32768);
2015-04-27 15:33:02 +00:00
for (sample, value) in buffer.iter_mut().zip(&mut data_source) {
2014-12-22 13:16:47 +00:00
*sample = value;
}
}
2014-12-22 13:16:47 +00:00
channel.play();
2014-12-11 16:23:33 +00:00
}
2014-12-11 15:28:26 +00:00
}