diff options
author | sfan5 <sfan5@live.de> | 2023-08-06 16:18:10 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-08-08 20:15:20 +0200 |
commit | 36bea732fb411c1097d47b756eb9a323ce1e3a56 (patch) | |
tree | de0818b10a10c215bebf47a9b0b456e464e1e70a /audio/out | |
parent | d9072fef2ab40816f6439f0c94a8229be7016de1 (diff) | |
download | mpv-36bea732fb411c1097d47b756eb9a323ce1e3a56.tar.bz2 mpv-36bea732fb411c1097d47b756eb9a323ce1e3a56.tar.xz |
ao_audiotrack: align buffer size to sample size
This looks like a pretty bad bug but only became a problem
with the last commit that allows rates like 22.5kHz to pass through
directly instead of being resampled.
Diffstat (limited to 'audio/out')
-rw-r--r-- | audio/out/ao_audiotrack.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/audio/out/ao_audiotrack.c b/audio/out/ao_audiotrack.c index dd4678011a..acd39fb869 100644 --- a/audio/out/ao_audiotrack.c +++ b/audio/out/ao_audiotrack.c @@ -714,11 +714,17 @@ static int init(struct ao *ao) return -1; } - int min = 0.075 * p->samplerate * af_fmt_to_bytes(ao->format) * ao->channels.num; + // Choose double of the minimum buffer size suggested by the driver, but not + // less than 75ms or more than 150ms. + const int bps = af_fmt_to_bytes(ao->format); + int min = 0.075 * p->samplerate * bps * ao->channels.num; int max = min * 2; + min = MP_ALIGN_UP(min, bps); + max = MP_ALIGN_UP(max, bps); p->size = MPCLAMP(buffer_size * 2, min, max); MP_VERBOSE(ao, "Setting bufferSize = %d (driver=%d, min=%d, max=%d)\n", p->size, buffer_size, min, max); - ao->device_buffer = p->size / af_fmt_to_bytes(ao->format); + assert(p->size % bps == 0); + ao->device_buffer = p->size / bps; p->chunksize = p->size; p->chunk = talloc_size(ao, p->size); |