/** * @brief Makes sure parameters work properly. */ static void audio_testOpen (void) { int i, n; int ret; /* Begin testcase. */ SDL_ATbegin( "Audio Open" ); /* List drivers. */ n = SDL_GetNumAudioDrivers(); SDL_ATprintVerbose( 1, "%d Audio Drivers\n", n ); for (i=0; i<n; i++) { SDL_ATprintVerbose( 1, " %s\n", SDL_GetAudioDriver(i) ); } /* Start SDL. */ ret = SDL_Init( SDL_INIT_AUDIO ); if (SDL_ATvassert( ret==0, "SDL_Init( SDL_INIT_AUDIO ): %s", SDL_GetError())) return; /* Print devices. */ SDL_ATprintVerbose( 1, "Using Audio Driver '%s'\n", SDL_GetCurrentAudioDriver() ); audio_printDevices(0); audio_printDevices(1); /* Quit SDL. */ SDL_Quit(); /* End testcase. */ SDL_ATend(); }
int main(int argc, char **argv) { int n; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } /* Print available audio drivers */ n = SDL_GetNumAudioDrivers(); if (n == 0) { SDL_Log("No built-in audio drivers\n\n"); } else { int i; SDL_Log("Built-in audio drivers:\n"); for (i = 0; i < n; ++i) { SDL_Log(" %s\n", SDL_GetAudioDriver(i)); } SDL_Log("\n"); } SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver()); print_devices(0); print_devices(1); SDL_Quit(); return 0; }
/** * \brief Checks available audio driver names. * * \sa https://wiki.libsdl.org/SDL_GetNumAudioDrivers * \sa https://wiki.libsdl.org/SDL_GetAudioDriver */ int audio_printAudioDrivers() { int i, n; const char *name; /* Get number of drivers */ n = SDL_GetNumAudioDrivers(); SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()"); SDLTest_AssertCheck(n>=0, "Verify number of audio drivers >= 0, got: %i", n); /* List drivers. */ if (n>0) { for (i=0; i<n; i++) { name = SDL_GetAudioDriver(i); SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i); SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL"); if (name != NULL) { SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name); } } } return TEST_COMPLETED; }
int main(int argc, char **argv) { /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } /* Print available audio drivers */ int n = SDL_GetNumAudioDrivers(); if (n == 0) { printf("No built-in audio drivers\n\n"); } else { int i; printf("Built-in audio drivers:\n"); for (i = 0; i < n; ++i) { printf(" %s\n", SDL_GetAudioDriver(i)); } printf("\n"); } printf("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver()); print_devices(0); print_devices(1); SDL_Quit(); return 0; }
std::vector<std::string> AudioManager::get_drivers() { std::vector<std::string> driver_list; auto num_drivers = SDL_GetNumAudioDrivers(); for (int i = 0; i < num_drivers; i++) { driver_list.push_back(SDL_GetAudioDriver(i)); } return driver_list; }
/** * \brief Start and stop audio directly * * \sa https://wiki.libsdl.org/SDL_InitAudio * \sa https://wiki.libsdl.org/SDL_QuitAudio */ int audio_initQuitAudio() { int result; int i, iMax; const char* audioDriver; /* Stop SDL audio subsystem */ SDL_QuitSubSystem( SDL_INIT_AUDIO ); SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)"); /* Loop over all available audio drivers */ iMax = SDL_GetNumAudioDrivers(); SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()"); SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax); for (i = 0; i < iMax; i++) { audioDriver = SDL_GetAudioDriver(i); SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i); SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL"); SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* Call Init */ result = SDL_AudioInit(audioDriver); SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver); SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result); /* Call Quit */ SDL_AudioQuit(); SDLTest_AssertPass("Call to SDL_AudioQuit()"); } /* NULL driver specification */ audioDriver = NULL; /* Call Init */ result = SDL_AudioInit(audioDriver); SDLTest_AssertPass("Call to SDL_AudioInit(NULL)"); SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result); /* Call Quit */ SDL_AudioQuit(); SDLTest_AssertPass("Call to SDL_AudioQuit()"); /* Restart audio again */ _audioSetUp(NULL); return TEST_COMPLETED; }
static void osd_sdl_info(void) { #if SDL_VERSION_ATLEAST(1,3,0) int i, cur, num = SDL_GetNumVideoDrivers(); mame_printf_verbose("Available videodrivers: "); for (i=0;i<num;i++) { const char *name = SDL_GetVideoDriver(i); mame_printf_verbose("%s ", name); } mame_printf_verbose("\n"); mame_printf_verbose("Current Videodriver: %s\n", SDL_GetCurrentVideoDriver()); num = SDL_GetNumVideoDisplays(); cur = SDL_GetCurrentVideoDisplay(); for (i=0;i<num;i++) { SDL_DisplayMode mode; int j; SDL_SelectVideoDisplay(i); mame_printf_verbose("\tDisplay #%d\n", i); if (SDL_GetDesktopDisplayMode(&mode)); mame_printf_verbose("\t\tDesktop Mode: %dx%d-%d@%d\n", mode.w, mode.h, SDL_BITSPERPIXEL(mode.format), mode.refresh_rate); if (SDL_GetCurrentDisplayMode(&mode)); mame_printf_verbose("\t\tCurrent Display Mode: %dx%d-%d@%d\n", mode.w, mode.h, SDL_BITSPERPIXEL(mode.format), mode.refresh_rate); mame_printf_verbose("\t\tRenderdrivers:\n"); for (j=0; j<SDL_GetNumRenderDrivers(); j++) { SDL_RendererInfo info; SDL_GetRenderDriverInfo(j, &info); mame_printf_verbose("\t\t\t%10s (%dx%d)\n", info.name, info.max_texture_width, info.max_texture_height); } } SDL_SelectVideoDisplay(cur); mame_printf_verbose("Available audio drivers: \n"); num = SDL_GetNumAudioDrivers(); for (i=0;i<num;i++) { mame_printf_verbose("\t%-20s\n", SDL_GetAudioDriver(i)); } #endif }
/** * @brief Checks available audio driver names. */ int audio_printAudioDrivers() { int i, n; const char *name; /* Get number of drivers */ n = SDL_GetNumAudioDrivers(); AssertTrue(n>=0, "Number of audio drivers >= 0"); /* List drivers. */ if (n>0) { for (i=0; i<n; i++) { name = SDL_GetAudioDriver(i); AssertTrue(name != NULL, "name != NULL"); AssertTrue(strlen(name)>0, "name empty"); } } }
static int lua_getAudioDrivers(lutok::state& state){ state.new_table(); int ii=1; for (int i=0; i<SDL_GetNumAudioDrivers(); i++){ const char * name = SDL_GetAudioDriver( i ); if (name){ state.push_integer(ii++); state.new_table(); state.push_literal("id"); state.push_integer(i); state.set_table(); state.push_literal("name"); state.push_string(name); state.set_table(); state.set_table(); } } return 1; }
void Audio_init () { SDL_AudioSpec want; want.freq = 44100; want.format = AUDIO_S16LSB; want.channels = 2; want.samples = 2048; want.callback = Audio_mixer; want.userdata = NULL; if (App_get_option_IV("info")) { int i; printf("Audio devices:\n"); for (i = 0; i < SDL_GetNumAudioDevices(0); i++) { const char* name = SDL_GetAudioDeviceName(i, 0); printf("\t%s\n", name); } const char* cur = SDL_GetCurrentAudioDriver(); printf("Current audio driver:\n\t%s\n", cur); printf("Audio drivers:\n"); for (i = 0; i < SDL_GetNumAudioDrivers(); i++) { const char* name = SDL_GetAudioDriver(i); printf("\t%s\n", name); } } _audio.device = SDL_OpenAudioDevice(NULL, 0, &want, &_audio.spec, SDL_AUDIO_ALLOW_ANY_CHANGE); if (_audio.device <= 0) error("Could not open audio device"); if (!App_get_option_IV("mute")) _audio.volume = SDL_MIX_MAXVOLUME; (void)SDL_AtomicSet(&_audio.playback_rate, 1); SDL_PauseAudioDevice(_audio.device, 0); }
int main(int argc, char *argv[]) { int i; char filename[4096]; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Load the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } if (argc > 1) { SDL_strlcpy(filename, argv[1], sizeof(filename)); } else { SDL_strlcpy(filename, "sample.wav", sizeof(filename)); } /* Load the wave file into memory */ if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError()); quit(1); } wave.spec.callback = fillerup; #if HAVE_SIGNAL_H /* Set the signals */ #ifdef SIGHUP signal(SIGHUP, poked); #endif signal(SIGINT, poked); #ifdef SIGQUIT signal(SIGQUIT, poked); #endif signal(SIGTERM, poked); #endif /* HAVE_SIGNAL_H */ /* Show the list of available drivers */ SDL_Log("Available audio drivers:"); for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) { SDL_Log("%i: %s", i, SDL_GetAudioDriver(i)); } /* Initialize fillerup() variables */ if (SDL_OpenAudio(&wave.spec, NULL) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError()); SDL_FreeWAV(wave.sound); quit(2); } SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); /* Let the audio run */ SDL_PauseAudio(0); while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) SDL_Delay(1000); /* Clean up on signal */ SDL_CloseAudio(); SDL_FreeWAV(wave.sound); SDL_Quit(); return (0); }
SDL_bool SDLTest_CommonInit(SDLTest_CommonState * state) { int i, j, m, n, w, h; SDL_DisplayMode fullscreen_mode; if (state->flags & SDL_INIT_VIDEO) { if (state->verbose & VERBOSE_VIDEO) { n = SDL_GetNumVideoDrivers(); if (n == 0) { fprintf(stderr, "No built-in video drivers\n"); } else { fprintf(stderr, "Built-in video drivers:"); for (i = 0; i < n; ++i) { if (i > 0) { fprintf(stderr, ","); } fprintf(stderr, " %s", SDL_GetVideoDriver(i)); } fprintf(stderr, "\n"); } } if (SDL_VideoInit(state->videodriver) < 0) { fprintf(stderr, "Couldn't initialize video driver: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->verbose & VERBOSE_VIDEO) { fprintf(stderr, "Video driver: %s\n", SDL_GetCurrentVideoDriver()); } /* Upload GL settings */ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size); SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size); SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size); SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size); SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size); SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples); if (state->gl_accelerated >= 0) { SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, state->gl_accelerated); } SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing); if (state->gl_major_version) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version); } if (state->gl_debug) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); } if (state->verbose & VERBOSE_MODES) { SDL_Rect bounds; SDL_DisplayMode mode; int bpp; Uint32 Rmask, Gmask, Bmask, Amask; n = SDL_GetNumVideoDisplays(); fprintf(stderr, "Number of displays: %d\n", n); for (i = 0; i < n; ++i) { fprintf(stderr, "Display %d: %s\n", i, SDL_GetDisplayName(i)); SDL_zero(bounds); SDL_GetDisplayBounds(i, &bounds); fprintf(stderr, "Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y); SDL_GetDesktopDisplayMode(i, &mode); SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); fprintf(stderr, " Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n", mode.w, mode.h, mode.refresh_rate, bpp, SDL_GetPixelFormatName(mode.format)); if (Rmask || Gmask || Bmask) { fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask); fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask); fprintf(stderr, " Blue Mask = 0x%.8x\n", Bmask); if (Amask) fprintf(stderr, " Alpha Mask = 0x%.8x\n", Amask); } /* Print available fullscreen video modes */ m = SDL_GetNumDisplayModes(i); if (m == 0) { fprintf(stderr, "No available fullscreen video modes\n"); } else { fprintf(stderr, " Fullscreen video modes:\n"); for (j = 0; j < m; ++j) { SDL_GetDisplayMode(i, j, &mode); SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); fprintf(stderr, " Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n", j, mode.w, mode.h, mode.refresh_rate, bpp, SDL_GetPixelFormatName(mode.format)); if (Rmask || Gmask || Bmask) { fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask); fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask); fprintf(stderr, " Blue Mask = 0x%.8x\n", Bmask); if (Amask) fprintf(stderr, " Alpha Mask = 0x%.8x\n", Amask); } } } } } if (state->verbose & VERBOSE_RENDER) { SDL_RendererInfo info; n = SDL_GetNumRenderDrivers(); if (n == 0) { fprintf(stderr, "No built-in render drivers\n"); } else { fprintf(stderr, "Built-in render drivers:\n"); for (i = 0; i < n; ++i) { SDL_GetRenderDriverInfo(i, &info); SDLTest_PrintRenderer(&info); } } } SDL_zero(fullscreen_mode); switch (state->depth) { case 8: fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8; break; case 15: fullscreen_mode.format = SDL_PIXELFORMAT_RGB555; break; case 16: fullscreen_mode.format = SDL_PIXELFORMAT_RGB565; break; case 24: fullscreen_mode.format = SDL_PIXELFORMAT_RGB24; break; default: fullscreen_mode.format = SDL_PIXELFORMAT_RGB888; break; } fullscreen_mode.refresh_rate = state->refresh_rate; state->windows = (SDL_Window **) SDL_malloc(state->num_windows * sizeof(*state->windows)); state->renderers = (SDL_Renderer **) SDL_malloc(state->num_windows * sizeof(*state->renderers)); if (!state->windows || !state->renderers) { fprintf(stderr, "Out of memory!\n"); return SDL_FALSE; } for (i = 0; i < state->num_windows; ++i) { char title[1024]; if (state->num_windows > 1) { SDL_snprintf(title, SDL_arraysize(title), "%s %d", state->window_title, i + 1); } else { SDL_strlcpy(title, state->window_title, SDL_arraysize(title)); } state->windows[i] = SDL_CreateWindow(title, state->window_x, state->window_y, state->window_w, state->window_h, state->window_flags); if (!state->windows[i]) { fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->window_minW || state->window_minH) { SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH); } if (state->window_maxW || state->window_maxH) { SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH); } SDL_GetWindowSize(state->windows[i], &w, &h); if (!(state->window_flags & SDL_WINDOW_RESIZABLE) && (w != state->window_w || h != state->window_h)) { printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h); state->window_w = w; state->window_h = h; } if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) { fprintf(stderr, "Can't set up fullscreen display mode: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->window_icon) { SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon); if (icon) { SDL_SetWindowIcon(state->windows[i], icon); SDL_FreeSurface(icon); } } SDL_ShowWindow(state->windows[i]); state->renderers[i] = NULL; if (!state->skip_renderer && (state->renderdriver || !(state->window_flags & SDL_WINDOW_OPENGL))) { m = -1; if (state->renderdriver) { SDL_RendererInfo info; n = SDL_GetNumRenderDrivers(); for (j = 0; j < n; ++j) { SDL_GetRenderDriverInfo(j, &info); if (SDL_strcasecmp(info.name, state->renderdriver) == 0) { m = j; break; } } if (m == n) { fprintf(stderr, "Couldn't find render driver named %s", state->renderdriver); return SDL_FALSE; } } state->renderers[i] = SDL_CreateRenderer(state->windows[i], m, state->render_flags); if (!state->renderers[i]) { fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->logical_w && state->logical_h) { SDL_RenderSetLogicalSize(state->renderers[i], state->logical_w, state->logical_h); } else if (state->scale) { SDL_RenderSetScale(state->renderers[i], state->scale, state->scale); } if (state->verbose & VERBOSE_RENDER) { SDL_RendererInfo info; fprintf(stderr, "Current renderer:\n"); SDL_GetRendererInfo(state->renderers[i], &info); SDLTest_PrintRenderer(&info); } } } } if (state->flags & SDL_INIT_AUDIO) { if (state->verbose & VERBOSE_AUDIO) { n = SDL_GetNumAudioDrivers(); if (n == 0) { fprintf(stderr, "No built-in audio drivers\n"); } else { fprintf(stderr, "Built-in audio drivers:"); for (i = 0; i < n; ++i) { if (i > 0) { fprintf(stderr, ","); } fprintf(stderr, " %s", SDL_GetAudioDriver(i)); } fprintf(stderr, "\n"); } } if (SDL_AudioInit(state->audiodriver) < 0) { fprintf(stderr, "Couldn't initialize audio driver: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->verbose & VERBOSE_VIDEO) { fprintf(stderr, "Audio driver: %s\n", SDL_GetCurrentAudioDriver()); } if (SDL_OpenAudio(&state->audiospec, NULL) < 0) { fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); return SDL_FALSE; } } return SDL_TRUE; }
/** * \brief Pause and unpause audio * * \sa https://wiki.libsdl.org/SDL_PauseAudio */ int audio_pauseUnpauseAudio() { int result; int i, iMax, j, k, l; int totalDelay; int pause_on; int originalCounter; const char* audioDriver; SDL_AudioSpec desired; /* Stop SDL audio subsystem */ SDL_QuitSubSystem( SDL_INIT_AUDIO ); SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)"); /* Loop over all available audio drivers */ iMax = SDL_GetNumAudioDrivers(); SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()"); SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax); for (i = 0; i < iMax; i++) { audioDriver = SDL_GetAudioDriver(i); SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i); SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL"); SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* Change specs */ for (j = 0; j < 2; j++) { /* Call Init */ result = SDL_AudioInit(audioDriver); SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver); SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result); /* Set spec */ SDL_memset(&desired, 0, sizeof(desired)); switch (j) { case 0: /* Set standard desired spec */ desired.freq = 22050; desired.format = AUDIO_S16SYS; desired.channels = 2; desired.samples = 4096; desired.callback = _audio_testCallback; desired.userdata = NULL; case 1: /* Set custom desired spec */ desired.freq = 48000; desired.format = AUDIO_F32SYS; desired.channels = 2; desired.samples = 2048; desired.callback = _audio_testCallback; desired.userdata = NULL; break; } /* Call Open */ result = SDL_OpenAudio(&desired, NULL); SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL)", j); SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0 got: %d", result); /* Start and stop audio multiple times */ for (l=0; l<3; l++) { SDLTest_Log("Pause/Unpause iteration: %d", l+1); /* Reset callback counters */ _audio_testCallbackCounter = 0; _audio_testCallbackLength = 0; /* Un-pause audio to start playing (maybe multiple times) */ pause_on = 0; for (k=0; k <= j; k++) { SDL_PauseAudio(pause_on); SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1); } /* Wait for callback */ totalDelay = 0; do { SDL_Delay(10); totalDelay += 10; } while (_audio_testCallbackCounter == 0 && totalDelay < 1000); SDLTest_AssertCheck(_audio_testCallbackCounter > 0, "Verify callback counter; expected: >0 got: %d", _audio_testCallbackCounter); SDLTest_AssertCheck(_audio_testCallbackLength > 0, "Verify callback length; expected: >0 got: %d", _audio_testCallbackLength); /* Pause audio to stop playing (maybe multiple times) */ for (k=0; k <= j; k++) { pause_on = (k==0) ? 1 : SDLTest_RandomIntegerInRange(99, 9999); SDL_PauseAudio(pause_on); SDLTest_AssertPass("Call to SDL_PauseAudio(%d), call %d", pause_on, k+1); } /* Ensure callback is not called again */ originalCounter = _audio_testCallbackCounter; SDL_Delay(totalDelay + 10); SDLTest_AssertCheck(originalCounter == _audio_testCallbackCounter, "Verify callback counter; expected: %d, got: %d", originalCounter, _audio_testCallbackCounter); } /* Call Close */ SDL_CloseAudio(); SDLTest_AssertPass("Call to SDL_CloseAudio()"); /* Call Quit */ SDL_AudioQuit(); SDLTest_AssertPass("Call to SDL_AudioQuit()"); } /* spec loop */ } /* driver loop */ /* Restart audio again */ _audioSetUp(NULL); return TEST_COMPLETED; }
/** * \brief Start, open, close and stop audio * * \sa https://wiki.libsdl.org/SDL_InitAudio * \sa https://wiki.libsdl.org/SDL_OpenAudio * \sa https://wiki.libsdl.org/SDL_CloseAudio * \sa https://wiki.libsdl.org/SDL_QuitAudio */ int audio_initOpenCloseQuitAudio() { int result, expectedResult; int i, iMax, j, k; const char* audioDriver; SDL_AudioSpec desired; /* Stop SDL audio subsystem */ SDL_QuitSubSystem( SDL_INIT_AUDIO ); SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)"); /* Loop over all available audio drivers */ iMax = SDL_GetNumAudioDrivers(); SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()"); SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax); for (i = 0; i < iMax; i++) { audioDriver = SDL_GetAudioDriver(i); SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i); SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL"); SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* Change specs */ for (j = 0; j < 2; j++) { /* Call Init */ result = SDL_AudioInit(audioDriver); SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver); SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result); /* Set spec */ SDL_memset(&desired, 0, sizeof(desired)); switch (j) { case 0: /* Set standard desired spec */ desired.freq = 22050; desired.format = AUDIO_S16SYS; desired.channels = 2; desired.samples = 4096; desired.callback = _audio_testCallback; desired.userdata = NULL; case 1: /* Set custom desired spec */ desired.freq = 48000; desired.format = AUDIO_F32SYS; desired.channels = 2; desired.samples = 2048; desired.callback = _audio_testCallback; desired.userdata = NULL; break; } /* Call Open (maybe multiple times) */ for (k=0; k <= j; k++) { result = SDL_OpenAudio(&desired, NULL); SDLTest_AssertPass("Call to SDL_OpenAudio(desired_spec_%d, NULL), call %d", j, k+1); expectedResult = (k==0) ? 0 : -1; SDLTest_AssertCheck(result == expectedResult, "Verify return value; expected: %d, got: %d", expectedResult, result); } /* Call Close (maybe multiple times) */ for (k=0; k <= j; k++) { SDL_CloseAudio(); SDLTest_AssertPass("Call to SDL_CloseAudio(), call %d", k+1); } /* Call Quit (maybe multiple times) */ for (k=0; k <= j; k++) { SDL_AudioQuit(); SDLTest_AssertPass("Call to SDL_AudioQuit(), call %d", k+1); } } /* spec loop */ } /* driver loop */ /* Restart audio again */ _audioSetUp(NULL); return TEST_COMPLETED; }
void DisplayDialog() { int return_value; GtkWidget *dialog; GtkWidget *main_frame, *main_box; GtkWidget *mixing_frame, *mixing_box; GtkWidget *int_label, *int_box; GtkWidget *effects_check; GtkWidget *dealias_filter; GtkWidget *debug_check; GtkWidget *debug_button; GtkWidget *output_frame, *output_box; GtkWidget *mod_label, *mod_box; GtkWidget *api_label, *api_box; #if SDL_MAJOR_VERSION >= 2 GtkWidget *sdl_api_label, *sdl_api_box; #endif GtkWidget *latency_label, *latency_slide; GtkWidget *sync_label, *sync_box; GtkWidget *advanced_button; /* Create the widgets */ dialog = gtk_dialog_new_with_buttons( "SPU2-X Config", NULL, /* parent window*/ (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), "OK", GTK_RESPONSE_ACCEPT, "Cancel", GTK_RESPONSE_REJECT, NULL); int_label = gtk_label_new("Interpolation:"); int_box = gtk_combo_box_text_new(); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(int_box), "0 - Nearest (fastest/bad quality)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(int_box), "1 - Linear (simple/okay sound)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(int_box), "2 - Cubic (artificial highs)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(int_box), "3 - Hermite (better highs)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(int_box), "4 - Catmull-Rom (PS2-like/slow)"); gtk_combo_box_set_active(GTK_COMBO_BOX(int_box), Interpolation); effects_check = gtk_check_button_new_with_label("Disable Effects Processing"); dealias_filter = gtk_check_button_new_with_label("Use the de-alias filter (overemphasizes the highs)"); debug_check = gtk_check_button_new_with_label("Enable Debug Options"); debug_button = gtk_button_new_with_label("Debug..."); mod_label = gtk_label_new("Module:"); mod_box = gtk_combo_box_text_new(); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(mod_box), "0 - No Sound (emulate SPU2 only)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(mod_box), "1 - PortAudio (cross-platform)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(mod_box), "2 - SDL Audio (recommended for PulseAudio)"); //gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(mod_box), "3 - Alsa (probably doesn't work)"); gtk_combo_box_set_active(GTK_COMBO_BOX(mod_box), OutputModule); api_label = gtk_label_new("PortAudio API:"); api_box = gtk_combo_box_text_new(); #ifdef __linux__ // In order to keep it the menu light, I only put linux major api gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(api_box), "0 - ALSA (recommended)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(api_box), "1 - OSS (legacy)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(api_box), "2 - JACK"); #else gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(api_box), "OSS"); #endif gtk_combo_box_set_active(GTK_COMBO_BOX(api_box), OutputAPI); #if SDL_MAJOR_VERSION >= 2 sdl_api_label = gtk_label_new("SDL API:"); sdl_api_box = gtk_combo_box_text_new(); // YES It sucks ... for (int i = 0; i < SDL_GetNumAudioDrivers(); ++i) { gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sdl_api_box), SDL_GetAudioDriver(i)); } gtk_combo_box_set_active(GTK_COMBO_BOX(sdl_api_box), SdlOutputAPI); #endif latency_label = gtk_label_new("Latency:"); const int min_latency = SynchMode == 0 ? LATENCY_MIN_TIMESTRETCH : LATENCY_MIN; #if GTK_MAJOR_VERSION < 3 latency_slide = gtk_hscale_new_with_range(min_latency, LATENCY_MAX, 5); #else latency_slide = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, min_latency, LATENCY_MAX, 5); #endif gtk_range_set_value(GTK_RANGE(latency_slide), SndOutLatencyMS); sync_label = gtk_label_new("Synchronization Mode:"); sync_box = gtk_combo_box_text_new(); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sync_box), "TimeStretch (Recommended)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sync_box), "Async Mix (Breaks some games!)"); gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sync_box), "None (Audio can skip.)"); gtk_combo_box_set_active(GTK_COMBO_BOX(sync_box), SynchMode); advanced_button = gtk_button_new_with_label("Advanced..."); #if GTK_MAJOR_VERSION < 3 main_box = gtk_hbox_new(false, 5); #else main_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); #endif main_frame = gtk_frame_new("SPU2-X Config"); gtk_container_add(GTK_CONTAINER(main_frame), main_box); #if GTK_MAJOR_VERSION < 3 mixing_box = gtk_vbox_new(false, 5); #else mixing_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); #endif mixing_frame = gtk_frame_new("Mixing Settings:"); gtk_container_add(GTK_CONTAINER(mixing_frame), mixing_box); #if GTK_MAJOR_VERSION < 3 output_box = gtk_vbox_new(false, 5); #else output_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); #endif output_frame = gtk_frame_new("Output Settings:"); gtk_container_add(GTK_CONTAINER(output_frame), output_box); gtk_container_add(GTK_CONTAINER(mixing_box), int_label); gtk_container_add(GTK_CONTAINER(mixing_box), int_box); gtk_container_add(GTK_CONTAINER(mixing_box), effects_check); gtk_container_add(GTK_CONTAINER(mixing_box), dealias_filter); gtk_container_add(GTK_CONTAINER(mixing_box), debug_check); gtk_container_add(GTK_CONTAINER(mixing_box), debug_button); gtk_container_add(GTK_CONTAINER(output_box), mod_label); gtk_container_add(GTK_CONTAINER(output_box), mod_box); gtk_container_add(GTK_CONTAINER(output_box), api_label); gtk_container_add(GTK_CONTAINER(output_box), api_box); #if SDL_MAJOR_VERSION >= 2 gtk_container_add(GTK_CONTAINER(output_box), sdl_api_label); gtk_container_add(GTK_CONTAINER(output_box), sdl_api_box); #endif gtk_container_add(GTK_CONTAINER(output_box), sync_label); gtk_container_add(GTK_CONTAINER(output_box), sync_box); gtk_container_add(GTK_CONTAINER(output_box), latency_label); gtk_container_add(GTK_CONTAINER(output_box), latency_slide); gtk_container_add(GTK_CONTAINER(output_box), advanced_button); gtk_container_add(GTK_CONTAINER(main_box), mixing_frame); gtk_container_add(GTK_CONTAINER(main_box), output_frame); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(effects_check), EffectsDisabled); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dealias_filter), postprocess_filter_dealias); //FinalVolume; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(debug_check), DebugEnabled); gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), main_frame); gtk_widget_show_all(dialog); g_signal_connect(sync_box, "changed", G_CALLBACK(cb_adjust_latency), latency_slide); g_signal_connect_swapped(advanced_button, "clicked", G_CALLBACK(advanced_dialog), advanced_button); g_signal_connect_swapped(debug_button, "clicked", G_CALLBACK(debug_dialog), debug_button); return_value = gtk_dialog_run(GTK_DIALOG(dialog)); if (return_value == GTK_RESPONSE_ACCEPT) { DebugEnabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(debug_check)); postprocess_filter_dealias = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dealias_filter)); if (gtk_combo_box_get_active(GTK_COMBO_BOX(int_box)) != -1) Interpolation = gtk_combo_box_get_active(GTK_COMBO_BOX(int_box)); EffectsDisabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(effects_check)); //FinalVolume; if (gtk_combo_box_get_active(GTK_COMBO_BOX(mod_box)) != -1) OutputModule = gtk_combo_box_get_active(GTK_COMBO_BOX(mod_box)); if (gtk_combo_box_get_active(GTK_COMBO_BOX(api_box)) != -1) { OutputAPI = gtk_combo_box_get_active(GTK_COMBO_BOX(api_box)); #ifdef __linux__ switch (OutputAPI) { case 0: PortaudioOut->SetApiSettings(L"ALSA"); break; case 1: PortaudioOut->SetApiSettings(L"OSS"); break; case 2: PortaudioOut->SetApiSettings(L"JACK"); break; default: PortaudioOut->SetApiSettings(L"Unknown"); } #else switch (OutputAPI) { case 0: PortaudioOut->SetApiSettings(L"OSS"); break; default: PortaudioOut->SetApiSettings(L"Unknown"); } #endif } #if SDL_MAJOR_VERSION >= 2 if (gtk_combo_box_get_active(GTK_COMBO_BOX(sdl_api_box)) != -1) { SdlOutputAPI = gtk_combo_box_get_active(GTK_COMBO_BOX(sdl_api_box)); // YES It sucks ... SDLOut->SetApiSettings(wxString(SDL_GetAudioDriver(SdlOutputAPI), wxConvUTF8)); } #endif SndOutLatencyMS = gtk_range_get_value(GTK_RANGE(latency_slide)); if (gtk_combo_box_get_active(GTK_COMBO_BOX(sync_box)) != -1) SynchMode = gtk_combo_box_get_active(GTK_COMBO_BOX(sync_box)); } gtk_widget_destroy(dialog); }
void ReadSettings() { // For some reason this can be called before we know what ini file we're writing to. // Lets not try to read it if that happens. if (!pathSet) { FileLog("Read called without the path set.\n"); return; } Interpolation = CfgReadInt(L"MIXING", L"Interpolation", 4); EffectsDisabled = CfgReadBool(L"MIXING", L"Disable_Effects", false); postprocess_filter_dealias = CfgReadBool(L"MIXING", L"DealiasFilter", false); FinalVolume = ((float)CfgReadInt(L"MIXING", L"FinalVolume", 100)) / 100; if (FinalVolume > 1.0f) FinalVolume = 1.0f; AdvancedVolumeControl = CfgReadBool(L"MIXING", L"AdvancedVolumeControl", false); VolumeAdjustCdb = CfgReadFloat(L"MIXING", L"VolumeAdjustC(dB)", 0); VolumeAdjustFLdb = CfgReadFloat(L"MIXING", L"VolumeAdjustFL(dB)", 0); VolumeAdjustFRdb = CfgReadFloat(L"MIXING", L"VolumeAdjustFR(dB)", 0); VolumeAdjustBLdb = CfgReadFloat(L"MIXING", L"VolumeAdjustBL(dB)", 0); VolumeAdjustBRdb = CfgReadFloat(L"MIXING", L"VolumeAdjustBR(dB)", 0); VolumeAdjustSLdb = CfgReadFloat(L"MIXING", L"VolumeAdjustSL(dB)", 0); VolumeAdjustSRdb = CfgReadFloat(L"MIXING", L"VolumeAdjustSR(dB)", 0); VolumeAdjustLFEdb = CfgReadFloat(L"MIXING", L"VolumeAdjustLFE(dB)", 0); VolumeAdjustC = powf(10, VolumeAdjustCdb / 10); VolumeAdjustFL = powf(10, VolumeAdjustFLdb / 10); VolumeAdjustFR = powf(10, VolumeAdjustFRdb / 10); VolumeAdjustBL = powf(10, VolumeAdjustBLdb / 10); VolumeAdjustBR = powf(10, VolumeAdjustBRdb / 10); VolumeAdjustSL = powf(10, VolumeAdjustSLdb / 10); VolumeAdjustSR = powf(10, VolumeAdjustSRdb / 10); VolumeAdjustLFE = powf(10, VolumeAdjustLFEdb / 10); delayCycles = CfgReadInt(L"DEBUG", L"DelayCycles", 4); wxString temp; CfgReadStr(L"OUTPUT", L"Output_Module", temp, PortaudioOut->GetIdent()); OutputModule = FindOutputModuleById(temp.c_str()); // find the driver index of this module // find current API #ifdef __linux__ CfgReadStr(L"PORTAUDIO", L"HostApi", temp, L"ALSA"); OutputAPI = -1; if (temp == L"ALSA") OutputAPI = 0; if (temp == L"OSS") OutputAPI = 1; if (temp == L"JACK") OutputAPI = 2; #else CfgReadStr(L"PORTAUDIO", L"HostApi", temp, L"OSS"); OutputAPI = -1; if (temp == L"OSS") OutputAPI = 0; #endif #ifdef __unix__ CfgReadStr(L"SDL", L"HostApi", temp, L"pulseaudio"); SdlOutputAPI = -1; #if SDL_MAJOR_VERSION >= 2 // YES It sucks ... for (int i = 0; i < SDL_GetNumAudioDrivers(); ++i) { if (!temp.Cmp(wxString(SDL_GetAudioDriver(i), wxConvUTF8))) SdlOutputAPI = i; } #endif #endif SndOutLatencyMS = CfgReadInt(L"OUTPUT", L"Latency", 300); SynchMode = CfgReadInt(L"OUTPUT", L"Synch_Mode", 0); PortaudioOut->ReadSettings(); #ifdef __unix__ SDLOut->ReadSettings(); #endif SoundtouchCfg::ReadSettings(); DebugConfig::ReadSettings(); // Sanity Checks // ------------- Clampify(SndOutLatencyMS, LATENCY_MIN, LATENCY_MAX); WriteSettings(); spuConfig->Flush(); }
SDL_bool CommonInit(CommonState * state) { int i, j, m, n; SDL_DisplayMode fullscreen_mode; if (state->flags & SDL_INIT_VIDEO) { if (state->verbose & VERBOSE_VIDEO) { n = SDL_GetNumVideoDrivers(); if (n == 0) { fprintf(stderr, "No built-in video drivers\n"); } else { fprintf(stderr, "Built-in video drivers:"); for (i = 0; i < n; ++i) { if (i > 0) { fprintf(stderr, ","); } fprintf(stderr, " %s", SDL_GetVideoDriver(i)); } fprintf(stderr, "\n"); } } if (SDL_VideoInit(state->videodriver, 0) < 0) { fprintf(stderr, "Couldn't initialize video driver: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->verbose & VERBOSE_VIDEO) { fprintf(stderr, "Video driver: %s\n", SDL_GetCurrentVideoDriver()); } if (state->verbose & VERBOSE_MODES) { SDL_DisplayMode mode; int bpp; Uint32 Rmask, Gmask, Bmask, Amask; n = SDL_GetNumVideoDisplays(); fprintf(stderr, "Number of displays: %d\n", n); for (i = 0; i < n; ++i) { fprintf(stderr, "Display %d:\n", i); SDL_SelectVideoDisplay(i); SDL_GetDesktopDisplayMode(&mode); SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); fprintf(stderr, " Current mode: %dx%d@%dHz, %d bits-per-pixel\n", mode.w, mode.h, mode.refresh_rate, bpp); if (Rmask || Gmask || Bmask) { fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask); fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask); fprintf(stderr, " Blue Mask = 0x%.8x\n", Bmask); if (Amask) fprintf(stderr, " Alpha Mask = 0x%.8x\n", Amask); } /* Print available fullscreen video modes */ m = SDL_GetNumDisplayModes(); if (m == 0) { fprintf(stderr, "No available fullscreen video modes\n"); } else { fprintf(stderr, " Fullscreen video modes:\n"); for (j = 0; j < m; ++j) { SDL_GetDisplayMode(j, &mode); SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); fprintf(stderr, " Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", j, mode.w, mode.h, mode.refresh_rate, bpp); if (Rmask || Gmask || Bmask) { fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask); fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask); fprintf(stderr, " Blue Mask = 0x%.8x\n", Bmask); if (Amask) fprintf(stderr, " Alpha Mask = 0x%.8x\n", Amask); } } } } } SDL_SelectVideoDisplay(state->display); if (state->verbose & VERBOSE_RENDER) { SDL_RendererInfo info; n = SDL_GetNumRenderDrivers(); if (n == 0) { fprintf(stderr, "No built-in render drivers\n"); } else { fprintf(stderr, "Built-in render drivers:\n"); for (i = 0; i < n; ++i) { SDL_GetRenderDriverInfo(i, &info); PrintRenderer(&info); } } } switch (state->depth) { case 8: fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8; break; case 15: fullscreen_mode.format = SDL_PIXELFORMAT_RGB555; break; case 16: fullscreen_mode.format = SDL_PIXELFORMAT_RGB565; break; default: fullscreen_mode.format = SDL_PIXELFORMAT_RGB888; break; } fullscreen_mode.w = state->window_w; fullscreen_mode.h = state->window_h; fullscreen_mode.refresh_rate = state->refresh_rate; SDL_SetFullscreenDisplayMode(&fullscreen_mode); state->windows = (SDL_WindowID *) SDL_malloc(state->num_windows * sizeof(*state->windows)); if (!state->windows) { fprintf(stderr, "Out of memory!\n"); return SDL_FALSE; } for (i = 0; i < state->num_windows; ++i) { char title[1024]; if (state->num_windows > 1) { SDL_snprintf(title, SDL_arraysize(title), "%s %d", state->window_title, i + 1); } else { SDL_strlcpy(title, state->window_title, SDL_arraysize(title)); } state->windows[i] = SDL_CreateWindow(title, state->window_x, state->window_y, state->window_w, state->window_h, state->window_flags); if (!state->windows[i]) { fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError()); return SDL_FALSE; } if (!state->skip_renderer && (state->renderdriver || !(state->window_flags & SDL_WINDOW_OPENGL))) { m = -1; if (state->renderdriver) { SDL_RendererInfo info; n = SDL_GetNumRenderDrivers(); for (j = 0; j < n; ++j) { SDL_GetRenderDriverInfo(j, &info); if (SDL_strcasecmp(info.name, state->renderdriver) == 0) { m = j; break; } } if (m == n) { fprintf(stderr, "Couldn't find render driver named %s", state->renderdriver); return SDL_FALSE; } } if (SDL_CreateRenderer (state->windows[i], m, state->render_flags) < 0) { fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->verbose & VERBOSE_RENDER) { SDL_RendererInfo info; fprintf(stderr, "Current renderer:\n"); SDL_GetRendererInfo(&info); PrintRenderer(&info); } } } SDL_SelectRenderer(state->windows[0]); } if (state->flags & SDL_INIT_AUDIO) { if (state->verbose & VERBOSE_AUDIO) { n = SDL_GetNumAudioDrivers(); if (n == 0) { fprintf(stderr, "No built-in audio drivers\n"); } else { fprintf(stderr, "Built-in audio drivers:"); for (i = 0; i < n; ++i) { if (i > 0) { fprintf(stderr, ","); } fprintf(stderr, " %s", SDL_GetAudioDriver(i)); } fprintf(stderr, "\n"); } } if (SDL_AudioInit(state->audiodriver) < 0) { fprintf(stderr, "Couldn't initialize audio driver: %s\n", SDL_GetError()); return SDL_FALSE; } if (state->verbose & VERBOSE_VIDEO) { fprintf(stderr, "Audio driver: %s\n", SDL_GetCurrentAudioDriver()); } if (SDL_OpenAudio(&state->audiospec, NULL) < 0) { fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); return SDL_FALSE; } } return SDL_TRUE; }
int main(int argc, char *argv[]) { int i; char filename[4096]; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Load the SDL library */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return (1); } /* Some targets (Mac CoreAudio) need an event queue for audio hotplug, so make and immediately hide a window. */ SDL_MinimizeWindow(SDL_CreateWindow("testaudiohotplug", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0)); if (argc > 1) { SDL_strlcpy(filename, argv[1], sizeof(filename)); } else { SDL_strlcpy(filename, "sample.wav", sizeof(filename)); } /* Load the wave file into memory */ if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError()); quit(1); } #if HAVE_SIGNAL_H /* Set the signals */ #ifdef SIGHUP signal(SIGHUP, poked); #endif signal(SIGINT, poked); #ifdef SIGQUIT signal(SIGQUIT, poked); #endif signal(SIGTERM, poked); #endif /* HAVE_SIGNAL_H */ /* Show the list of available drivers */ SDL_Log("Available audio drivers:"); for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) { SDL_Log("%i: %s", i, SDL_GetAudioDriver(i)); } SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver()); #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(loop, 0, 1); #else while (!done) { SDL_Delay(100); iteration(); } #endif /* Clean up on signal */ SDL_FreeWAV(sound); SDL_Quit(); return (0); }
static int lua_SDL_GetNumAudioDrivers(lutok::state& state){ state.push_integer(SDL_GetNumAudioDrivers()); return 1; }