From: Nathaniel Wesley Filardo Date: Tue, 23 Feb 2010 05:36:40 +0000 (-0500) Subject: Add tracker --export and --audio options X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=030234a1d15a3757d09cdb93e5cad798d9ee6cee;p=acmetensortoys-chiptunes Add tracker --export and --audio options --- diff --git a/tracker/gui.c b/tracker/gui.c index 810e683..b18909e 100644 --- a/tracker/gui.c +++ b/tracker/gui.c @@ -21,7 +21,7 @@ char filename[1024]; char *notenames[] = {"C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "H-"}; -char *validcmds = "0dfijlmtvw~+="; +char *validcmds = "0dfijlmtvw~+=S"; /*char *keymap[2] = { ";oqejkixdbhmwnvsz", @@ -487,11 +487,13 @@ void exportdata(FILE *f, int maxtrack, int *resources) { exportseek = 0; for(i = 0; i < 16 + maxtrack; i++) { + // if(exportfile) fprintf(exportfile, "songdata_resources%d:\n", i); exportchunk(resources[i], 13); } resources[nres++] = alignbyte(); + // if(exportfile) fprintf(exportfile, "songdata_song:\n"); for(i = 0; i < songlen; i++) { for(j = 0; j < 4; j++) { if(song[i].transp[j]) { @@ -508,6 +510,7 @@ void exportdata(FILE *f, int maxtrack, int *resources) { for(i = 1; i < 16; i++) { resources[nres++] = alignbyte(); + // if(exportfile) fprintf(exportfile, "songdata_instrument%d:\n", i); if(instrument[i].length > 1) { for(j = 0; j < instrument[i].length; j++) { exportchunk(packcmd(instrument[i].line[j].cmd), 8); @@ -521,6 +524,7 @@ void exportdata(FILE *f, int maxtrack, int *resources) { for(i = 1; i <= maxtrack; i++) { resources[nres++] = alignbyte(); + // if(exportfile) fprintf(exportfile, "songdata_track%d:\n", i); for(j = 0; j < tracklen; j++) { u8 cmd = packcmd(track[i].line[j].cmd[0]); @@ -544,9 +548,18 @@ void exportdata(FILE *f, int maxtrack, int *resources) { } } -void export() { - FILE *f = fopen("exported.s", "w"); - FILE *hf = fopen("exported.h", "w"); +void export(char *stem) { + int blen = strlen(stem) + 5; + char *buf = alloca(blen); + if(!buf) { + return; + } + snprintf(buf, blen, "%s.s", stem); + FILE *f = fopen(buf, "w"); + + snprintf(buf, blen, "%s.h", stem); + FILE *hf = fopen(buf, "w"); + int i, j; int maxtrack = 0; int resources[256]; @@ -650,7 +663,7 @@ void handleinput() { optimize(); break; case '%': - export(); + export("export"); break; case KEY_LEFT: switch(currtab) { diff --git a/tracker/main.c b/tracker/main.c index 99e161b..0e65317 100644 --- a/tracker/main.c +++ b/tracker/main.c @@ -62,36 +62,51 @@ void audiocb(void *userdata, Uint8 *buf, int len) { } int main(int argc, char **argv) { - SDL_AudioSpec requested, obtained; - - if(argc != 2) { - err(1, "usage: %s \n", argv[0]); - } - - SDL_Init(SDL_INIT_AUDIO); - - atexit(SDL_Quit); - - requested.freq = 16000; - requested.format = AUDIO_U8; - requested.samples = 256; - requested.callback = audiocb; - requested.channels = 1; - if(SDL_OpenAudio(&requested, &obtained) == -1) { - err(1, "SDL_OpenAudio"); - } - - fprintf(stderr, "freq %d\n", obtained.freq); - fprintf(stderr, "samples %d\n", obtained.samples); - initchip(); initgui(); - loadfile(argv[1]); - - SDL_PauseAudio(0); - - guiloop(); + if(!strcmp("--audio", argv[1])) { + loadfile(argv[2]); + + char *pcmname = (argc > 2) ? argv[3] : "audio" ; + FILE *f = fopen(pcmname, "w"); + + startplaysong(0); + + while(playsong) { + u8 res = interrupthandler(); + fwrite(&res, 1, 1, f); + } + fclose(f); + } else if(!strcmp("--export", argv[1])) { + loadfile(argv[2]); + char *exportname = (argc > 2) ? argv[3] : "export" ; + export(exportname); + } else { + if(argc != 2) { + err(1, "usage: %s \n", argv[0]); + } + + SDL_AudioSpec requested, obtained; + SDL_Init(SDL_INIT_AUDIO); + atexit(SDL_Quit); + + requested.freq = 16000; + requested.format = AUDIO_U8; + requested.samples = 256; + requested.callback = audiocb; + requested.channels = 1; + if(SDL_OpenAudio(&requested, &obtained) == -1) { + err(1, "SDL_OpenAudio"); + } + + fprintf(stderr, "freq %d\n", obtained.freq); + fprintf(stderr, "samples %d\n", obtained.samples); + + loadfile(argv[1]); + SDL_PauseAudio(0); + guiloop(); + } return 0; } diff --git a/tracker/stuff.h b/tracker/stuff.h index 2c3f59b..0367441 100644 --- a/tracker/stuff.h +++ b/tracker/stuff.h @@ -31,6 +31,7 @@ void guiloop(); void startplaysong(int); void startplaytrack(int); void loadfile(char *); +void export(char *); extern u8 trackpos; extern u8 playtrack;