Fixed bug 3662 - Error message when using the audio conversion setup without an initialized audio subsystem is a bit vague
authorSam Lantinga <slouken@libsdl.org>
Mon, 28 Aug 2017 21:42:39 -0700
changeset 11406f40c2dedaded
parent 11405 4e12f78c2b0e
child 11407 ff9e8ae4d4fb
Fixed bug 3662 - Error message when using the audio conversion setup without an initialized audio subsystem is a bit vague

Simon Hug

This issue actually raises the question if this API change (requirement of initialized audio subsystem) is breaking backwards compatibility. I don't see the documentation saying it is needed in 2.0.5.
src/audio/SDL_audio.c
src/audio/SDL_audio_c.h
src/audio/SDL_audiocvt.c
src/audio/SDL_audiotypecvt.c
     1.1 --- a/src/audio/SDL_audio.c	Tue Aug 29 00:41:45 2017 -0400
     1.2 +++ b/src/audio/SDL_audio.c	Mon Aug 28 21:42:39 2017 -0700
     1.3 @@ -874,8 +874,6 @@
     1.4      return NULL;
     1.5  }
     1.6  
     1.7 -extern void SDL_ChooseAudioConverters(void);
     1.8 -
     1.9  int
    1.10  SDL_AudioInit(const char *driver_name)
    1.11  {
    1.12 @@ -890,8 +888,6 @@
    1.13      SDL_zero(current_audio);
    1.14      SDL_zero(open_devices);
    1.15  
    1.16 -    SDL_ChooseAudioConverters();
    1.17 -
    1.18      /* Select the proper audio driver */
    1.19      if (driver_name == NULL) {
    1.20          driver_name = SDL_getenv("SDL_AUDIODRIVER");
     2.1 --- a/src/audio/SDL_audio_c.h	Tue Aug 29 00:41:45 2017 -0400
     2.2 +++ b/src/audio/SDL_audio_c.h	Mon Aug 28 21:42:39 2017 -0700
     2.3 @@ -54,7 +54,10 @@
     2.4  /* Function to calculate the size and silence for a SDL_AudioSpec */
     2.5  extern void SDL_CalculateAudioSpec(SDL_AudioSpec * spec);
     2.6  
     2.7 -/* These pointers get set during init to various SIMD implementations. */
     2.8 +/* Choose the audio filter functions below */
     2.9 +extern void SDL_ChooseAudioConverters(void);
    2.10 +
    2.11 +/* These pointers get set during SDL_ChooseAudioConverters() to various SIMD implementations. */
    2.12  extern SDL_AudioFilter SDL_Convert_S8_to_F32;
    2.13  extern SDL_AudioFilter SDL_Convert_U8_to_F32;
    2.14  extern SDL_AudioFilter SDL_Convert_S16_to_F32;
     3.1 --- a/src/audio/SDL_audiocvt.c	Tue Aug 29 00:41:45 2017 -0400
     3.2 +++ b/src/audio/SDL_audiocvt.c	Mon Aug 28 21:42:39 2017 -0700
     3.3 @@ -895,11 +895,6 @@
     3.4          return SDL_InvalidParamError("cvt");
     3.5      }
     3.6  
     3.7 -    /* Conversions from and to float require the audio subsystem to be initialized */
     3.8 -    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
     3.9 -        return SDL_SetError("Audio subsystem has not been initialized");
    3.10 -    }
    3.11 -
    3.12      /* Make sure we zero out the audio conversion before error checking */
    3.13      SDL_zerop(cvt);
    3.14  
    3.15 @@ -932,6 +927,9 @@
    3.16      cvt->len_ratio = 1.0;
    3.17      cvt->rate_incr = ((double) dst_rate) / ((double) src_rate);
    3.18  
    3.19 +    /* Make sure we've chosen audio conversion functions (MMX, scalar, etc.) */
    3.20 +    SDL_ChooseAudioConverters();
    3.21 +
    3.22      /* SDL now favors float32 as its preferred internal format, and considers
    3.23         everything else to be a degenerate case that we might have to make
    3.24         multiple passes over the data to convert to and from float32 as
     4.1 --- a/src/audio/SDL_audiotypecvt.c	Tue Aug 29 00:41:45 2017 -0400
     4.2 +++ b/src/audio/SDL_audiotypecvt.c	Mon Aug 28 21:42:39 2017 -0700
     4.3 @@ -752,7 +752,7 @@
     4.4          return;
     4.5      }
     4.6  
     4.7 -    #define SET_CONVERTER_FUNCS(fntype) \
     4.8 +#define SET_CONVERTER_FUNCS(fntype) \
     4.9          SDL_Convert_S8_to_F32 = SDL_Convert_S8_to_F32_##fntype; \
    4.10          SDL_Convert_U8_to_F32 = SDL_Convert_U8_to_F32_##fntype; \
    4.11          SDL_Convert_S16_to_F32 = SDL_Convert_S16_to_F32_##fntype; \
    4.12 @@ -765,18 +765,18 @@
    4.13          SDL_Convert_F32_to_S32 = SDL_Convert_F32_to_S32_##fntype; \
    4.14          converters_chosen = SDL_TRUE
    4.15  
    4.16 -    #if HAVE_SSE2_INTRINSICS
    4.17 +#if HAVE_SSE2_INTRINSICS
    4.18      if (SDL_HasSSE2()) {
    4.19          SET_CONVERTER_FUNCS(SSE2);
    4.20          return;
    4.21      }
    4.22 -    #endif
    4.23 +#endif
    4.24  
    4.25 -    #if NEED_SCALAR_CONVERTER_FALLBACKS
    4.26 +#if NEED_SCALAR_CONVERTER_FALLBACKS
    4.27      SET_CONVERTER_FUNCS(Scalar);
    4.28 -    #endif
    4.29 +#endif
    4.30  
    4.31 -    #undef SET_CONVERTER_FUNCS
    4.32 +#undef SET_CONVERTER_FUNCS
    4.33  
    4.34      SDL_assert(converters_chosen == SDL_TRUE);
    4.35  }