audio: Handle non-power-of-two spec.samples when unsupported

Fixes #3685
This commit is contained in:
Ethan Lee 2022-07-17 10:35:09 -04:00
parent d21a18c65f
commit 90b86b132a
9 changed files with 21 additions and 0 deletions

View File

@ -1413,6 +1413,19 @@ open_audio_device(const char *devname, int iscapture,
}
}
/* For backends that require a power-of-two value for spec.samples, take the
* value we got from 'desired' and round up to the nearest value
*/
if (!current_audio.impl.SupportsNonPow2Samples && device->spec.samples > 0) {
device->spec.samples -= 1;
device->spec.samples |= device->spec.samples >> 1;
device->spec.samples |= device->spec.samples >> 2;
device->spec.samples |= device->spec.samples >> 4;
device->spec.samples |= device->spec.samples >> 8;
device->spec.samples |= device->spec.samples >> 16;
device->spec.samples += 1;
}
if (current_audio.impl.OpenDevice(device, devname) < 0) {
close_audio_device(device);
return 0;

View File

@ -88,6 +88,7 @@ typedef struct SDL_AudioDriverImpl
SDL_bool OnlyHasDefaultOutputDevice;
SDL_bool OnlyHasDefaultCaptureDevice;
SDL_bool AllowsArbitraryDeviceNames;
SDL_bool SupportsNonPow2Samples;
} SDL_AudioDriverImpl;

View File

@ -1009,6 +1009,7 @@ ALSA_Init(SDL_AudioDriverImpl * impl)
impl->FlushCapture = ALSA_FlushCapture;
impl->HasCaptureSupport = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */
}

View File

@ -1173,6 +1173,7 @@ COREAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->ProvidesOwnCallbackThread = SDL_TRUE;
impl->HasCaptureSupport = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */
}

View File

@ -668,6 +668,7 @@ DSOUND_Init(SDL_AudioDriverImpl * impl)
impl->GetDefaultAudioInfo = DSOUND_GetDefaultAudioInfo;
impl->HasCaptureSupport = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */
}

View File

@ -195,6 +195,7 @@ DISKAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->AllowsArbitraryDeviceNames = SDL_TRUE;
impl->HasCaptureSupport = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */
}

View File

@ -1417,6 +1417,7 @@ PIPEWIRE_Init(SDL_AudioDriverImpl *impl)
impl->HasCaptureSupport = SDL_TRUE;
impl->ProvidesOwnCallbackThread = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE;
}

View File

@ -945,6 +945,7 @@ PULSEAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->GetDefaultAudioInfo = PULSEAUDIO_GetDefaultAudioInfo;
impl->HasCaptureSupport = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */
}

View File

@ -617,6 +617,7 @@ WASAPI_Init(SDL_AudioDriverImpl * impl)
impl->Deinitialize = WASAPI_Deinitialize;
impl->GetDefaultAudioInfo = WASAPI_GetDefaultAudioInfo;
impl->HasCaptureSupport = SDL_TRUE;
impl->SupportsNonPow2Samples = SDL_TRUE;
return SDL_TRUE; /* this audio target is available. */
}