From 96fa3ebd1ace54666f32a27e807faab4df18590e Mon Sep 17 00:00:00 2001 From: Kevin Mitchell Date: Mon, 1 Dec 2014 00:38:59 -0800 Subject: ao/wasapi: make sure that < 16-bit pcm never happens it just sucks. noone should have to listen to that. --- audio/out/ao_wasapi_utils.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'audio/out/ao_wasapi_utils.c') diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c index 62fcac0334..2c7d245aa4 100755 --- a/audio/out/ao_wasapi_utils.c +++ b/audio/out/ao_wasapi_utils.c @@ -21,6 +21,7 @@ #define _WIN32_WINNT 0x600 #include +#include #include #include #include @@ -210,6 +211,12 @@ static bool set_ao_format(struct ao *ao, WAVEFORMATEXTENSIBLE wformat) { struct wasapi_state *state = (struct wasapi_state *)ao->priv; + // explicitly disallow 8 bits - this will catch if the + // closestMatch returned by IsFormatSupported in try_format below returns + // a bit depth of less than 16 + if (wformat.Format.wBitsPerSample < 16) + return false; + bool is_float = !mp_GUID_compare(&mp_KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, &wformat.SubFormat); @@ -240,6 +247,13 @@ static bool try_format(struct ao *ao, const struct mp_chmap channels) { struct wasapi_state *state = (struct wasapi_state *)ao->priv; + /* If for some reason we get 8-bits, try 16-bit equivalent instead. + This can happen if 8-bits is initially requested in ao->format + or in the unlikely event that GetMixFormat return 8-bits. + If someone with a "vintage" sound card or something complains + this can be reconsidered */ + bits = FFMAX(16, bits); + WAVEFORMATEXTENSIBLE wformat; set_format(&wformat, bits / 8, samplerate, channels.num, mp_chmap_to_waveext(&channels)); @@ -346,13 +360,9 @@ static bool find_formats(struct ao *ao) /* See if the format works as-is */ int bits = af_fmt2bits(ao->format); - /* don't try 8bits -- there are various 8bit modes other than PCM (*-law et al); - let's just stick to PCM or float here. */ - if (bits == 8) { - bits = 16; - } else if (try_format(ao, bits, ao->samplerate, ao->channels)) { + if (try_format(ao, bits, ao->samplerate, ao->channels)) return true; - } + if (!state->opt_exclusive) { /* shared mode, we can use the system default mix format. */ if (try_mix_format(ao)) { -- cgit v1.2.3