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/>.
10 /** @file sdl_s.cpp Playing sound via SDL. */
14 #include "../stdafx.h"
21 #include "../safeguards.h"
23 /** Factory for the SDL sound driver. */
24 static FSoundDriver_SDL iFSoundDriver_SDL
;
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
)
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
;
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);
55 void SoundDriver_SDL::Stop()
57 SDL_CALL
SDL_CloseAudio();
58 SdlClose(SDL_INIT_AUDIO
);