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
|
|
22
|
|
23 extern void gb_sound(int, int, int, int);
|
|
24
|
|
25
|
|
26 static void pwp_sdlaudio_fill(void *udata, Uint8 * buf, int len)
|
|
27 {
|
|
28 pwplib.player();
|
|
29 gb_genwave(buf, len);
|
|
30 }
|
|
31
|
|
32 static void pwp_sdlaudio_loopflush(void)
|
|
33 {
|
|
34 /* Dummy */
|
|
35 }
|
|
36
|
|
37 static void pwp_sdlaudio_close(void)
|
|
38 {
|
|
39 SDL_CloseAudio();
|
|
40 }
|
|
41
|
|
42 int pwp_sdlaudio_init()
|
|
43 {
|
|
44 SDL_AudioSpec fmt;
|
|
45
|
|
46 fmt.freq = 44100;
|
|
47 fmt.format = AUDIO_U8;
|
|
48 fmt.channels = 1;
|
|
49 fmt.samples = fmt.freq / TIMERHZ;
|
|
50 fmt.callback = pwp_sdlaudio_fill;
|
|
51
|
|
52 if (SDL_OpenAudio(&fmt, NULL) < 0)
|
|
53 {
|
|
54 pwpwrite("* SDL: Could not get desired audio format.\n");
|
|
55 return 0;
|
|
56 }
|
|
57
|
|
58 pwpwrite("* SDL sound\n");
|
|
59
|
|
60 pwplib.sound = gb_sound;
|
|
61 pwplib.loopflush = pwp_sdlaudio_loopflush;
|
|
62 gb_init(fmt.freq);
|
|
63
|
|
64 SDL_PauseAudio(0);
|
|
65
|
|
66 pwp_regdestr(pwp_sdlaudio_close);
|
|
67
|
|
68 return 1;
|
|
69 }
|
|
70 #endif
|