Envelope infrastructure now in place. Basic preecho running (but
[platform/upstream/libvorbis.git] / lib / codec.h
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-1999             *
9  * by 1999 Monty <monty@xiph.org> and The XIPHOPHORUS Company       *
10  * http://www.xiph.org/                                             *
11  *                                                                  *
12  ********************************************************************
13
14  function: codec headers
15  author: Monty <xiphmont@mit.edu>
16  modifications by: Monty
17  last modification date: Jul 28 1999
18
19  ********************************************************************/
20
21 #ifndef _vorbis_codec_h_
22 #define _vorbis_codec_h_
23
24 typedef struct {
25   long endbyte;     
26   int  endbit;      
27
28   unsigned char *buffer;
29   unsigned char *ptr;
30   long storage;
31   
32 } oggpack_buffer;
33
34 typedef struct vorbis_info{
35   int channels;
36   int rate;
37   int version;
38   int mode;
39   char **user_comments;
40   char *vendor;
41
42   int smallblock;
43   int largeblock;
44   int envelopesa;
45   int envelopech;
46   int *envelopemap; /* which envelope applies to what pcm channel */
47   int **channelmap; /* which encoding channels produce what pcm */
48
49   double preecho_thresh;
50   double preecho_clamp;
51 } vorbis_info;
52  
53 typedef struct {
54   unsigned char *header;
55   long header_len;
56   unsigned char *body;
57   long body_len;
58 } ogg_page;
59
60 typedef struct {
61   unsigned char   *body_data;    /* bytes from packet bodies */
62   long    body_storage;          /* storage elements allocated */
63   long    body_fill;             /* elements stored; fill mark */
64   long    body_returned;         /* elements of fill returned */
65
66
67   int    *lacing_vals;    /* The values that will go to the segment table */
68   size64 *pcm_vals;       /* pcm_pos values for headers. Not compact
69                              this way, but it is simple coupled to the
70                              lacing fifo */
71   long    lacing_storage;
72   long    lacing_fill;
73   long    lacing_packet;
74   long    lacing_returned;
75
76   unsigned char    header[282];      /* working space for header encode */
77   int              header_fill;
78
79   int     e_o_s;          /* set when we have buffered the last packet in the
80                              logical bitstream */
81   int     b_o_s;          /* set after we've written the initial page
82                              of a logical bitstream */
83   long    serialno;
84   long    pageno;
85   size64  pcmpos;
86
87 } ogg_stream_state;
88
89 typedef struct {
90   unsigned char *packet;
91   long  bytes;
92   long  b_o_s;
93   long  e_o_s;
94
95   size64 frameno;
96
97 } ogg_packet;
98
99 typedef struct {
100   unsigned char *data;
101   int storage;
102   int fill;
103   int returned;
104
105   int unsynced;
106   int headerbytes;
107   int bodybytes;
108 } ogg_sync_state;
109
110 typedef struct {
111   int winlen;
112   double *window;
113 } envelope_lookup;
114
115 typedef struct vorbis_dsp_state{
116   int samples_per_envelope_step;
117   int block_size[2];
118   double *window[2][2][2]; /* windowsize, leadin, leadout */
119
120   envelope_lookup ve;
121   vorbis_info vi;
122
123   double **pcm;
124   double **pcmret;
125   int      pcm_storage;
126   int      pcm_channels;
127   int      pcm_current;
128   int      pcm_returned;
129
130   double **multipliers;
131   int      envelope_storage;
132   int      envelope_channels;
133   int      envelope_current;
134
135   int  eofflag;
136
137   long lW;
138   long W;
139   long nW;
140   long centerW;
141
142   long frame;
143   long samples;
144
145 } vorbis_dsp_state;
146
147 typedef struct vorbis_block{
148   double **pcm;
149   double **mult;
150   int    pcm_channels; /* allocated, not used */
151   int    pcm_storage;  /* allocated, not used */
152   int    mult_channels; /* allocated, not used */
153   int    mult_storage;  /* allocated, not used */
154
155   long  lW;
156   long  W;
157   long  nW;
158   int   pcmend;
159   int   multend;
160
161   int eofflag;
162   int frameno;
163   vorbis_dsp_state *vd; /* For read-only access of configuration */
164 } vorbis_block;
165
166 /* libvorbis encodes in two abstraction layers; first we perform DSP
167    and produce a packet (see docs/analysis.txt).  The packet is then
168    coded into a framed OggSquish bitstream by the second layer (see
169    docs/framing.txt).  Decode is the reverse process; we sync/frame
170    the bitstream and extract individual packets, then decode the
171    packet back into PCM audio.
172
173    The extra framing/packetizing is used in streaming formats, such as
174    files.  Over the net (such as with UDP), the framing and
175    packetization aren't necessary as they're provided by the transport
176    and the streaming layer is not used */
177
178 /* OggSquish BITSREAM PRIMITIVES: encoding **************************/
179
180 extern int    ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
181 extern int    ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
182
183 /* OggSquish BITSREAM PRIMITIVES: decoding **************************/
184
185 extern int    ogg_sync_init(ogg_sync_state *oy);
186 extern int    ogg_sync_clear(ogg_sync_state *oy);
187 extern int    ogg_sync_destroy(ogg_sync_state *oy);
188 extern int    ogg_sync_reset(ogg_sync_state *oy);
189
190 extern char  *ogg_sync_buffer(ogg_sync_state *oy, long size);
191 extern int    ogg_sync_wrote(ogg_sync_state *oy, long bytes);
192 extern int    ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
193 extern int    ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
194 extern int    ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
195
196 /* OggSquish BITSREAM PRIMITIVES: general ***************************/
197
198 extern int    ogg_stream_init(ogg_stream_state *os,int serialno);
199 extern int    ogg_stream_clear(ogg_stream_state *os);
200 extern int    ogg_stream_reset(ogg_stream_state *os);
201 extern int    ogg_stream_destroy(ogg_stream_state *os);
202 extern int    ogg_stream_eof(ogg_stream_state *os);
203
204 extern int    ogg_page_version(ogg_page *og);
205 extern int    ogg_page_continued(ogg_page *og);
206 extern int    ogg_page_bos(ogg_page *og);
207 extern int    ogg_page_eos(ogg_page *og);
208 extern size64 ogg_page_frameno(ogg_page *og);
209 extern int    ogg_page_serialno(ogg_page *og);
210 extern int    ogg_page_pageno(ogg_page *og);
211
212 /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
213
214 extern int      vorbis_analysis_init(vorbis_dsp_state *vd,vorbis_info *vi);
215 extern int      vorbis_analysis_reset(vorbis_dsp_state *vd);
216 extern void     vorbis_analysis_free(vorbis_dsp_state *vd);
217 extern double **vorbis_analysis_buffer(vorbis_dsp_state *vd,int vals);
218 extern int      vorbis_analysis_wrote(vorbis_dsp_state *vd,int vals);
219 extern int      vorbis_analysis_blockout(vorbis_dsp_state *vd,
220                                          vorbis_block *vb);
221 extern int      vorbis_analysis_packetout(vorbis_dsp_state *vd,
222                                           vorbis_block *vb,
223                                           ogg_packet *op);
224
225 /* Vorbis PRIMITIVES: synthesis layer *******************************/
226
227 extern void vorbis_synthesis_free(vorbis_dsp_state *vd);
228 extern int  vorbis_synthesis_init(vorbis_dsp_state *vd,vorbis_info *vi);
229
230 extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
231 extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,double ***pcm);
232 extern int vorbis_synthesis_read(vorbis_dsp_state *v,int bytes);
233
234
235
236 #endif
237