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

ALSA: Replace snd_pcm_delay with snd_pcm_avail #383

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/alsadevice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,14 @@ fn playback_loop_bytes(
match msg {
Ok(AudioMessage::Audio(chunk)) => {
// measure delay only on running non-stalled device
let delay_at_chunk_recvd = if !device_stalled
let avail_at_chunk_recvd = if !device_stalled
&& pcmdevice.state_raw() == alsa_sys::SND_PCM_STATE_RUNNING as i32
{
pcmdevice.status().ok().map(|status| status.get_delay())
pcmdevice.avail().ok()
} else {
None
};
//trace!("PB: Delay at chunk rcvd: {:?}", delay_at_chunk_recvd);
//trace!("PB: Avail at chunk rcvd: {:?}", avail_at_chunk_recvd);

conversion_result =
chunk_to_buffer_rawbytes(&chunk, &mut buffer, &params.sample_format);
Expand Down Expand Up @@ -533,9 +533,11 @@ fn playback_loop_bytes(
.signal_peak
.add_record(chunk_stats.peak_linear());
}
if let Some(delay) = delay_at_chunk_recvd {
if delay != 0 {
buffer_avg.add_value(delay as f64);
if let Some(avail) = avail_at_chunk_recvd {
// TODO: This is wrongfully assumes that the alsa buffer is 4 * chunksize
let delay_at_chunk_recvd = (params.chunksize * 4) as i64 - avail as i64;
if delay_at_chunk_recvd != 0 {
buffer_avg.add_value(delay_at_chunk_recvd as f64);
}
}
if timer.larger_than_millis((1000.0 * params.adjust_period) as u64) {
Expand Down