audio/pcmconv: cleanup

This commit is contained in:
cinap_lenrek 2012-12-12 19:04:57 +01:00
parent 985df234d6
commit a8b02eb198

View file

@ -23,9 +23,9 @@ struct Chan
ulong ; /* filter step */ ulong ; /* filter step */
ulong le; /* filter end */ ulong le; /* filter end */
int u; /* unity scale */
int *h; /* filter coefficients */ int *h; /* filter coefficients */
int *; /* coefficient deltas for interpolation */ int *; /* coefficient deltas for interpolation */
int u; /* unity scale */
int wx; /* extra samples */ int wx; /* extra samples */
int ix; /* buffer index */ int ix; /* buffer index */
@ -34,17 +34,13 @@ struct Chan
}; };
enum { enum {
Nl = 8, Nl = 8, /* 2^Nl samples per zero crossing in fir */
= 8, = 8, /* phase bits for filter interpolation */
Np = Nl+, Np = Nl+, /* phase bits (fract of fixed point) */
L = 1<<Np,
Nz = 13,
One = 1<<Np, One = 1<<Np,
}; };
void int
chaninit(Chan *c, int irate, int orate, int count) chaninit(Chan *c, int irate, int orate, int count)
{ {
static int h[] = { static int h[] = {
@ -55,29 +51,35 @@ chaninit(Chan *c, int irate, int orate, int count)
c->ρ = ((uvlong)orate<<Np)/irate; c->ρ = ((uvlong)orate<<Np)/irate;
if(c->ρ == One) if(c->ρ == One)
return; goto Done;
c-> = ((uvlong)irate<<Np)/orate; c-> = ((uvlong)irate<<Np)/orate;
c-> = L; c-> = 1<<(Nl+);
c->le = nelem(h)<<;
c->wx = 1 + (c->le / c->);
c->u = 13128; /* unity scale factor for fir */
if(c->ρ < One){ if(c->ρ < One){
c->u *= c->ρ; c->u *= c->ρ;
c->u >>= Np; c->u >>= Np;
c-> *= c->ρ; c-> *= c->ρ;
c-> >>= Np; c-> >>= Np;
c->wx *= c->;
c->wx >>= Np;
} }
c->le = nelem(h)<<;
c->h = h;
if(!init){ if(!init){
init = 1; init = 1;
for(n=0; n<nelem()-1; n++) for(n=0; n<nelem()-1; n++)
[n] = h[n+1] - h[n]; [n] = h[n+1] - h[n];
} }
c->h = h;
c-> = ; c-> = ;
c->u = 13128; /* unity scale factor for fir */
c->wx = 2*Nz*irate / orate;
c->ix = c->wx; c->ix = c->wx;
c->t = c->ix<<Np; c->t = c->ix<<Np;
c->nx = c->wx*2 + count; c->nx = c->wx*2 + count;
c->x = sbrk(sizeof(c->x[0]) * c->nx); c->x = sbrk(sizeof(c->x[0]) * c->nx);
count += c->nx; /* account for buffer accumulation */
Done:
return ((uvlong)count * c->ρ) >> Np;
} }
int int
@ -418,7 +420,7 @@ main(int argc, char *argv[])
int *out, *in; int *out, *in;
Chan ch[8]; Chan ch[8];
Desc i, o; Desc i, o;
int k, r, n, m; int k, n, m, nin, nout;
vlong l; vlong l;
void (*oconv)(int *, uchar *, int, int, int) = nil; void (*oconv)(int *, uchar *, int, int, int) = nil;
@ -473,21 +475,22 @@ main(int argc, char *argv[])
if(i.fmt == 'f' || o.fmt == 'f') if(i.fmt == 'f' || o.fmt == 'f')
setfcr(getfcr() & ~(FPINVAL|FPOVFL)); setfcr(getfcr() & ~(FPINVAL|FPOVFL));
n = (sizeof(ibuf)-i.framesz)/i.framesz; nin = (sizeof(ibuf)-i.framesz)/i.framesz;
r = n*i.framesz; in = sbrk(sizeof(int) * nin);
m = 3+(n*o.rate)/i.rate;
in = sbrk(sizeof(int) * n);
out = sbrk(sizeof(int) * m);
obuf = sbrk(o.framesz * m);
nout = 0;
memset(ch, 0, sizeof(ch)); memset(ch, 0, sizeof(ch));
for(k=0; k < i.channels; k++) for(k=0; k < i.channels; k++)
chaninit(&ch[k], i.rate, o.rate, n); nout = chaninit(&ch[k], i.rate, o.rate, nin);
out = sbrk(sizeof(int) * nout);
obuf = sbrk(o.framesz * nout);
for(;;){ for(;;){
if(l >= 0 && l < r) n = nin * i.framesz;
r = l; if(l >= 0 && l < n)
n = cread(0, ibuf, r, i.framesz); n = l;
n = cread(0, ibuf, n, i.framesz);
if(n < 0) if(n < 0)
sysfatal("read: %r"); sysfatal("read: %r");
if(l > 0) if(l > 0)