-#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;
-
-int main(int argc, char **argv)
-{
- audio_init();
- audio_set_callback(au_callback, 0);
-
- audio_play(22050, 1);
-
- return 0;
-}
-
-/* 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)
-{
- memcpy(buffer, snd_click, snd_click_size);
- return snd_click_size;
-}
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <dos.h>\r
+#include <conio.h>\r
+#include "audio.h"\r
+\r
+static int au_callback(void *buffer, int size, void *cls);\r
+\r
+static signed char *snd_click;\r
+static int snd_click_size;\r
+\r
+static int dbg_cbcalled;\r
+\r
+int main(int argc, char **argv)\r
+{\r
+ FILE *fp;\r
+\r
+ if(!(fp = fopen("click.pcm", "rb"))) {\r
+ fprintf(stderr, "failed to open click.pcm\n");\r
+ return 1;\r
+ }\r
+ fseek(fp, 0, SEEK_END);\r
+ snd_click_size = ftell(fp);\r
+ rewind(fp);\r
+ if(!(snd_click = malloc(snd_click_size))) {\r
+ fprintf(stderr, "failed to allocate sound sample\n");\r
+ return 1;\r
+ }\r
+ fread(snd_click, 1, snd_click_size, fp);\r
+ fclose(fp);\r
+\r
+ audio_init();\r
+ audio_set_callback(au_callback, 0);\r
+\r
+ for(;;) {\r
+ if(kbhit()) {\r
+ int c = getch();\r
+ switch(c) {\r
+ case 27:\r
+ goto end;\r
+ case ' ':\r
+ if(audio_isplaying()) {\r
+ audio_stop();\r
+ } else {\r
+ audio_play(22050, 8, 1);\r
+ }\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ }\r
+\r
+ _disable();\r
+ if(dbg_cbcalled) {\r
+ dbg_cbcalled = 0;\r
+ _enable();\r
+ printf("callback called!\n");\r
+ } else {\r
+ _enable();\r
+ }\r
+ }\r
+\r
+end:\r
+ audio_stop();\r
+ return 0;\r
+}\r
+\r
+/* snd_click_size is < 65536 so we can just throw it all at once in there */\r
+static int au_callback(void *buffer, int size, void *cls)\r
+{\r
+ dbg_cbcalled = 1;\r
+ memcpy(buffer, snd_click, snd_click_size);\r
+ return snd_click_size;\r
+}\r