1 /********************************************************************
3 * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS DISTRIBUTING. *
8 * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-1999 *
9 * by 1999 Monty <monty@xiph.org> and The XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: spectrum envelope and residue code/decode
15 author: Monty <xiphmont@mit.edu>
16 modifications by: Monty
17 last modification date: Oct 17 1999
19 ********************************************************************/
27 /* this code is still seriously abbreviated. I'm filling in pieces as
28 we go... --Monty 19991004 */
30 /* unlike other LPC-based coders, we never apply the filter, only
31 inspect the frequency response, thus we don't need to guard against
32 instability. However, two coefficients quantising to the same
33 value will cause the response to explode. */
35 int _vs_spectrum_encode(vorbis_block *vb,double amp,double *lsp){
36 /* no real coding yet. Just write out full sized words for now
37 because people need bitstreams to work with */
40 int m=vb->vd->vi->floororder[scale];
46 int bits=rint(log(n)/log(2));
49 _oggpack_write(&vb->opb,amp*327680,18);
52 int val=rint(lsp[i]/M_PI*n-last);
53 _oggpack_write(&vb->opb,val,bits);
54 lsp[i]=(last+=val)*M_PI/n;
56 /* Underpowered but sufficient */
57 if(lsp[i]<dlast+min)lsp[i]=dlast+min;
63 int _vs_spectrum_decode(vorbis_block *vb,double *amp,double *lsp){
65 int m=vb->vd->vi->floororder[scale];
69 int bits=rint(log(n)/log(2));
73 *amp=_oggpack_read(&vb->opb,18)/327680.;
76 int val=_oggpack_read(&vb->opb,bits);
77 lsp[i]=(last+=val)*M_PI/n;
78 /* Underpowered but sufficient */
79 if(lsp[i]<dlast+min)lsp[i]=dlast+min;
86 void _vs_residue_quantize(double *data,double *curve,
87 vorbis_info *vi,int n){
89 /* The following is temporary, hardwired bullshit */
94 int val=rint(data[i]/curve[i]);
98 if(val==0 || val==2 || val==-2){
114 int _vs_residue_encode(vorbis_block *vb,double *data){
115 /* no real coding yet. Just write out full sized words for now
116 because people need bitstreams to work with */
122 _oggpack_write(&vb->opb,(int)(data[i]+16),6);
128 int _vs_residue_decode(vorbis_block *vb,double *data){
129 /* no real coding yet. Just write out full sized words for now
130 because people need bitstreams to work with */
136 data[i]=_oggpack_read(&vb->opb,6)-16;
137 /*if(data[i]>=0)data[i]+=1;*/