Skip to content

Problem when setting buffer time (alsa backend) #391

@richard-uk1

Description

@richard-uk1

Continuing from #247, I'm still getting the problem (the story is I removed the set_buffer call but it was re-introduced as it created unacceptable latency). I've implemented dumping the HwParams (code below) and to be honest it looks like a bug in the ALSA driver for my sound card. I have an idea to make it work on my setup - that is to try to set the buffer time, and just to leave it unconstrained if there is an error setting it. I'll knock up a PR with the idea in it.

Code to implement `Debug` for `HwParams`
impl fmt::Debug for HwParams {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        unsafe {
            match dump_alsa(|outputp| alsa::snd_pcm_hw_params_dump(self.0, outputp) == 0) {
                Some(msg) => write!(f, "HwParams({})", msg),
                None => f.write_str("HwParams")
            }
        }
    }
}

/// output of dump_fn should be whether the function ran successfully (false means an error)
unsafe fn dump_alsa(dump_fn: impl FnOnce(*mut alsa::snd_output_t) -> bool) -> Option<String> {
    let mut outputp: *mut alsa::snd_output_t = ptr::null_mut();
    if let Err(e) = check_errors(alsa::snd_output_buffer_open(&mut outputp)) {
        return None;
    }
    if ! dump_fn(outputp) {
        return None;
    }
    let mut output_cstr: *mut libc::c_char = ptr::null_mut();
    let len = alsa::snd_output_buffer_string(outputp, &mut output_cstr);
    // be careful to drop this before any mutating calls to outputp
    let output_cstr: &[u8] = std::slice::from_raw_parts(output_cstr as *const u8, len);
    Some(String::from_utf8_lossy(output_cstr).into_owned())
}

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