/** * Initialize the audio subsystem. */ int InitSound() { int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq, lowpass, samples; FCEUI_printf("Initializing audio...\n"); g_config->getOption("SDL.Sound", &sound); if (!sound) return 0; memset(&spec, 0, sizeof(spec)); if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { puts(SDL_GetError()); KillSound(); return(0); } char driverName[8]; SDL_AudioDriverName(driverName, 8); fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName); // load configuration variables g_config->getOption("SDL.Sound.Rate", &soundrate); g_config->getOption("SDL.Sound.BufSize", &soundbufsize); g_config->getOption("SDL.Sound.Volume", &soundvolume); g_config->getOption("SDL.Sound.Quality", &soundq); g_config->getOption("SDL.Sound.TriangleVolume", &soundtrianglevolume); g_config->getOption("SDL.Sound.Square1Volume", &soundsquare1volume); g_config->getOption("SDL.Sound.Square2Volume", &soundsquare2volume); g_config->getOption("SDL.Sound.NoiseVolume", &soundnoisevolume); g_config->getOption("SDL.Sound.PCMVolume", &soundpcmvolume); g_config->getOption("SDL.Sound.LowPass", &lowpass); spec.freq = soundrate; spec.format = AUDIO_S16; spec.channels = 2; spec.samples = 512; spec.callback = fillaudio; spec.userdata = 0; while(spec.samples < (soundrate / 60) * 1) spec.samples <<= 1; s_BufferSize = spec.samples * 4; s_Buffer = (int16 *) malloc(sizeof(int16) * s_BufferSize); if (!s_Buffer) return 0; s_BufferRead = s_BufferWrite = s_BufferIn = 0; printf("SDL Size: %d, Internal size: %d\n", spec.samples, s_BufferSize); if(SDL_OpenAudio(&spec, 0) < 0) { puts(SDL_GetError()); KillSound(); return(0); } SDL_PauseAudio(0); FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundQuality(soundq); FCEUI_Sound(soundrate); FCEUI_SetTriangleVolume(soundtrianglevolume); FCEUI_SetSquare1Volume(soundsquare1volume); FCEUI_SetSquare2Volume(soundsquare2volume); FCEUI_SetNoiseVolume(soundnoisevolume); FCEUI_SetPCMVolume(soundpcmvolume); FCEUI_SetLowPass(lowpass); return (1); }
/** * Initialize the audio subsystem. */ int InitSound() { int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq; SDL_AudioSpec spec; g_config->getOption("SDL.Sound", &sound); if(!sound) { return 0; } memset(&spec, 0, sizeof(spec)); if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { puts(SDL_GetError()); KillSound(); return 0; } char driverName[8]; #if SDL_VERSION_ATLEAST(2, 0, 0) // TODO - SDL 2 #else SDL_AudioDriverName(driverName, 8); fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName); #endif // load configuration variables g_config->getOption("SDL.Sound.Rate", &soundrate); g_config->getOption("SDL.Sound.BufSize", &soundbufsize); g_config->getOption("SDL.Sound.Volume", &soundvolume); g_config->getOption("SDL.Sound.Quality", &soundq); g_config->getOption("SDL.Sound.TriangleVolume", &soundtrianglevolume); g_config->getOption("SDL.Sound.Square1Volume", &soundsquare1volume); g_config->getOption("SDL.Sound.Square2Volume", &soundsquare2volume); g_config->getOption("SDL.Sound.NoiseVolume", &soundnoisevolume); g_config->getOption("SDL.Sound.PCMVolume", &soundpcmvolume); spec.freq = soundrate; spec.format = AUDIO_S16SYS; spec.channels = 1; spec.samples = 512; spec.callback = fillaudio; spec.userdata = 0; s_BufferSize = soundbufsize * soundrate / 1000; // For safety, set a bare minimum: if (s_BufferSize < spec.samples * 2) s_BufferSize = spec.samples * 2; s_Buffer = (int *)FCEU_dmalloc(sizeof(int) * s_BufferSize); if (!s_Buffer) return 0; s_BufferRead = s_BufferWrite = s_BufferIn = 0; if(SDL_OpenAudio(&spec, 0) < 0) { puts(SDL_GetError()); KillSound(); return 0; } SDL_PauseAudio(0); FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundQuality(soundq); FCEUI_Sound(soundrate); FCEUI_SetTriangleVolume(soundtrianglevolume); FCEUI_SetSquare1Volume(soundsquare1volume); FCEUI_SetSquare2Volume(soundsquare2volume); FCEUI_SetNoiseVolume(soundnoisevolume); FCEUI_SetPCMVolume(soundpcmvolume); return 1; }