Browse Source

Write `max_frame_count` in `write_callback`

This is the same as behvaiour as in the origianl `sio_sine.c` example.
The pulseaudio output is still distorted, but it does output a
continuous signal and not a single buffer like before.
master
Andreas Linz 5 years ago
parent
commit
5779dc9492
1 changed files with 11 additions and 10 deletions
  1. +11
    -10
      examples/sine.rs

+ 11
- 10
examples/sine.rs View File

@ -50,16 +50,17 @@ fn main() {
out.register_write_callback(|out: rsoundio::OutStream,
min_frame_count: u32,
max_frame_count: u32| {
let mut data = vec![0.0f32; BUF_SIZE];
let len = if backend != rsoundio::SioBackend::PulseAudio {
::std::cmp::min(BUF_SIZE, max_frame_count as usize)
} else {
BUF_SIZE
};
consumer.read_blocking(&mut data[..len]);
let frames = vec![data[..len].iter().cloned().collect(),
data[..len].iter().cloned().collect()];
out.write_stream_f32(min_frame_count, &frames).unwrap();
let mut frames_left = max_frame_count as usize;
let mut buf = vec![0.0f32; BUF_SIZE];
while frames_left > 0 {
let len = ::std::cmp::min(BUF_SIZE, frames_left);
consumer.read_blocking(&mut buf[..len]);
let left = buf[..len].iter().cloned().collect::<Vec<f32>>();
let right = left.clone();
let frames = vec![left, right];
let cnt = out.write_stream_f32(min_frame_count, &frames).unwrap() as usize;
frames_left -= cnt;
}
});
out.register_underflow_callback(|out: rsoundio::OutStream| {
println!("Underflow in {} occured!", out.name().unwrap())

Loading…
Cancel
Save