audio/pcmconv: cleanup
This commit is contained in:
parent
985df234d6
commit
a8b02eb198
|
@ -23,9 +23,9 @@ struct Chan
|
||||||
ulong lΔ; /* filter step */
|
ulong lΔ; /* filter step */
|
||||||
ulong le; /* filter end */
|
ulong le; /* filter end */
|
||||||
|
|
||||||
|
int u; /* unity scale */
|
||||||
int *h; /* filter coefficients */
|
int *h; /* filter coefficients */
|
||||||
int *hΔ; /* coefficient deltas for interpolation */
|
int *hΔ; /* 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 */
|
||||||
Nη = 8,
|
Nη = 8, /* phase bits for filter interpolation */
|
||||||
Np = Nl+Nη,
|
Np = Nl+Nη, /* 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->tΔ = ((uvlong)irate<<Np)/orate;
|
c->tΔ = ((uvlong)irate<<Np)/orate;
|
||||||
c->lΔ = L;
|
c->lΔ = 1<<(Nl+Nη);
|
||||||
|
c->le = nelem(h)<<Nη;
|
||||||
|
c->wx = 1 + (c->le / c->lΔ);
|
||||||
|
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->lΔ *= c->ρ;
|
c->lΔ *= c->ρ;
|
||||||
c->lΔ >>= Np;
|
c->lΔ >>= Np;
|
||||||
|
c->wx *= c->tΔ;
|
||||||
|
c->wx >>= Np;
|
||||||
}
|
}
|
||||||
c->le = nelem(h)<<Nη;
|
|
||||||
c->h = h;
|
|
||||||
if(!init){
|
if(!init){
|
||||||
init = 1;
|
init = 1;
|
||||||
for(n=0; n<nelem(hΔ)-1; n++)
|
for(n=0; n<nelem(hΔ)-1; n++)
|
||||||
hΔ[n] = h[n+1] - h[n];
|
hΔ[n] = h[n+1] - h[n];
|
||||||
}
|
}
|
||||||
|
c->h = h;
|
||||||
c->hΔ = hΔ;
|
c->hΔ = hΔ;
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue