ref: 9976f6fa310e511273e5ed02c5c3ebca4af5c3da
parent: cea086da84e938d9396df9d250072ec956a125c6
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sat Dec 5 12:48:05 EST 2020
increase buffer size, add -s command line option
--- a/ft2dec.c
+++ b/ft2dec.c
@@ -2,10 +2,15 @@
#include "pmplay.h"
#include "pmp_mix.h"
+enum
+{
+ Nsamp = 4096,
+};
+
static void
usage(void)
{
- fprint(2, "usage: %s [-v volume] [-a amp] [-f freq] <file.(xm|mod|ft) >/dev/audio\n", argv0);
+ fprint(2, "usage: %s [-a amp] [-f freq] [-s seconds] [-v volume] <file.(xm|mod|ft) >/dev/audio\n", argv0);
exits("usage");
}
@@ -12,21 +17,27 @@
void
main(int argc, char **argv)
{
- int n, r, sz, frq, amp, vol;
- s16int s[1024*2];
+ int amp, frq, vol, n, r, sz;
+ s16int s[Nsamp*2];
+ double pos;
u8int *b;
- frq = 44100;
amp = 10;
+ frq = 44100;
+ pos = 0;
vol = 256;
ARGBEGIN{
+ case 'a':
+ amp = atoi(EARGF(usage()));
+ assert(amp >= 1 && amp <= 32);
+ break;
case 'f':
frq = atoi(EARGF(usage()));
assert(frq >= 8000 && frq <= 96000);
break;
- case 'a':
- amp = atoi(EARGF(usage()));
- assert(amp >= 1 && amp <= 32);
+ case 's':
+ pos = atof(EARGF(usage()));
+ assert(pos >= 0.0);
break;
case 'v':
vol = atoi(EARGF(usage()));
@@ -36,7 +47,7 @@
usage();
}ARGEND
- if(!initMusic(frq, nelem(s)/2, true, true))
+ if(!initMusic(frq, Nsamp, true, true))
sysfatal("initMusic");
setAmp(amp);
setMasterVol(vol);
@@ -60,11 +71,21 @@
if(!startMusic())
sysfatal("startMusic");
startPlaying();
+ for(; pos > 0.0; pos -= (double)n / 44100.0){
+ n = pos * 44100;
+ if(n < 1)
+ break;
+ if(n > Nsamp)
+ n = Nsamp;
+ mix_UpdateBuffer(s, n);
+ if(dump_EndOfTune(song.len-1))
+ break;
+ }
for(;;){
- mix_UpdateBuffer(s, nelem(s)/2);
- write(1, s, sizeof(s));
if(dump_EndOfTune(song.len-1))
break;
+ mix_UpdateBuffer(s, Nsamp);
+ write(1, s, sizeof(s));
}
stopMusic();