(svn r27729) -Codechange: Do not count static NewGRF when checking for the maximum...
[openttd.git] / src / sound / sdl_s.cpp
blobe3fb99eaa790b43601eafb295adec913e3f8d7bf
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file sdl_s.cpp Playing sound via SDL. */
12 #ifdef WITH_SDL
14 #include "../stdafx.h"
16 #include "../mixer.h"
17 #include "../sdl.h"
18 #include "sdl_s.h"
19 #include <SDL.h>
21 #include "../safeguards.h"
23 /** Factory for the SDL sound driver. */
24 static FSoundDriver_SDL iFSoundDriver_SDL;
26 /**
27 * Callback that fills the sound buffer.
28 * @param userdata Ignored.
29 * @param stream The stream to put data into.
30 * @param len The length of the stream in bytes.
32 static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
34 MxMixSamples(stream, len / 4);
37 const char *SoundDriver_SDL::Start(const char * const *parm)
39 SDL_AudioSpec spec;
41 const char *s = SdlOpen(SDL_INIT_AUDIO);
42 if (s != NULL) return s;
44 spec.freq = GetDriverParamInt(parm, "hz", 44100);
45 spec.format = AUDIO_S16SYS;
46 spec.channels = 2;
47 spec.samples = GetDriverParamInt(parm, "samples", 1024);
48 spec.callback = fill_sound_buffer;
49 MxInitialize(spec.freq);
50 SDL_CALL SDL_OpenAudio(&spec, &spec);
51 SDL_CALL SDL_PauseAudio(0);
52 return NULL;
55 void SoundDriver_SDL::Stop()
57 SDL_CALL SDL_CloseAudio();
58 SdlClose(SDL_INIT_AUDIO);
61 #endif /* WITH_SDL */