-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Description
When using duplex mode, I'm getting serious gaps in the audio output. This is in release mode, and even if I increase the frames per buffer to buffers sizes corresponding to multiple seconds, there are gaps between the buffers. The gaps are approximate 1 sec long. A minimal example to reproduce looks like this:
use std::io;
use portaudio as pa;
const CHANNELS: i32 = 2;
const SAMPLE_RATE: f64 = 44_100.0;
const FRAMES_PER_BUFFER: u32 = 1024;
fn main() {
run().unwrap()
}
fn run() -> Result<(), pa::Error> {
let pa = pa::PortAudio::new()?;
let mut settings = pa.default_duplex_stream_settings(
CHANNELS,
CHANNELS,
SAMPLE_RATE,
FRAMES_PER_BUFFER,
)?;
settings.flags = pa::stream_flags::CLIP_OFF;
let callback = move |pa::DuplexStreamCallbackArgs { in_buffer, out_buffer, frames, time, .. }: pa::DuplexStreamCallbackArgs<f32, f32>| {
for i in 0 .. out_buffer.len() {
out_buffer[i] = ((i * 2 % 1000) - 500) as f32 / 1000.0;
}
pa::Continue
};
// Start stream
let mut stream = pa.open_non_blocking_stream(settings, callback)?;
stream.start()?;
// Wait for user input to quit
println!("Press enter/return to quit...");
let mut user_input = String::new();
io::stdin().read_line(&mut user_input).ok();
stream.stop()?;
stream.close()?;
Ok(())
}
I can run the same example in other languages just fine, which indicates it is a problem in the Rust binding themselves.
The non-duplex variant using default_output_stream_settings
also runs fine.
Metadata
Metadata
Assignees
Labels
No labels