summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2014-12-25 23:07:26 -0800
committerKevin Mitchell <kevmitch@gmail.com>2015-01-02 14:08:47 -0800
commit155c8e20ef5baa59e7f016a7ccd5d051f7a79731 (patch)
tree6b93ef99b3b28011d285e639e80c306251350e5f
parent81948634ca0f25d5bc7670d7f4be61e78295d097 (diff)
downloadmpv-155c8e20ef5baa59e7f016a7ccd5d051f7a79731.tar.bz2
mpv-155c8e20ef5baa59e7f016a7ccd5d051f7a79731.tar.xz
ao/wasapi: improve exclusive mode format search
fixes #1376
-rwxr-xr-xaudio/out/ao_wasapi_utils.c82
1 files changed, 36 insertions, 46 deletions
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c
index d731118e40..378d82669d 100755
--- a/audio/out/ao_wasapi_utils.c
+++ b/audio/out/ao_wasapi_utils.c
@@ -389,6 +389,25 @@ static bool try_passthrough(struct ao *ao)
return false;
}
+static bool search_sample_formats(struct ao *ao, int samplerate, struct mp_chmap *channels)
+{
+ // try float
+ for (int bits = 64; bits; bits -= 32){
+ if (try_format(ao, bits, bits, true, samplerate, channels))
+ return true;
+ }
+
+ // try int
+ // some common bit depths / container sizes (requests welcome)
+ int bits[] = {32, 24, 32, 24, 32, 16};
+ int valid_bits[] = {32, 24, 24, 20, 20, 16};
+ for (int i = 0; i < MP_ARRAY_SIZE(bits); i++) {
+ if (try_format(ao, bits[i], valid_bits[i], false, samplerate, channels))
+ return true;
+ }
+ return false;
+}
+
static bool find_formats(struct ao *ao)
{
struct wasapi_state *state = (struct wasapi_state *)ao->priv;
@@ -418,55 +437,26 @@ static bool find_formats(struct ao *ao)
}
/* Exclusive mode, we have to guess. */
- int start_bits = 32;
- /* fixme: try float first */
- bool is_float = false;
- while (1) { // not infinite -- returns at bottom
- bits = start_bits;
- for (; bits > 8; bits -= 8) {
- int samplerate = ao->samplerate;
- if (try_format(ao, bits, bits, is_float, samplerate, &ao->channels))
- return true;
-
- // make samplerate fit in [44100 192000]
- // we check for samplerate > 96k so that we can upsample instead of downsampling later
- if (samplerate < 44100 || samplerate > 96000) {
- if (samplerate < 44100)
- samplerate = 44100;
- if (samplerate > 96000)
- samplerate = 192000;
- if (try_format(ao, bits, bits, is_float, samplerate, &ao->channels))
- return true;
- }
-
- // try bounding to 96kHz
- if (samplerate > 48000) {
- samplerate = 96000;
- if (try_format(ao, bits, bits, is_float, samplerate, &ao->channels))
- return true;
- }
-
- // try bounding to 48kHz
- if (samplerate > 44100) {
- samplerate = 48000;
- if (try_format(ao, bits, bits, is_float, samplerate, &ao->channels))
- return true;
- }
+ while (true) {
+ int samplerate = ao->samplerate;
+ // try integer multiples of requested sample rate first
+ while (samplerate <= 384000) {
+ if (search_sample_formats(ao, samplerate, &ao->channels))
+ return true;
+ samplerate += ao->samplerate;
+ }
- /* How bad is this? try 44100hz, but only on 16bit */
- if (bits == 16 && samplerate != 44100) {
- samplerate = 44100;
- if (try_format(ao, bits, bits, is_float, samplerate, &ao->channels))
- return true;
- }
+ // now try list of typical sample rates (requests welcome)
+ int samplerates[] = {384000, 352800, 192000, 176400, 96000, 88200,
+ 48000, 44100, 32000, 22050, 16000, 11025,
+ 8000};
+ for (int i = 0; i < MP_ARRAY_SIZE(samplerates); i++){
+ if (search_sample_formats(ao, samplerates[i], &ao->channels))
+ return true;
}
- if (ao->channels.num > 6) {
- /* Maybe this is 5.1 hardware with no support for more. */
- mp_chmap_from_channels(&ao->channels, 6);
- } else if (ao->channels.num != 2) {
- /* Poor quality hardware? Try stereo mode, go through the list again. */
- mp_chmap_from_channels(&ao->channels, 2);
+ if (ao->channels.num > 1) {
+ mp_chmap_from_channels(&ao->channels, ao->channels.num - 1);
} else {
MP_ERR(ao, "Couldn't find acceptable audio format\n");
return false;