It's all coming back together slowly. Incremental update.
[platform/upstream/libvorbis.git] / lib / floor0.c
1 /********************************************************************
2  *                                                                  *
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.                            *
7  *                                                                  *
8  * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000             *
9  * by Monty <monty@xiph.org> and The XIPHOPHORUS Company            *
10  * http://www.xiph.org/                                             *
11  *                                                                  *
12  ********************************************************************
13
14  function: floor backend 0 implementation
15  last mod: $Id: floor0.c,v 1.2 2000/01/22 13:28:19 xiphmont Exp $
16
17  ********************************************************************/
18
19 #include <stdlib.h>
20 #include <string.h>
21 #include "vorbis/codec.h"
22 #include "bitwise.h"
23 #include "registry.h"
24
25 static void pack (vorbis_info_floor *i,oggpack_buffer *opb){
26   vorbis_info_floor0 *d=(vorbis_info_floor0 *)i;
27   int j;
28   _oggpack_write(opb,d->order,8);
29   _oggpack_write(opb,d->rate,16);
30   _oggpack_write(opb,d->barkmap,16);
31   _oggpack_write(opb,d->stages,8);
32   for(j=0;j<d->stages;j++)
33     _oggpack_write(opb,d->books[j],8);
34 }
35
36 static vorbis_info_floor *unpack (vorbis_info *vi,oggpack_buffer *opb){
37   int j;
38   vorbis_info_floor0 *d=malloc(sizeof(vorbis_info_floor0));
39   d->order=_oggpack_read(opb,8);
40   d->rate=_oggpack_read(opb,16);
41   d->barkmap=_oggpack_read(opb,16);
42   d->stages=_oggpack_read(opb,8);
43   
44   if(d->order<1)goto err_out;
45   if(d->rate<1)goto err_out;
46   if(d->barkmap<1)goto err_out;
47   if(d->stages<1)goto err_out;
48
49   d->books=alloca(sizeof(int)*d->stages);
50   for(j=0;j<d->stages;j++){
51     d->books[j]=_oggpack_read(opb,8);
52     if(d->books[j]<0 || d->books[j]>=vi->books)goto err_out;
53   }
54   return(d);  
55  err_out:
56   free_info(d);
57   return(NULL);
58 }
59
60 static vorbis_look_floor *look (vorbis_info *vi,vorbis_info_mode *mi,
61                               vorbis_info_floor *i){
62
63 }
64 static void free_info(vorbis_info_floor *i){
65   vorbis_info_floor0 *d=(vorbis_info_floor0 *)i;
66   if(d){
67     if(d->books)free(d->books);
68     memset(i,0,sizeof(vorbis_info_floor0));
69   }
70 }
71 static void free_look(vorbis_look_floor *i){
72 }
73
74 static void forward(vorbis_block *vb,vorbis_look_floor *i,
75                     double *in,double *out){
76
77
78       /* Convert our floor to a set of lpc coefficients 
79       vb->amp[i]=sqrt(vorbis_curve_to_lpc(floor,lpc,vl));
80
81       LSP <-> LPC is orthogonal and LSP quantizes more stably 
82       vorbis_lpc_to_lsp(lpc,lsp,vl->m);
83
84       code the spectral envelope; mutates the lsp coeffs to reflect
85       what was actually encoded 
86       _vs_spectrum_encode(vb,vb->amp[i],lsp);
87
88       Generate residue from the decoded envelope, which will be
89          slightly different to the pre-encoding floor due to
90          quantization.  Slow, yes, but perhaps more accurate 
91
92       vorbis_lsp_to_lpc(lsp,lpc,vl->m); 
93       vorbis_lpc_to_curve(curve,lpc,vb->amp[i],vl);*/
94   return(0);
95 }
96 static void inverse(vorbis_block *vb,vorbis_look_floor *i,
97                     double *in,double *out){
98   return(0);
99 }
100
101 /* export hooks */
102 vorbis_func_floor floor0_exportbundle={
103   &pack,&unpack,&look,&free_info,&free_look,&forward,&inverse
104 };
105
106