works in dosbox
[dos_sbtest] / src / audio.c
1 #include <stdio.h>
2 #include "audio.h"
3 #include "au_sb.h"
4
5 struct audrv {
6         void *(*get_buffer)(int *size);
7         void (*start)(int rate, int nchan);
8         void (*pause)(void);
9         void (*cont)(void);
10         void (*stop)(void);
11         void (*volume)(int vol);
12 };
13
14 static struct audrv drv;
15
16 static audio_callback_func cbfunc;
17 static void *cbcls;
18
19 void audio_init(void)
20 {
21         if(sb_detect()) {
22                 drv.get_buffer = sb_buffer;
23                 drv.start = sb_start;
24                 drv.pause = sb_pause;
25                 drv.cont = sb_continue;
26                 drv.stop = sb_stop;
27                 drv.volume = sb_volume;
28                 return;
29         }
30
31         printf("No supported audio device detected\n");
32 }
33
34 void audio_set_callback(audio_callback_func func, void *cls)
35 {
36         cbfunc = func;
37         cbcls = cls;
38 }
39
40 int audio_callback(void *buf, int sz)
41 {
42         if(!cbfunc) {
43                 return 0;
44         }
45         return cbfunc(buf, sz, cbcls);
46 }
47
48 void audio_play(int rate, int nchan)
49 {
50         drv.start(rate, nchan);
51 }
52
53 void audio_pause(void)
54 {
55         drv.pause();
56 }
57
58 void audio_resume(void)
59 {
60         drv.cont();
61 }
62
63 void audio_stop(void)
64 {
65         drv.stop();
66 }
67
68 void audio_volume(int vol)
69 {
70         drv.volume(vol);
71 }