- double *work=alloca((look->ln+look->n)*sizeof(double));
- double amp;
- long bits=0;
-
-#ifdef TRAIN_LSP
- FILE *of;
- FILE *ef;
- char buffer[80];
-
-#if 1
- sprintf(buffer,"lsp0coeff_%d.vqd",vb->mode);
- of=fopen(buffer,"a");
-#endif
-
- sprintf(buffer,"lsp0ent_%d.vqd",vb->mode);
- ef=fopen(buffer,"a");
-#endif
-
- /* our floor comes in on a linear scale; go to a [-Inf...0] dB
- scale. The curve has to be positive, so we offset it. */
-
- for(j=0;j<look->n;j++){
- double val=todB(in[j])+info->ampdB;
- if(val<1.)
- work[j]=1.;
- else
- work[j]=val;
- }
-
- /* use 'out' as temp storage */
- /* Convert our floor to a set of lpc coefficients */
- amp=sqrt(_curve_to_lpc(work,out,look,seq));
-
- /* amp is in the range (0. to ampdB]. Encode that range using
- ampbits bits */
-
- {
- long maxval=(1L<<info->ampbits)-1;
-
- long val=rint(amp/info->ampdB*maxval);
-
- if(val<0)val=0; /* likely */
- if(val>maxval)val=maxval; /* not bloody likely */
-
- _oggpack_write(&vb->opb,val,info->ampbits);
- if(val>0)
- amp=(float)val/maxval*info->ampdB;
- else
- amp=0;
- }
-
- if(amp>0){
-
- /* the spec supports using one of a number of codebooks. Right
- now, encode using this lib supports only one */
- codebook *b=vb->vd->fullbooks+info->books[0];
- _oggpack_write(&vb->opb,0,_ilog(info->numbooks));
-
- /* LSP <-> LPC is orthogonal and LSP quantizes more stably */
- vorbis_lpc_to_lsp(out,out,look->m);
-
-#ifdef ANALYSIS
- if(vb->W==0){fprintf(stderr,"%d ",seq);}
- vorbis_lsp_to_lpc(out,work,look->m);
- _lpc_to_curve(work,work,amp,look,"Ffloor",seq);
- for(j=0;j<look->n;j++)work[j]-=info->ampdB;
- _analysis_output("rawfloor",seq,work,look->n,0,0);
- {
- double last=0;
- for(j=0;j<look->m;j++){
- work[j]=out[j]-last;
- last=out[j];
- }
- }
- _analysis_output("rawlsp",seq,work,look->m,0,0);
-
-#endif
-
-#if 1
-#ifdef TRAIN_LSP
- {
- double last=0.;
- for(j=0;j<look->m;j++){
- fprintf(of,"%.12g, ",out[j]-last);
- last=out[j];
- }
- }
- fprintf(of,"\n");
- fclose(of);
-#endif
-#endif
-
- /* code the spectral envelope, and keep track of the actual
- quantized values; we don't want creeping error as each block is
- nailed to the last quantized value of the previous block. */