dropped the compiled-in sound sample, loading from the filesystem
[dos_sbtest] / src / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "audio.h"
5
6 static int au_callback(void *buffer, int size, void *cls);
7
8 static signed char *snd_click;
9 static int snd_click_size;
10
11 int main(int argc, char **argv)
12 {
13         FILE *fp;
14
15         if(!(fp = fopen("click.pcm", "rb"))) {
16                 fprintf(stderr, "failed to open click.pcm\n");
17                 return 1;
18         }
19         fseek(fp, 0, SEEK_END);
20         snd_click_size = ftell(fp);
21         rewind(fp);
22         if(!(snd_click = malloc(snd_click_size))) {
23                 fprintf(stderr, "failed to allocate sound sample\n");
24                 return 1;
25         }
26         fread(snd_click, 1, snd_click_size, fp);
27         fclose(fp);
28
29         audio_init();
30         audio_set_callback(au_callback, 0);
31
32         audio_play(22050, 1);
33
34         return 0;
35 }
36
37 /* snd_click_size is < 65536 so we can just throw it all at once in there */
38 static int au_callback(void *buffer, int size, void *cls)
39 {
40         memcpy(buffer, snd_click, snd_click_size);
41         return snd_click_size;
42 }