src/sound/sdl_s.cpp
author richk
Sat, 14 Jul 2007 19:42:58 +0000
branchNewGRF_ports
changeset 6720 35756db7e577
parent 6573 7624f942237f
child 10429 1b99254f9607
permissions -rw-r--r--
(svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2174
diff changeset
     2
6450
1c2016673250 (svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents: 6314
diff changeset
     3
#ifdef WITH_SDL
1c2016673250 (svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents: 6314
diff changeset
     4
2189
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     5
#include "../stdafx.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     6
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     7
#include "../driver.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     8
#include "../mixer.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     9
#include "../sdl.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    10
#include "sdl_s.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include <SDL.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6573
diff changeset
    13
static FSoundDriver_SDL iFSoundDriver_SDL;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6573
diff changeset
    14
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
static void CDECL fill_sound_buffer(void *userdata, Uint8 *stream, int len)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
{
2977
0240dd4704a7 (svn r3552) Remove the global variable _mixer
tron
parents: 2189
diff changeset
    17
	MxMixSamples(stream, len / 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6573
diff changeset
    20
const char *SoundDriver_SDL::Start(const char * const *parm)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
	SDL_AudioSpec spec;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
    23
1301
313804601383 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
    24
	const char *s = SdlOpen(SDL_INIT_AUDIO);
423
9e28d68fa333 (svn r621) Merge r450 to trunk:
tron
parents: 410
diff changeset
    25
	if (s != NULL) return s;
9e28d68fa333 (svn r621) Merge r450 to trunk:
tron
parents: 410
diff changeset
    26
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	spec.freq = GetDriverParamInt(parm, "hz", 11025);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	spec.format = AUDIO_S16SYS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	spec.channels = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	spec.samples = 512;
423
9e28d68fa333 (svn r621) Merge r450 to trunk:
tron
parents: 410
diff changeset
    31
	spec.callback = fill_sound_buffer;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	SDL_CALL SDL_OpenAudio(&spec, &spec);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	SDL_CALL SDL_PauseAudio(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6573
diff changeset
    37
void SoundDriver_SDL::Stop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	SDL_CALL SDL_CloseAudio();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	SdlClose(SDL_INIT_AUDIO);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
6314
f738bcf05ad6 (svn r8691) -Cleanup: Some proper #endif comments for sound/music/video files, and a little elimination of magic numbers in Win32SoundStart
Darkvater
parents: 5835
diff changeset
    43
#endif /* WITH_SDL */