Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL backend broken on Android #1021

Open
deveee opened this issue Jul 24, 2024 · 5 comments
Open

SDL backend broken on Android #1021

deveee opened this issue Jul 24, 2024 · 5 comments

Comments

@deveee
Copy link

deveee commented Jul 24, 2024

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.

@deveee
Copy link
Author

deveee commented Jul 31, 2024

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.

@kcat
Copy link
Owner

kcat commented Jul 31, 2024

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.

@deveee
Copy link
Author

deveee commented Jul 31, 2024

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.

44100.mp4
48000.mp4

@kcat
Copy link
Owner

kcat commented Aug 1, 2024

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 efd2e8f 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.

@deveee
Copy link
Author

deveee commented Aug 19, 2024

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:

  • it works on Asus Max Pro M2 with Android 9 with default frequency (I don't need to change it to 44100)
  • for Samsung A55 with Android 14 it works after I set frequency to 44100.

Maybe SDL doesn't check supported frequencies or ignores requested frequency or so... I never looked at this part of SDL code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants