Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge output gaps in duplex mode #180

Open
bluenote10 opened this issue May 3, 2020 · 0 comments
Open

Huge output gaps in duplex mode #180

bluenote10 opened this issue May 3, 2020 · 0 comments

Comments

@bluenote10
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant