Mercurial > hg > forks > pwpunix
annotate pwplib/snd-sdl.c @ 6:e2f028bf775a
Possibly start SDL audio more sanely.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 18 May 2010 05:34:18 +0300 |
parents | acb5694e93d9 |
children | a379d6a2a717 |
rev | line source |
---|---|
0 | 1 /* |
2 * pwplib SDL (Simple Directmedia Layer) audio "driver" | |
3 * (C) Copyright 2010 ccr/TNSP^PWP <ccr@tnsp.org> | |
4 * | |
5 * This file and other changes are distributed under same | |
6 * license as pwplib itself. | |
7 */ | |
8 | |
9 #include "config.h" | |
10 | |
11 #ifdef DRIVE_SDL | |
12 | |
13 #include <stdio.h> | |
14 #include <stdlib.h> | |
15 #include <unistd.h> | |
16 #include <SDL.h> | |
17 | |
18 #include "pwplib.h" | |
19 | |
20 #define TIMERHZ 72 | |
21 | |
6
e2f028bf775a
Possibly start SDL audio more sanely.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
22 static int pwp_sdlaudio_start = 1; |
0 | 23 |
24 extern void gb_sound(int, int, int, int); | |
25 | |
26 | |
27 static void pwp_sdlaudio_fill(void *udata, Uint8 * buf, int len) | |
28 { | |
29 pwplib.player(); | |
30 gb_genwave(buf, len); | |
31 } | |
32 | |
33 static void pwp_sdlaudio_loopflush(void) | |
34 { | |
6
e2f028bf775a
Possibly start SDL audio more sanely.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
35 if (pwp_sdlaudio_start) { |
e2f028bf775a
Possibly start SDL audio more sanely.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
36 pwp_sdlaudio_start = 0; |
e2f028bf775a
Possibly start SDL audio more sanely.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
37 SDL_PauseAudio(0); |
e2f028bf775a
Possibly start SDL audio more sanely.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
38 } |
0 | 39 } |
40 | |
41 static void pwp_sdlaudio_close(void) | |
42 { | |
43 SDL_CloseAudio(); | |
44 } | |
45 | |
46 int pwp_sdlaudio_init() | |
47 { | |
48 SDL_AudioSpec fmt; | |
49 | |
50 fmt.freq = 44100; | |
51 fmt.format = AUDIO_U8; | |
52 fmt.channels = 1; | |
53 fmt.samples = fmt.freq / TIMERHZ; | |
54 fmt.callback = pwp_sdlaudio_fill; | |
55 | |
56 if (SDL_OpenAudio(&fmt, NULL) < 0) | |
57 { | |
58 pwpwrite("* SDL: Could not get desired audio format.\n"); | |
59 return 0; | |
60 } | |
61 | |
62 pwpwrite("* SDL sound\n"); | |
63 | |
64 pwplib.sound = gb_sound; | |
65 pwplib.loopflush = pwp_sdlaudio_loopflush; | |
66 gb_init(fmt.freq); | |
67 | |
68 pwp_regdestr(pwp_sdlaudio_close); | |
69 | |
70 return 1; | |
71 } | |
72 #endif |