Open deveee opened 4 months ago
Btw. I tried
const ALCint context_attribs[] = {
ALC_FREQUENCY, 44100,
0
};
if (!(m_context = unique_ptr_alccontext(
alcCreateContext(m_device.get(), context_attribs), delete_alccontext))) {
errorstream << "Audio: Global Initialization: Failed to create context" << std::endl;
return false;
}
but it doesn't make any difference.
Currently the SDL backend doesn't allow changing the output rate, since the output is created when the device is opened, before getting configuration info, and isn't able to be reset during context creation so it stays with the configuration it had. This can be fixed to reopen the device with a new configuration, but risks causing a failure if the device can't be reopened for some reason, as the device it had would be closed and it couldn't keep the old configuration.
What do you mean by the sound being "broken"? It doesn't open/initialize? It's completely garbled? Occasional clicking? OpenAL Soft does open the device with the flags indicating the sample rate can be changed if needed, so it shouldn't fail for an unsupported sample rate.
Here are two recorded videos. The only difference is default output rate 44100 vs 48000. It does initialize and plays something but it's not what should be played. It's more like a crackling sounds.
https://github.com/user-attachments/assets/46d6b1ca-75e1-4880-af39-66d876565f42
https://github.com/user-attachments/assets/9effbae2-5f1e-46c5-941c-d9278d9f6592
The underlying issue would likely be an SDL or phone problem. OpenAL Soft requests a particular sample rate, and specifies the sample rate can be changed as needed. SDL succeeds and reports it set the requested sample rate, indicating either the underlying device accepted the requested sample rate, or SDL put its own resampler in between OpenAL Soft and the underlying device, in which case the audio problems stem from there.
That said, with commit efd2e8fca0ff2669b54d4826029307e95da36479 the SDL backend should try to reopen the device when trying to reconfigure the device, so specifying a frequency during context creation should make it try to use the requested rate. You'd need to query it afterward from the device to tell what was actually set in case it needed to be changed.
I just checked and with current git openal it works fine when I set ALC_FREQUENCY to 44100 during context creation.
Hard to tell if it's a problem with a phone or with SDL. I tried with two phones:
Maybe SDL doesn't check supported frequencies or ignores requested frequency or so... I never looked at this part of SDL code.
We use OpenAL + SDL in MultiCraft on Android. In current OpenAL version the sound is broken. I need manually change DEFAULT_OUTPUT_RATE to 44100 to make it working.
I wonder if it's possible to change output rate with some functions during openal initialization?
Tested with OpenAL 1.23.1 and SDL 2.30.3. With OpenAL 1.22.2 it works fine without any changes.