sound/sdl.c
author tron
Sat, 23 Jul 2005 15:34:05 +0000
changeset 2173 dabe358aec40
parent 2171 008122046f7f
permissions -rw-r--r--
(svn r2687) Make a variable static
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     1
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     2
#include "openttd.h"
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents: 2169
diff changeset
     3
#include "driver.h"
1496
3d0b86f5dcb8 (svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents: 1474
diff changeset
     4
#include "mixer.h"
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents: 2169
diff changeset
     5
#include "sdl.h"
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents: 2169
diff changeset
     6
#include "sound/sdl.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     7
#include <SDL.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
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
    10
{
423
9e28d68fa333 (svn r621) Merge r450 to trunk:
tron
parents: 410
diff changeset
    11
	MxMixSamples(_mixer, stream, len / 4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
1301
313804601383 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
    14
static const char *SdlSoundStart(const char * const *parm)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
	SDL_AudioSpec spec;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 179
diff changeset
    17
1301
313804601383 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
    18
	const char *s = SdlOpen(SDL_INIT_AUDIO);
423
9e28d68fa333 (svn r621) Merge r450 to trunk:
tron
parents: 410
diff changeset
    19
	if (s != NULL) return s;
9e28d68fa333 (svn r621) Merge r450 to trunk:
tron
parents: 410
diff changeset
    20
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
	spec.freq = GetDriverParamInt(parm, "hz", 11025);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
	spec.format = AUDIO_S16SYS;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
	spec.channels = 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
	spec.samples = 512;
423
9e28d68fa333 (svn r621) Merge r450 to trunk:
tron
parents: 410
diff changeset
    25
	spec.callback = fill_sound_buffer;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
	SDL_CALL SDL_OpenAudio(&spec, &spec);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	SDL_CALL SDL_PauseAudio(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
423
9e28d68fa333 (svn r621) Merge r450 to trunk:
tron
parents: 410
diff changeset
    31
static void SdlSoundStop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	SDL_CALL SDL_CloseAudio();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	SdlClose(SDL_INIT_AUDIO);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
const HalSoundDriver _sdl_sound_driver = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	SdlSoundStart,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	SdlSoundStop,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
};