Skip to content

alsa(pipewire): seconds high latency with BufferSize::Fixed #1034

@remind-me-later

Description

@remind-me-later

Hi! I'm using CPAL to make a GB emulator, since the reversal of this commit I'm getting a very high latency when using Alsa on Linux, the delay is of multiple seconds. I also tried the branch fix/pipewire-alsa-latency, but it doesn't solve the issue. Commit 5dd648ee8564d3d0ed77c60c95246425dbeebd10 works like a charm though. All the Cpal code in my project is in the audio file, but this is the setup:

const BUFFER_SIZE: u32 = 512;
const RING_BUFFER_SIZE: usize = BUFFER_SIZE as usize * 4;
const SAMPLE_RATE: i32 = 48000;

let host = cpal::default_host();
let device = host.default_output_device().ok_or(Error::GetOutputDevice)?;

let config = cpal::StreamConfig {
    channels: 2,
    sample_rate: cpal::SampleRate(SAMPLE_RATE as u32),
    buffer_size: cpal::BufferSize::Fixed(BUFFER_SIZE),
};

let error_callback = |err| eprintln!("an AudioError occurred on stream: {err}");
let data_callback = move |buffer: &mut [ProcessSample], _: &_| {
    if let Ok(mut ring) = ring_buffer_clone.lock() {
        ring.write_samples_interleaved(buffer);
    }
};

let stream = device
    .build_output_stream(&config, data_callback, error_callback, None)
    .map_err(|_err| Error::BuildStream)?;

As in this issue I'm also using PipeWire. Let me know if you need anything. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions