2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file sdl_s.cpp Playing sound via SDL. */
|
|
|
|
|
2005-07-25 07:16:10 +00:00
|
|
|
#ifdef WITH_SDL
|
|
|
|
|
2007-02-23 12:56:10 +00:00
|
|
|
#include "../stdafx.h"
|
|
|
|
|
2005-07-25 07:16:10 +00:00
|
|
|
#include "../mixer.h"
|
|
|
|
#include "../sdl.h"
|
|
|
|
#include "sdl_s.h"
|
2005-07-23 15:16:57 +00:00
|
|
|
#include <SDL.h>
|
|
|
|
|
2007-07-05 12:23:54 +00:00
|
|
|
static FSoundDriver_SDL iFSoundDriver_SDL;
|
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
|
|
|
|
{
|
2006-02-05 09:56:04 +00:00
|
|
|
MxMixSamples(stream, len / 4);
|
2005-07-23 15:16:57 +00:00
|
|
|
}
|
|
|
|
|
2007-07-05 12:23:54 +00:00
|
|
|
const char *SoundDriver_SDL::Start(const char * const *parm)
|
2005-07-23 15:16:57 +00:00
|
|
|
{
|
|
|
|
SDL_AudioSpec spec;
|
|
|
|
|
|
|
|
const char *s = SdlOpen(SDL_INIT_AUDIO);
|
|
|
|
if (s != NULL) return s;
|
|
|
|
|
2009-08-09 23:04:08 +00:00
|
|
|
spec.freq = GetDriverParamInt(parm, "hz", 44100);
|
2005-07-23 15:16:57 +00:00
|
|
|
spec.format = AUDIO_S16SYS;
|
|
|
|
spec.channels = 2;
|
|
|
|
spec.samples = 512;
|
|
|
|
spec.callback = fill_sound_buffer;
|
2009-07-10 18:22:04 +00:00
|
|
|
MxInitialize(spec.freq);
|
2005-07-23 15:16:57 +00:00
|
|
|
SDL_CALL SDL_OpenAudio(&spec, &spec);
|
|
|
|
SDL_CALL SDL_PauseAudio(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-05 12:23:54 +00:00
|
|
|
void SoundDriver_SDL::Stop()
|
2005-07-23 15:16:57 +00:00
|
|
|
{
|
|
|
|
SDL_CALL SDL_CloseAudio();
|
|
|
|
SdlClose(SDL_INIT_AUDIO);
|
|
|
|
}
|
|
|
|
|
2007-02-12 21:55:10 +00:00
|
|
|
#endif /* WITH_SDL */
|