~ft/dumb

4ab1bfbc5d1d261f48404aa4859e002a9f0d9838 — Sigrid Solveig Haflínudóttir 1 year, 9 months ago 6620310
moddec: add options to specify output sampling rate and to choose resampler
1 files changed, 21 insertions(+), 8 deletions(-)

M examples/moddec.c
M examples/moddec.c => examples/moddec.c +21 -8
@@ 4,7 4,6 @@

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define RATIO (65536.0/44100.0)

enum {
	Nsamp = 4096,


@@ 15,7 14,7 @@ static uchar b[Nsamp*2*2];
static void
usage(void)
{
	fprint(2, "usage: %s [-s SECONDS]\n", argv0);
	fprint(2, "usage: %s [-f FREQ] [-r RESAMPLER] [-s SECONDS]\n", argv0);
	exits("usage");
}



@@ 24,17 23,29 @@ main(int argc, char **argv)
{
	DUMB_IT_SIGRENDERER *itren;
	DUH_SIGRENDERER *ren;
	int n, sz, r, resamp;
	double pos, freq, ratio;
	sample_t **samp;
	char *data, *t;
	int n, sz, r;
	double pos;
	long nsamp;
	DUH *f;

	setfcr(getfcr() & ~(FPINVAL|FPOVFL));

	freq = 44100.0;
	resamp = DUMB_RQ_CUBIC;
	pos = 0.0;
	ARGBEGIN{
	case 'f':
		freq = atoi(EARGF(usage()));
		if(freq < 1000)
			sysfatal("invalid frequency %d", (int)freq);
		break;
	case 'r':
		resamp = atoi(EARGF(usage()));
		if(resamp < 0)
			sysfatal("invalid resampler %d", resamp);
		break;
	case 's':
		pos = atof(EARGF(usage()));
		break;


@@ 59,22 70,24 @@ main(int argc, char **argv)
			break;
	}

	ratio = 65536.0/freq;

	if((f = dumb_read_any(dumbfile_open_memory(data, sz), 0, 0)) == nil)
		sysfatal("unknown/invalid mod");
	if((t = (char*)duh_get_tag(f, "TITLE")) != nil && *t)
		fprint(2, "%s\n", t);
	fprint(2, "duration: %g\n", duh_get_length(f)*RATIO/100000.0);
	ren = duh_start_sigrenderer(f, 0, 2, pos*100000.0/RATIO);
	fprint(2, "duration: %g\n", duh_get_length(f)*ratio/100000.0);
	ren = duh_start_sigrenderer(f, 0, 2, pos*100000.0/ratio);
	itren = duh_get_it_sigrenderer(ren);
	dumb_it_set_loop_callback(itren, dumb_it_callback_terminate, nil);
	dumb_it_set_xm_speed_zero_callback(itren, dumb_it_callback_terminate, nil);
	dumb_it_set_resampling_quality(itren, DUMB_RQ_CUBIC);
	dumb_it_set_resampling_quality(itren, resamp);
	if(pos > 0.0)
		fprint(2, "time: %g\n", pos);

	n = 0;
	for(;;){
		n = duh_render_int(ren, &samp, &nsamp, 16, 0, 1.0, RATIO, MAX(n, Nsamp), b);
		n = duh_render_int(ren, &samp, &nsamp, 16, 0, 1.0, ratio, MAX(n, Nsamp), b);
		if(n <= 0)
			break;
		if(write(1, b, n*2*2) != n*2*2)