Replace example by a sinusoid generator

This commit is contained in:
Pierre Krieger 2014-12-11 17:51:58 +01:00
parent 873779aaa8
commit 03ccf4bfea
1 changed files with 18 additions and 1 deletions

View File

@ -3,8 +3,25 @@ extern crate cpal;
fn main() { fn main() {
let mut channel = cpal::Channel::new(); let mut channel = cpal::Channel::new();
let mut data_source =
std::iter::iterate(0.0f32, |f| f + 0.03)
.map(|angle| {
use std::num::FloatMath;
use std::num::Int;
let angle = angle.sin();
let max: u16 = Int::max_value();
let value = (max as f32 / 2.0) + (angle * (max as f32 / 2.0));
value as u16
})
.map(|v| (v, v));
loop { loop {
let mut buffer = channel.append_data::<(u16, u16)>(); let mut buffer = channel.append_data::<(u16, u16)>();
buffer[0] = std::rand::random();
for value in buffer.iter_mut() {
*value = data_source.next().unwrap();
}
} }
} }