# sdl_s.cpp

Go to the documentation of this file.

    00001 /* $Id: sdl_s.cpp 18820 2010-01-15 23:45:26Z rubidium $ */
    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
    00021 static FSoundDriver_SDL iFSoundDriver_SDL;
    00022
    00023 static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
    00024 {
    00025   MxMixSamples(stream, len / 4);
    00026 }
    00027
    00028 const char *SoundDriver_SDL::Start(const char * const *parm)
    00029 {
    00030   SDL_AudioSpec spec;
    00031
    00032   const char *s = SdlOpen(SDL_INIT_AUDIO);
    00033   if (s != NULL) return s;
    00034
    00035   spec.freq = GetDriverParamInt(parm, "hz", 44100);
    00036   spec.format = AUDIO_S16SYS;
    00037   spec.channels = 2;
    00038   spec.samples = GetDriverParamInt(parm, "samples", 1024);
    00039   spec.callback = fill_sound_buffer;
    00040   MxInitialize(spec.freq);
    00041   SDL_CALL SDL_OpenAudio(&spec, &spec);
    00042   SDL_CALL SDL_PauseAudio(0);
    00043   return NULL;
    00044 }
    00045
    00046 void SoundDriver_SDL::Stop()
    00047 {
    00048   SDL_CALL SDL_CloseAudio();
    00049   SdlClose(SDL_INIT_AUDIO);
    00050 }
    00051
    00052 #endif /* WITH_SDL */