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_OpenAudio(desired, obtained) doesn't update desired's size when obtained is NULL #2509

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.0
Reported for operating system, platform: Other, All

Comments on the original bug report:

On 2017-07-23 19:01:48 +0000, David Ludwig wrote:

The SDL wiki's documentation for SDL_OpenAudio(desired, obtained) states that, if and when 'obtained' is NULL, that 'desired' will be modified, as appropriate:

Via: https://wiki.libsdl.org/SDL_OpenAudio
alternatively: https://web.archive.org/web/20161112172633/https://wiki.libsdl.org/SDL_OpenAudio

"If obtained is NULL, the audio data passed to the callback function will be guaranteed to be in the requested format, and will be automatically converted to the actual hardware audio format if necessary. If obtained is NULL, desired will have fields modified."

SDL_OpenAudio, via both SDL 2.0.5, and SDL2 as of https://hg.libsdl.org/SDL/rev/4094632213a2, does not update the 'desired' structure's 'size' parameter, if and when 'obtained' is NULL.

This bug manifested via an unofficial port of Basilisk II to SDL2 (via https://github.com/davidludwig/macemu), and was reported by Clang's Address Sanitizer in Xcode 8.3.3.

On 2017-07-23 19:04:28 +0000, David Ludwig wrote:

Created attachment 2807
fix # 1 (rejected) for SDL Bug 3710

This change modifies SDL_OpenAudio(desired, obtained), if and when called with 'obtained == NULL', to record the SDL_AudioSpec changes to a temporary buffer, then, on successful creation of an audio device, copy those values back into 'desired'.

On 2017-08-09 05:25:35 +0000, Ryan C. Gordon wrote:

(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.)

Tagging a bunch of bugs as target-2.0.6.

This means we're in the final stretch for an official SDL 2.0.6 release! These are the bugs we really want to fix before shipping if humanly possible.

That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.6 release, and generally be organized about what we're aiming to ship. After some debate, we might just remove this tag again and deal with it for a later release.

Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment.

Thanks!
--ryan.

On 2017-08-11 17:14:21 +0000, Sam Lantinga wrote:

This is the wrong fix. The actual behavior should be that the application should get called back with exactly what it requested and SDL should convert it to the correct format for output.

On 2017-08-13 20:19:45 +0000, wrote:

*** Bug 3749 has been marked as a duplicate of this bug. ***

On 2017-08-21 22:10:18 +0000, David Ludwig wrote:

If and when 'obtained' is NULL, should SDL modify the 'desired' field's 'size' parameter? For example:

SDL_AudioSpec want;
SDL_memset(&want, 0, sizeof(want));
want.freq = 48000;
want.format = AUDIO_F32;
want.channels = 2;
want.samples = 4096;
want.callback = MyAudioCallback;
if (SDL_OpenAudio(&want, NULL) != 0) {
exit(1);
}

//
// Assuming we get to this point in the code, should 'want.size' be zero, or non-zero?
// Currently, it'll be zero.
//

On 2017-08-21 23:28:14 +0000, Sam Lantinga wrote:

size is the only field that should be written, and it should be calculated from the other fields in the desired audio spec.

On 2017-08-22 13:09:57 +0000, David Ludwig wrote:

I've created a new set of patches. I am happy to create more, if it would help.

One version only copies 'size'.

A second version copies both 'size' and 'silence'. When looking over the documentation for SDL_OpenAudio in SDL_audio.h, it mentioned that both 'size' and 'silence' were things that SDL_OpenAudio would calculate.

Regarding both patches, I did notice that SDL 1.2 appears to have always modified desired's size and silence fields. The SDL wiki, at https://wiki.libsdl.org/SDL_OpenAudio#Remarks , does note:

"This function remains for compatibility with SDL 1.2, but also because it's slightly easier to use than the new functions in SDL 2.0."

Should SDL_OpenAudio, in SDL 2.x, always write size and/or silence field(s) in 'desired', regardless of whether 'obtained' is passed in?

On 2017-08-22 13:12:15 +0000, David Ludwig wrote:

Created attachment 2874
fix # 2,A, adjust both 'size' and 'silence'

On 2017-08-22 13:12:50 +0000, David Ludwig wrote:

Created attachment 2875
fix # 2,B, adjust only 'size'

On 2017-08-22 13:20:38 +0000, David Ludwig wrote:

For reference, here is a link to SDL_audio.c on SDL 1.2.x, which contains its implementation of SDL_OpenAudio: https://hg.libsdl.org/SDL/file/SDL-1.2/src/audio/SDL_audio.c

On 2017-08-28 02:10:55 +0000, Sam Lantinga wrote:

Fix # 2,A is in, thanks!
https://hg.libsdl.org/SDL/rev/ec27c4fd6880

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

1 participant