mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-14 13:56:00 +00:00
audio: Let emscripten update device->sample_frames at device open time.
Fixes #11435.
This commit is contained in:
@@ -144,7 +144,7 @@ const char *SDL_GetCurrentAudioDriver(void)
|
|||||||
return current_audio.name;
|
return current_audio.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetDefaultSampleFramesFromFreq(const int freq)
|
int SDL_GetDefaultSampleFramesFromFreq(const int freq)
|
||||||
{
|
{
|
||||||
const char *hint = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES);
|
const char *hint = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_SAMPLE_FRAMES);
|
||||||
if (hint) {
|
if (hint) {
|
||||||
@@ -626,7 +626,7 @@ static SDL_AudioDevice *CreatePhysicalAudioDevice(const char *name, bool recordi
|
|||||||
device->recording = recording;
|
device->recording = recording;
|
||||||
SDL_copyp(&device->spec, spec);
|
SDL_copyp(&device->spec, spec);
|
||||||
SDL_copyp(&device->default_spec, spec);
|
SDL_copyp(&device->default_spec, spec);
|
||||||
device->sample_frames = GetDefaultSampleFramesFromFreq(device->spec.freq);
|
device->sample_frames = SDL_GetDefaultSampleFramesFromFreq(device->spec.freq);
|
||||||
device->silence_value = SDL_GetSilenceValueForFormat(device->spec.format);
|
device->silence_value = SDL_GetSilenceValueForFormat(device->spec.format);
|
||||||
device->handle = handle;
|
device->handle = handle;
|
||||||
|
|
||||||
@@ -1666,7 +1666,7 @@ static bool OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec
|
|||||||
device->spec.format = (SDL_AUDIO_BITSIZE(device->default_spec.format) >= SDL_AUDIO_BITSIZE(spec.format)) ? device->default_spec.format : spec.format;
|
device->spec.format = (SDL_AUDIO_BITSIZE(device->default_spec.format) >= SDL_AUDIO_BITSIZE(spec.format)) ? device->default_spec.format : spec.format;
|
||||||
device->spec.freq = SDL_max(device->default_spec.freq, spec.freq);
|
device->spec.freq = SDL_max(device->default_spec.freq, spec.freq);
|
||||||
device->spec.channels = SDL_max(device->default_spec.channels, spec.channels);
|
device->spec.channels = SDL_max(device->default_spec.channels, spec.channels);
|
||||||
device->sample_frames = GetDefaultSampleFramesFromFreq(device->spec.freq);
|
device->sample_frames = SDL_GetDefaultSampleFramesFromFreq(device->spec.freq);
|
||||||
SDL_UpdatedAudioDeviceFormat(device); // start this off sane.
|
SDL_UpdatedAudioDeviceFormat(device); // start this off sane.
|
||||||
|
|
||||||
device->currently_opened = true; // mark this true even if impl.OpenDevice fails, so we know to clean up.
|
device->currently_opened = true; // mark this true even if impl.OpenDevice fails, so we know to clean up.
|
||||||
|
@@ -91,6 +91,9 @@ extern SDL_AudioDevice *SDL_FindPhysicalAudioDeviceByCallback(bool (*callback)(S
|
|||||||
// Backends should call this if they change the device format, channels, freq, or sample_frames to keep other state correct.
|
// Backends should call this if they change the device format, channels, freq, or sample_frames to keep other state correct.
|
||||||
extern void SDL_UpdatedAudioDeviceFormat(SDL_AudioDevice *device);
|
extern void SDL_UpdatedAudioDeviceFormat(SDL_AudioDevice *device);
|
||||||
|
|
||||||
|
// Backends can call this to get a reasonable default sample frame count for a device's sample rate.
|
||||||
|
int SDL_GetDefaultSampleFramesFromFreq(const int freq);
|
||||||
|
|
||||||
// Backends can call this to get a standardized name for a thread to power a specific audio device.
|
// Backends can call this to get a standardized name for a thread to power a specific audio device.
|
||||||
extern char *SDL_GetAudioThreadName(SDL_AudioDevice *device, char *buf, size_t buflen);
|
extern char *SDL_GetAudioThreadName(SDL_AudioDevice *device, char *buf, size_t buflen);
|
||||||
|
|
||||||
|
@@ -190,6 +190,7 @@ static bool EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device)
|
|||||||
|
|
||||||
// limit to native freq
|
// limit to native freq
|
||||||
device->spec.freq = EM_ASM_INT({ return Module['SDL3'].audioContext.sampleRate; });
|
device->spec.freq = EM_ASM_INT({ return Module['SDL3'].audioContext.sampleRate; });
|
||||||
|
device->sample_frames = SDL_GetDefaultSampleFramesFromFreq(device->spec.freq);
|
||||||
|
|
||||||
SDL_UpdatedAudioDeviceFormat(device);
|
SDL_UpdatedAudioDeviceFormat(device);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user