-
Notifications
You must be signed in to change notification settings - Fork 2
/
sdl_snd.c
72 lines (55 loc) · 1.16 KB
/
sdl_snd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdlib.h>
#include <SDL.h>
#include "def.h"
#include "device.h"
#include "hardware.h"
void fill_audio(void *udata, Uint8 *stream, int len);
samp getsample(void);
samp *buf;
Uint4 bsize;
bool wave_device_available = FALSE;
bool initsounddevice(void)
{
return(TRUE);
}
bool setsounddevice(int base, int irq, int dma, Uint4 samprate, Uint4 bufsize)
{
SDL_AudioSpec wanted;
bool result = FALSE;
wanted.freq = samprate;
wanted.samples = bufsize;
wanted.channels = 1;
wanted.format = AUDIO_U8;
wanted.userdata = NULL;
wanted.callback = fill_audio;
#ifdef _VGL
restorekeyb();
#endif
if ((SDL_Init(SDL_INIT_AUDIO)) >= 0)
if ((SDL_OpenAudio(&wanted, NULL)) >= 0)
result = TRUE;
if (result == FALSE)
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
else {
buf = malloc(bufsize);
bsize = bufsize;
wave_device_available = TRUE;
}
#ifdef _VGL
initkeyb();
#endif
return(result);
}
void fill_audio(void *udata, Uint8 *stream, int len)
{
int i;
if (len > bsize)
len = bsize;
for(i = 0; i<len; i++)
buf[i] = getsample();
SDL_MixAudio(stream, buf, len, SDL_MIX_MAXVOLUME);
}
void killsounddevice(void)
{
SDL_PauseAudio(1);
}