X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dos_sbtest;a=blobdiff_plain;f=src%2Fmain.c;fp=src%2Fmain.c;h=264c04ee674914f805c657a509db87cfbb1f34d5;hp=c7630e57e1d304b3c2614ee89cfe2e496e0051b2;hb=07c19444f4f2a55abf97d181ab62aeaa51033c62;hpb=01a545fde6dc446fe626382f8bba50b9b7c1a35b diff --git a/src/main.c b/src/main.c index c7630e5..264c04e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,42 +1,75 @@ -#include -#include -#include -#include "audio.h" - -static int au_callback(void *buffer, int size, void *cls); - -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); - - 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 +#include +#include +#include +#include +#include "audio.h" + +static int au_callback(void *buffer, int size, void *cls); + +static signed char *snd_click; +static int snd_click_size; + +static int dbg_cbcalled; + +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); + + for(;;) { + if(kbhit()) { + int c = getch(); + switch(c) { + case 27: + goto end; + case ' ': + if(audio_isplaying()) { + audio_stop(); + } else { + audio_play(22050, 1); + } + break; + default: + break; + } + } + + _disable(); + if(dbg_cbcalled) { + dbg_cbcalled = 0; + _enable(); + printf("callback called!\n"); + } else { + _enable(); + } + } + +end: + audio_stop(); + 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) +{ + dbg_cbcalled = 1; + memcpy(buffer, snd_click, snd_click_size); + return snd_click_size; +}