ref: 46f9c39bf931494b7e2e3bdfbcdb17dae6ea599a
dir: /ft2dec.c/
#include "common.h" #include "pmplay.h" #include "pmp_mix.h" static void usage(void) { fprint(2, "usage: %s [-v volume] [-a amp] [-f freq] <file.(xm|mod|ft) >/dev/audio\n", argv0); exits("usage"); } void main(int argc, char **argv) { int n, r, sz, frq, amp, vol; s16int s[1024*2]; u8int *b; frq = 44100; amp = 10; vol = 256; ARGBEGIN{ case 'f': frq = atoi(EARGF(usage())); assert(frq >= 8000 && frq <= 96000); break; case 'a': amp = atoi(EARGF(usage())); assert(amp >= 1 && amp <= 32); break; case 'v': vol = atoi(EARGF(usage())); assert(vol >= 0 && vol <= 256); break; default: usage(); }ARGEND if(!initMusic(frq, nelem(s)/2, true, true)) sysfatal("initMusic"); setAmp(amp); setMasterVol(vol); sz = 32768; b = nil; for(n = 0;; n += r){ if(sz-n < 65536){ sz *= 2; if((b = realloc(b, sz)) == nil) sysfatal("memory"); } if((r = read(0, b+n, sz-n)) < 0) sysfatal("%r"); if(r == 0) break; } if(!loadMusicFromData(b, n)) sysfatal("loadMusicFromData"); if(!startMusic()) sysfatal("startMusic"); startPlaying(); for(;;){ mix_UpdateBuffer(s, nelem(s)/2); write(1, s, sizeof(s)); if(dump_EndOfTune(song.len-1)) break; } stopMusic(); freeMusic(); exits(nil); }