Skip to content

Commit d0259f1

Browse files
committed
aplay: place hard limits on resampler conversions
Allow time for each rate ratio adjustment to have an effect on the delay before making another ajustment. Do not allow the resampler to modify the rate ratio beyond fixed limits above and below the nominal rate ratio. If the delay changes too rapidly, or the delay goes too far away from the target value, then reset the rate ratio to its nominal value and update the target delay value.
1 parent a21ffd6 commit d0259f1

File tree

3 files changed

+190
-82
lines changed

3 files changed

+190
-82
lines changed

utils/aplay/aplay.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ static void *io_worker_routine(struct io_worker *w) {
601601
#if WITH_LIBSAMPLERATE
602602
if (use_resampler)
603603
resampler_reset(resampler);
604-
#endif
605604
}
605+
#endif
606606
}
607607

608608
ssize_t ret;
@@ -725,7 +725,9 @@ static void *io_worker_routine(struct io_worker *w) {
725725
w->ba_pcm.rate,
726726
w->alsa_pcm.format,
727727
w->alsa_pcm.rate,
728-
read_buffer.nmemb / w->ba_pcm.channels);
728+
w->alsa_pcm.start_threshold,
729+
w->alsa_pcm.start_threshold + w->alsa_pcm.period_frames,
730+
read_buffer.nmemb );
729731

730732
if (resampler == NULL)
731733
goto fail;
@@ -826,9 +828,6 @@ static void *io_worker_routine(struct io_worker *w) {
826828
#if WITH_LIBSAMPLERATE
827829
size_t resample_delay_frames;
828830
if (use_resampler) {
829-
if (!alsa_pcm_is_running(&w->alsa_pcm) || w->alsa_pcm.underrun)
830-
resampler_reset(resampler);
831-
832831
resample_delay_frames = ffb_len_out(write_buffer) / w->ba_pcm.channels;
833832
resample_delay_frames /= resampler_current_rate_ratio(resampler);
834833
}
@@ -845,8 +844,14 @@ static void *io_worker_routine(struct io_worker *w) {
845844
}
846845

847846
#if WITH_LIBSAMPLERATE
848-
if (use_resampler && alsa_pcm_is_running(&w->alsa_pcm)) {
849-
bool rate_changed = resampler_update_rate_ratio(resampler, dr.avg_value);
847+
if (use_resampler) {
848+
bool rate_changed = false;
849+
if (w->alsa_pcm.underrun) {
850+
resampler_reset(resampler);
851+
rate_changed = true;
852+
}
853+
if (alsa_pcm_is_running(&w->alsa_pcm))
854+
rate_changed = resampler_update_rate_ratio(resampler, read_samples / w->ba_pcm.channels, dr.avg_value);
850855
if (verbose >= 5 && rate_changed)
851856
debug("new rate ratio %.6f", resampler_current_rate_ratio(resampler));
852857
}

0 commit comments

Comments
 (0)