OpenTTD
sdl_s.cpp
Go to the documentation of this file.
1 /* $Id: sdl_s.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2 
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  */
9 
12 #ifdef WITH_SDL
13 
14 #include "../stdafx.h"
15 
16 #include "../mixer.h"
17 #include "../sdl.h"
18 #include "sdl_s.h"
19 #include <SDL.h>
20 
21 #include "../safeguards.h"
22 
25 
32 static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
33 {
34  MxMixSamples(stream, len / 4);
35 }
36 
37 const char *SoundDriver_SDL::Start(const char * const *parm)
38 {
39  SDL_AudioSpec spec;
40 
41  const char *s = SdlOpen(SDL_INIT_AUDIO);
42  if (s != NULL) return s;
43 
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;
53 }
54 
56 {
57  SDL_CALL SDL_CloseAudio();
58  SdlClose(SDL_INIT_AUDIO);
59 }
60 
61 #endif /* WITH_SDL */