From 2f20168b0b5105566ecb330ea4b83c358e4b4e6d Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 7 Mar 2018 23:01:52 +0100 Subject: ao_sdl: fix default buffer size If you set desired.samples to 0, SDL will return a default buffer size on obtained.samples. This was broken, because ceil_power_of_two(0) returns 1. Since 0 is usually not considered a power of two, this is probably correct, but we still want to set desired.samples to 0 in this case. --- audio/out/ao_sdl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'audio') diff --git a/audio/out/ao_sdl.c b/audio/out/ao_sdl.c index 1564e26120..6144918dfe 100644 --- a/audio/out/ao_sdl.c +++ b/audio/out/ao_sdl.c @@ -113,8 +113,7 @@ static int init(struct ao *ao) ao->format = af_fmt_from_planar(ao->format); - SDL_AudioSpec desired, obtained; - + SDL_AudioSpec desired = {0}; desired.format = AUDIO_S16SYS; for (int n = 0; fmtmap[n][0]; n++) { if (ao->format == fmtmap[n][0]) { @@ -124,8 +123,10 @@ static int init(struct ao *ao) } desired.freq = ao->samplerate; desired.channels = ao->channels.num; - desired.samples = MPMIN(32768, ceil_power_of_two(ao->samplerate * - priv->buflen)); + if (priv->buflen) { + desired.samples = MPMIN(32768, ceil_power_of_two(ao->samplerate * + priv->buflen)); + } desired.callback = audio_callback; desired.userdata = ao; @@ -134,7 +135,7 @@ static int init(struct ao *ao) (int) desired.freq, (int) desired.channels, (int) desired.format, (int) desired.samples); - obtained = desired; + SDL_AudioSpec obtained = desired; if (SDL_OpenAudio(&desired, &obtained)) { if (!ao->probing) MP_ERR(ao, "could not open audio: %s\n", SDL_GetError()); -- cgit v1.2.3