********************************************************************
function: predefined encoding modes
- last mod: $Id: modes.h,v 1.1 1999/12/31 12:35:11 xiphmont Exp $
+ last mod: $Id: modes.h,v 1.2 2000/01/01 02:52:57 xiphmont Exp $
********************************************************************/
/* dummy, dummy, dummy, dummy */
0, NULL, 0, NULL,
/* smallblock, largeblock, LPC order (small, large) */
- {256, 2048}, {8,22},
+ {256, 2048}, {12,22},
/* {bark mapping size}, spectral channels */
- {32,128}, 2,
+ {64,256}, 2,
/* thresh sample period, preecho clamp trigger threshhold, range, dummy */
64, 4, 2, NULL,
/* noise masking curve dB attenuation levels [20] */
/*{-12,-12,-18,-18,-18,-18,-18,-18,-18,-12,
-8,-4,0,0,0,0,0,0,0,0},*/
{-100,-100,-100,-100,-100,-100,-100,-24,-24,-24,
- -24,-24,-24,-24,-24,-24,-24,-24,-24,-24},
+ -24,-24,-24,-24,-24,-24,-24,-24,-24,-24},
/* noise masking scale biases */
.95,1.01,.01,
/* tone masking curve dB attenuation levels [20] */
********************************************************************
function: linear scale -> bark and mel scales
- last mod: $Id: barkmel.h,v 1.1 1999/12/31 12:35:12 xiphmont Exp $
+ last mod: $Id: barkmel.h,v 1.2 2000/01/01 02:52:58 xiphmont Exp $
********************************************************************/
#define fBARK(f) (13.1*atan(.00074*(f))+2.24*atan((f)*(f)*1.85e-8)+1e-4*(f))
#define iBARK(z) (102.*(z)-2.*pow(z,2.)+.4*pow(z,3)+pow(1.46,z)-1.)
-#define fMEL(f) (1000.*(log(1.+(f)*.001)*1.442695))
+#define fMEL(f) (log(1.+(f)*.001)*1442.695)
+#define iMEL(m) (1000.*exp((m)/1442.695)-1000.)
#endif
********************************************************************
function: LPC low level routines
- last mod: $Id: lpc.c,v 1.11 1999/12/31 12:35:14 xiphmont Exp $
+ last mod: $Id: lpc.c,v 1.12 2000/01/01 02:52:59 xiphmont Exp $
********************************************************************/
The below is authoritative in terms of defining scale mapping.
Note that the scale depends on the sampling rate as well as the
- linear block and mapping sizes (note that for a given sample rate
- and block size, there's generally a fairly obviously optimal
- mapping size */
+ linear block and mapping sizes */
void lpc_init(lpc_lookup *l,int n, long mapped, long rate, int m){
int i;
scale=mapped/fBARK(rate);
/* the mapping from a linear scale to a smaller bark scale is
- straightforward with a single catch; make sure not to skip any
- bark-scale bins. In order to do this, we assign map_N = min
- (map_N-1 + 1, bark(N)) */
+ straightforward. We do *not* make sure that the linear mapping
+ does not skip bark-scale bins; the decoder simply skips them and
+ the encoder may do what it wishes in filling them. They're
+ necessary in some mapping combinations to keep the scale spacing
+ accurate */
{
int last=-1;
for(i=0;i<n;i++){
represent
band edges */
if(val>=mapped)val=mapped; /* guard against the approximation */
- if(val>last+1)val=last+1;
l->linearmap[i]=val;
last=val;
}
frequencies. We figure the weight of bands in proportion to
their linear/bark width ratio below, again, authoritatively. We
use computed width (not the number of actual bins above) for
- smoothness in the scale; they should agree closely unless the
- encoder chose parameters poorly (and got a bark scale that would
- have had lots of skipped bins) */
+ smoothness in the scale; they should agree closely */
for(i=0;i<mapped;i++)
l->barknorm[i]=iBARK((i+1)/scale)-iBARK(i/scale);
int mapped=l->ln;
double *work=alloca(sizeof(double)*mapped);
- int i;
+ int i,j,last=0;
memset(work,0,sizeof(double)*mapped);
we select the maximum value of each band as representative (this
helps make sure peaks don't go out of range. In error terms,
selecting min would make more sense, but the codebook is trained
- numerically, so we don't lose in encoding. We'd still want to
+ numerically, so we don't actually lose. We'd still want to
use the original curve for error and noise estimation */
for(i=0;i<l->n;i++){
int bark=l->linearmap[i];
if(work[bark]<curve[i])work[bark]=curve[i];
+ if(bark>last+1){
+ /* If the bark scale is climbing rapidly, some bins may end up
+ going unused. This isn't a waste actually; it keeps the
+ scale resolution even so that the LPC generator has an easy
+ time. However, if we leave the bins empty we lose energy.
+ So, fill 'em in. The decoder does not do anything witht he
+ unused bins, so we can fill them anyway we like to end up
+ with a better spectral curve */
+
+ /* we'll always have a bin zero, so we don't need to guard init */
+ long span=bark-last;
+ for(j=1;j<span;j++){
+ double del=(double)j/span;
+ work[j+last]=work[bark]*del+work[last]*(1.-del);
+ }
+ }
+ last=bark;
}
for(i=0;i<mapped;i++)work[i]*=l->barknorm[i];