src/audio/SDL_audio.c
changeset 10790 92726dd20acd
parent 10772 ffb8f194db6e
child 10792 98447b8fda53
equal deleted inserted replaced
10789:e3eb7a266ec2 10790:92726dd20acd
   104 #if SDL_AUDIO_DRIVER_EMSCRIPTEN
   104 #if SDL_AUDIO_DRIVER_EMSCRIPTEN
   105     &EMSCRIPTENAUDIO_bootstrap,
   105     &EMSCRIPTENAUDIO_bootstrap,
   106 #endif
   106 #endif
   107     NULL
   107     NULL
   108 };
   108 };
       
   109 
       
   110 
       
   111 #ifdef HAVE_LIBSAMPLERATE_H
       
   112 #ifdef SDL_LIBSAMPLERATE_DYNAMIC
       
   113 static void *SRC_lib = NULL;
       
   114 #endif
       
   115 SDL_bool SRC_available = SDL_FALSE;
       
   116 SRC_STATE* (*SRC_src_new)(int converter_type, int channels, int *error) = NULL;
       
   117 int (*SRC_src_process)(SRC_STATE *state, SRC_DATA *data) = NULL;
       
   118 int (*SRC_src_reset)(SRC_STATE *state) = NULL;
       
   119 SRC_STATE* (*SRC_src_delete)(SRC_STATE *state) = NULL;
       
   120 const char* (*SRC_src_strerror)(int error) = NULL;
       
   121 
       
   122 static SDL_bool
       
   123 LoadLibSampleRate(void)
       
   124 {
       
   125     SRC_available = SDL_FALSE;
       
   126 
       
   127     if (!SDL_GetHintBoolean("SDL_AUDIO_ALLOW_LIBRESAMPLE", SDL_TRUE)) {
       
   128         return SDL_FALSE;
       
   129     }
       
   130 
       
   131 #ifdef SDL_LIBSAMPLERATE_DYNAMIC
       
   132     SDL_assert(SRC_lib == NULL);
       
   133     SRC_lib = SDL_LoadObject(SDL_LIBSAMPLERATE_DYNAMIC);
       
   134     if (!SRC_lib) {
       
   135         return SDL_FALSE;
       
   136     }
       
   137 #endif
       
   138 
       
   139     SRC_src_new = (SRC_STATE* (*)(int converter_type, int channels, int *error))SDL_LoadFunction(state->SRC_lib, "src_new");
       
   140     SRC_src_process = (int (*)(SRC_STATE *state, SRC_DATA *data))SDL_LoadFunction(state->SRC_lib, "src_process");
       
   141     SRC_src_reset = (int(*)(SRC_STATE *state))SDL_LoadFunction(state->SRC_lib, "src_reset");
       
   142     SRC_src_delete = (SRC_STATE* (*)(SRC_STATE *state))SDL_LoadFunction(state->SRC_lib, "src_delete");
       
   143     SRC_src_strerror = (const char* (*)(int error))SDL_LoadFunction(state->SRC_lib, "src_strerror");
       
   144 
       
   145     if (!SRC_src_new || !SRC_src_process || !SRC_src_reset || !SRC_src_delete || !SRC_src_strerror) {
       
   146         #ifdef SDL_LIBSAMPLERATE_DYNAMIC
       
   147         SDL_UnloadObject(SRC_lib);
       
   148         SRC_lib = NULL;
       
   149         #endif
       
   150         return SDL_FALSE;
       
   151     }
       
   152 
       
   153     SRC_available = SDL_TRUE;
       
   154     return SDL_TRUE;
       
   155 }
       
   156 
       
   157 static void
       
   158 UnloadLibSampleRate(void)
       
   159 {
       
   160 #ifdef SDL_LIBSAMPLERATE_DYNAMIC
       
   161     if (SRC_lib != NULL) {
       
   162         SDL_UnloadObject(SRC_lib);
       
   163     }
       
   164     SRC_lib = NULL;
       
   165 #endif
       
   166 
       
   167     SRC_available = SDL_FALSE;
       
   168     SRC_src_new = NULL;
       
   169     SRC_src_process = NULL;
       
   170     SRC_src_reset = NULL;
       
   171     SRC_src_delete = NULL;
       
   172     SRC_src_strerror = NULL;
       
   173 }
       
   174 #endif
   109 
   175 
   110 static SDL_AudioDevice *
   176 static SDL_AudioDevice *
   111 get_audio_device(SDL_AudioDeviceID id)
   177 get_audio_device(SDL_AudioDeviceID id)
   112 {
   178 {
   113     id--;
   179     id--;
   826     finish_audio_entry_points_init();
   892     finish_audio_entry_points_init();
   827 
   893 
   828     /* Make sure we have a list of devices available at startup. */
   894     /* Make sure we have a list of devices available at startup. */
   829     current_audio.impl.DetectDevices();
   895     current_audio.impl.DetectDevices();
   830 
   896 
       
   897 #ifdef HAVE_LIBSAMPLERATE_H
       
   898     LoadLibSampleRate();
       
   899 #endif
       
   900 
   831     return 0;
   901     return 0;
   832 }
   902 }
   833 
   903 
   834 /*
   904 /*
   835  * Get the current audio driver name
   905  * Get the current audio driver name
  1425 
  1495 
  1426     SDL_DestroyMutex(current_audio.detectionLock);
  1496     SDL_DestroyMutex(current_audio.detectionLock);
  1427 
  1497 
  1428     SDL_zero(current_audio);
  1498     SDL_zero(current_audio);
  1429     SDL_zero(open_devices);
  1499     SDL_zero(open_devices);
       
  1500 
       
  1501 #ifdef HAVE_LIBSAMPLERATE_H
       
  1502     UnloadLibSampleRate();
       
  1503 #endif
  1430 }
  1504 }
  1431 
  1505 
  1432 #define NUM_FORMATS 10
  1506 #define NUM_FORMATS 10
  1433 static int format_idx;
  1507 static int format_idx;
  1434 static int format_idx_sub;
  1508 static int format_idx_sub;