dropped the compiled-in sound sample, loading from the filesystem
[dos_sbtest] / src / main.c
index fd87b7a..c7630e5 100644 (file)
@@ -1,15 +1,31 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include "audio.h"
 
 static int au_callback(void *buffer, int size, void *cls);
 
-/* defined in ausamples.s */
-extern signed char snd_click[];
-extern int snd_click_size;
+static signed char *snd_click;
+static int snd_click_size;
 
 int main(int argc, char **argv)
 {
+       FILE *fp;
+
+       if(!(fp = fopen("click.pcm", "rb"))) {
+               fprintf(stderr, "failed to open click.pcm\n");
+               return 1;
+       }
+       fseek(fp, 0, SEEK_END);
+       snd_click_size = ftell(fp);
+       rewind(fp);
+       if(!(snd_click = malloc(snd_click_size))) {
+               fprintf(stderr, "failed to allocate sound sample\n");
+               return 1;
+       }
+       fread(snd_click, 1, snd_click_size, fp);
+       fclose(fp);
+
        audio_init();
        audio_set_callback(au_callback, 0);
 
@@ -21,23 +37,6 @@ int main(int argc, char **argv)
 /* snd_click_size is < 65536 so we can just throw it all at once in there */
 static int au_callback(void *buffer, int size, void *cls)
 {
-       int i;
-       signed char *ptr = buffer;
-       signed char *src = snd_click;
-       /*
-          for(i=0; i<size; i++) {
-          if((i / 32) & 1) {
-        *ptr++ = -64;
-        } else {
-        *ptr++ = 64;
-        }
-        }
-        */
-       /*memcpy(buffer, snd_click, snd_click_size);*/
-
-       for(i=0; i<snd_click_size; i++) {
-               *ptr++ = *src++;
-       }
-
+       memcpy(buffer, snd_click, snd_click_size);
        return snd_click_size;
 }