- scale=look->ln/toBARK(info->rate/2.);
-
- /* the mapping from a linear scale to a smaller bark scale is
- 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 */
- look->linearmap=malloc(look->n*sizeof(int));
- for(j=0;j<look->n;j++){
- int val=floor( toBARK((info->rate/2.)/look->n*j)
- *scale); /* bark numbers represent band edges */
- if(val>look->ln)val=look->ln; /* guard against the approximation */
- look->linearmap[j]=val;
- }
- return look;
-}
-
-static vorbis_echstate_floor *state (vorbis_info_floor *i){
- vorbis_echstate_floor0 *state=calloc(1,sizeof(vorbis_echstate_floor0));
- vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
-
- /* a safe size if usually too big (dim==1) */
- state->codewords=malloc(info->order*sizeof(long));
- state->curve=malloc(info->barkmap*sizeof(double));
- state->frameno=-1;
- return(state);
-}
-
-static void free_state (vorbis_echstate_floor *vs){
- vorbis_echstate_floor0 *state=(vorbis_echstate_floor0 *)vs;
- if(state){
- free(state->codewords);
- free(state->curve);
- memset(state,0,sizeof(vorbis_echstate_floor0));
- free(state);
- }
-}
-
-#include <stdio.h>
-
-double _curve_error(double *curve1,double *curve2,long n){
- double acc=0.;
- long i;
- for(i=0;i<n;i++){
- double val=curve1[i]-curve2[i];
- acc+=val*val;
- }
- return(acc);
-}
-
-/* less efficient than the decode side (written for clarity). We're
- not bottlenecked here anyway */
-
-double _curve_to_lpc(double *curve,double *lpc,
- vorbis_look_floor0 *l,long frameno){
- /* map the input curve to a bark-scale curve for encoding */
-
- int mapped=l->ln;
- double *work=alloca(sizeof(double)*mapped);
- int i,j,last=0;
- int bark=0;
-
- memset(work,0,sizeof(double)*mapped);
-
- /* Only the decode side is behavior-specced; for now in the encoder,
- 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 actually lose. We'd still want to
- use the original curve for error and noise estimation */
-
- for(i=0;i<l->n;i++){
- 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 with 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);
- }
+ float scale=look->ln/toBARK(info->rate/2.f);
+
+ /* the mapping from a linear scale to a smaller bark scale is
+ 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 */
+ look->linearmap[W]=_ogg_malloc((n+1)*sizeof(**look->linearmap));
+ for(j=0;j<n;j++){
+ int val=floor( toBARK((info->rate/2.f)/n*j)
+ *scale); /* bark numbers represent band edges */
+ if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
+ look->linearmap[W][j]=val;