Increase the number of road and tram subtypes to 32.
[openttd-joker.git] / src / sound / sdl_s.cpp
blob1c4fcb33da4ef5b14e79bda80c6bf5621bdd7736
1 /* $Id: sdl_s.cpp 22406 2011-05-01 19:51:52Z rubidium $ */
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 != nullptr) 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 nullptr;
55 void SoundDriver_SDL::Stop()
57 SDL_CALL SDL_CloseAudio();
58 SdlClose(SDL_INIT_AUDIO);
61 #endif /* WITH_SDL */