Fixed bug 3710 - SDL_OpenAudio(desired, obtained) doesn't update desired's size when obtained is NULL
authorSam Lantinga <slouken@libsdl.org>
Sun, 27 Aug 2017 19:10:30 -0700
changeset 11364ec27c4fd6880
parent 11363 2d3d35b2c95a
child 11365 a9bd2625fa01
Fixed bug 3710 - SDL_OpenAudio(desired, obtained) doesn't update desired's size when obtained is NULL

David Ludwig

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:
src/audio/SDL_audio.c
     1.1 --- a/src/audio/SDL_audio.c	Sun Aug 27 19:05:57 2017 -0700
     1.2 +++ b/src/audio/SDL_audio.c	Sun Aug 27 19:10:30 2017 -0700
     1.3 @@ -1413,7 +1413,14 @@
     1.4          id = open_audio_device(NULL, 0, desired, obtained,
     1.5                                 SDL_AUDIO_ALLOW_ANY_CHANGE, 1);
     1.6      } else {
     1.7 -        id = open_audio_device(NULL, 0, desired, NULL, 0, 1);
     1.8 +        SDL_AudioSpec _obtained;
     1.9 +        SDL_zero(_obtained);
    1.10 +        id = open_audio_device(NULL, 0, desired, &_obtained, 0, 1);
    1.11 +        /* On successful open, copy calculated values into 'desired'. */
    1.12 +        if (id > 0) {
    1.13 +            desired->size = _obtained.size;
    1.14 +            desired->silence = _obtained.silence;
    1.15 +        }
    1.16      }
    1.17  
    1.18      SDL_assert((id == 0) || (id == 1));