# sdl_s.cpp

Go to the documentation of this file.

    00001 /* $Id: sdl_s.cpp 16804 2009-07-13 10:16:50Z rubidium $ */
    00002
    00005 #ifdef WITH_SDL
    00006
    00007 #include "../stdafx.h"
    00008
    00009 #include "../mixer.h"
    00010 #include "../sdl.h"
    00011 #include "sdl_s.h"
    00012 #include <SDL.h>
    00013
    00014 static FSoundDriver_SDL iFSoundDriver_SDL;
    00015
    00016 static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
    00017 {
    00018   MxMixSamples(stream, len / 4);
    00019 }
    00020
    00021 const char *SoundDriver_SDL::Start(const char * const *parm)
    00022 {
    00023   SDL_AudioSpec spec;
    00024
    00025   const char *s = SdlOpen(SDL_INIT_AUDIO);
    00026   if (s != NULL) return s;
    00027
    00028   spec.freq = GetDriverParamInt(parm, "hz", 11025);
    00029   spec.format = AUDIO_S16SYS;
    00030   spec.channels = 2;
    00031   spec.samples = 512;
    00032   spec.callback = fill_sound_buffer;
    00033   MxInitialize(spec.freq);
    00034   SDL_CALL SDL_OpenAudio(&spec, &spec);
    00035   SDL_CALL SDL_PauseAudio(0);
    00036   return NULL;
    00037 }
    00038
    00039 void SoundDriver_SDL::Stop()
    00040 {
    00041   SDL_CALL SDL_CloseAudio();
    00042   SdlClose(SDL_INIT_AUDIO);
    00043 }
    00044
    00045 #endif /* WITH_SDL */