sdl_s.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifdef WITH_SDL
00013 
00014 #include "../stdafx.h"
00015 
00016 #include "../mixer.h"
00017 #include "../sdl.h"
00018 #include "sdl_s.h"
00019 #include <SDL.h>
00020 
00022 static FSoundDriver_SDL iFSoundDriver_SDL;
00023 
00030 static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
00031 {
00032   MxMixSamples(stream, len / 4);
00033 }
00034 
00035 const char *SoundDriver_SDL::Start(const char * const *parm)
00036 {
00037   SDL_AudioSpec spec;
00038 
00039   const char *s = SdlOpen(SDL_INIT_AUDIO);
00040   if (s != NULL) return s;
00041 
00042   spec.freq = GetDriverParamInt(parm, "hz", 44100);
00043   spec.format = AUDIO_S16SYS;
00044   spec.channels = 2;
00045   spec.samples = GetDriverParamInt(parm, "samples", 1024);
00046   spec.callback = fill_sound_buffer;
00047   MxInitialize(spec.freq);
00048   SDL_CALL SDL_OpenAudio(&spec, &spec);
00049   SDL_CALL SDL_PauseAudio(0);
00050   return NULL;
00051 }
00052 
00053 void SoundDriver_SDL::Stop()
00054 {
00055   SDL_CALL SDL_CloseAudio();
00056   SdlClose(SDL_INIT_AUDIO);
00057 }
00058 
00059 #endif /* WITH_SDL */

Generated on Mon May 9 05:19:00 2011 for OpenTTD by  doxygen 1.6.1