I tried to simplify the code but it is still not working:
#[task(binds = DMA1_STR1, shared = [], local = [audio, buffer, phase], priority = 8)]
fn audio_handler(mut ctx: audio_handler::Context) {
let audio = &mut ctx.local.audio;
let buffer = &mut ctx.local.buffer;
let phase = &mut ctx.local.phase;
audio.get_stereo(buffer);
for i in 0..buffer.len() {
match i {
0 => {
phase[i].0 = phase[phase.len()-1].0 + 440.0 / 48000.0;
phase[i].1 = phase[phase.len()-1].1 + 440.0 / 48000.0;
},
_ => {
phase[i].0 = phase[i-1].0 + 440.0 / 48000.0;
phase[i].1 = phase[i-1].1 + 440.0 / 48000.0;
}
}
let l = libm::sin((phase[i].0 * 2.0 * core::f32::consts::PI).into()) as f32;
let r = libm::sin((phase[i].1 * 2.0 * core::f32::consts::PI).into()) as f32;
audio.push_stereo((l, r)).unwrap();
};
}
Here I have init phase
exactly same as buffer
, a stereo f32 tuple.
When I flash it, it seems that there is a very short time of beeping.
I am sure my HW connection is correct as I can play the DSP example from the browser programmer.