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