src/sound/sdl_s.cpp
branchcustombridgeheads
changeset 5649 55c8267c933f
parent 5643 3778051e8095
child 6253 23983700e3d7
equal deleted inserted replaced
5648:1608018c5ff2 5649:55c8267c933f
       
     1 /* $Id$ */
       
     2 
       
     3 #include "../stdafx.h"
       
     4 
       
     5 #ifdef WITH_SDL
       
     6 
       
     7 #include "../openttd.h"
       
     8 #include "../driver.h"
       
     9 #include "../mixer.h"
       
    10 #include "../sdl.h"
       
    11 #include "sdl_s.h"
       
    12 #include <SDL.h>
       
    13 
       
    14 static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
       
    15 {
       
    16 	MxMixSamples(stream, len / 4);
       
    17 }
       
    18 
       
    19 static const char *SdlSoundStart(const char * const *parm)
       
    20 {
       
    21 	SDL_AudioSpec spec;
       
    22 
       
    23 	const char *s = SdlOpen(SDL_INIT_AUDIO);
       
    24 	if (s != NULL) return s;
       
    25 
       
    26 	spec.freq = GetDriverParamInt(parm, "hz", 11025);
       
    27 	spec.format = AUDIO_S16SYS;
       
    28 	spec.channels = 2;
       
    29 	spec.samples = 512;
       
    30 	spec.callback = fill_sound_buffer;
       
    31 	SDL_CALL SDL_OpenAudio(&spec, &spec);
       
    32 	SDL_CALL SDL_PauseAudio(0);
       
    33 	return NULL;
       
    34 }
       
    35 
       
    36 static void SdlSoundStop(void)
       
    37 {
       
    38 	SDL_CALL SDL_CloseAudio();
       
    39 	SdlClose(SDL_INIT_AUDIO);
       
    40 }
       
    41 
       
    42 const HalSoundDriver _sdl_sound_driver = {
       
    43 	SdlSoundStart,
       
    44 	SdlSoundStop,
       
    45 };
       
    46 
       
    47 #endif