Merge branch_beta3 onto the mainline.
[platform/upstream/libvorbis.git] / include / vorbis / codec.h
1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5  * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH    *
6  * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.        *
7  *                                                                  *
8  * THE OggVorbis 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: libvorbis codec headers
15  last mod: $Id: codec.h,v 1.33 2000/11/06 00:06:55 xiphmont Exp $
16
17  ********************************************************************/
18
19 #ifndef _vorbis_codec_h_
20 #define _vorbis_codec_h_
21
22 #ifdef __cplusplus
23 extern "C"
24 {
25 #endif /* __cplusplus */
26
27 #include <ogg/ogg.h>
28
29 typedef struct vorbis_info{
30   int version;
31   int channels;
32   long rate;
33
34   /* The below bitrate declarations are *hints*.
35      Combinations of the three values carry the following implications:
36      
37      all three set to the same value: 
38        implies a fixed rate bitstream
39      only nominal set: 
40        implies a VBR stream that averages the nominal bitrate.  No hard 
41        upper/lower limit
42      upper and or lower set: 
43        implies a VBR bitstream that obeys the bitrate limits. nominal 
44        may also be set to give a nominal rate.
45      none set:
46        the coder does not care to speculate.
47   */
48
49   long bitrate_upper;
50   long bitrate_nominal;
51   long bitrate_lower;
52   long bitrate_window;
53
54   void *codec_setup;
55 } vorbis_info;
56
57 /* vorbis_dsp_state buffers the current vorbis audio
58    analysis/synthesis state.  The DSP state belongs to a specific
59    logical bitstream ****************************************************/
60 typedef struct vorbis_dsp_state{
61   int analysisp;
62   vorbis_info *vi;
63
64   float **pcm;
65   float **pcmret;
66   int      pcm_storage;
67   int      pcm_current;
68   int      pcm_returned;
69
70   int  preextrapolate;
71   int  eofflag;
72
73   long lW;
74   long W;
75   long nW;
76   long centerW;
77
78   ogg_int64_t granulepos;
79   ogg_int64_t sequence;
80
81   ogg_int64_t glue_bits;
82   ogg_int64_t time_bits;
83   ogg_int64_t floor_bits;
84   ogg_int64_t res_bits;
85
86   void       *backend_state;
87 } vorbis_dsp_state;
88
89 typedef struct vorbis_block{
90   /* necessary stream state for linking to the framing abstraction */
91   float  **pcm;       /* this is a pointer into local storage */ 
92   oggpack_buffer opb;
93   
94   long  lW;
95   long  W;
96   long  nW;
97   int   pcmend;
98   int   mode;
99
100   int         eofflag;
101   ogg_int64_t granulepos;
102   ogg_int64_t sequence;
103   vorbis_dsp_state *vd; /* For read-only access of configuration */
104
105   /* local storage to avoid remallocing; it's up to the mapping to
106      structure it */
107   void               *localstore;
108   long                localtop;
109   long                localalloc;
110   long                totaluse;
111   struct alloc_chain *reap;
112
113   /* bitmetrics for the frame */
114   long glue_bits;
115   long time_bits;
116   long floor_bits;
117   long res_bits;
118
119 } vorbis_block;
120
121 /* vorbis_block is a single block of data to be processed as part of
122 the analysis/synthesis stream; it belongs to a specific logical
123 bitstream, but is independant from other vorbis_blocks belonging to
124 that logical bitstream. *************************************************/
125
126 struct alloc_chain{
127   void *ptr;
128   struct alloc_chain *next;
129 };
130
131 /* vorbis_info contains all the setup information specific to the
132    specific compression/decompression mode in progress (eg,
133    psychoacoustic settings, channel setup, options, codebook
134    etc). vorbis_info and substructures are in backends.h.
135 *********************************************************************/
136
137 /* the comments are not part of vorbis_info so that vorbis_info can be
138    static storage */
139 typedef struct vorbis_comment{
140   /* unlimited user comment fields.  libvorbis writes 'libvorbis'
141      whatever vendor is set to in encode */
142   char **user_comments;
143   int   *comment_lengths;
144   int    comments;
145   char  *vendor;
146
147 } vorbis_comment;
148
149
150 /* libvorbis encodes in two abstraction layers; first we perform DSP
151    and produce a packet (see docs/analysis.txt).  The packet is then
152    coded into a framed OggSquish bitstream by the second layer (see
153    docs/framing.txt).  Decode is the reverse process; we sync/frame
154    the bitstream and extract individual packets, then decode the
155    packet back into PCM audio.
156
157    The extra framing/packetizing is used in streaming formats, such as
158    files.  Over the net (such as with UDP), the framing and
159    packetization aren't necessary as they're provided by the transport
160    and the streaming layer is not used */
161
162 /* Vorbis PRIMITIVES: general ***************************************/
163
164 extern void     vorbis_info_init(vorbis_info *vi);
165 extern void     vorbis_info_clear(vorbis_info *vi);
166 extern void     vorbis_comment_init(vorbis_comment *vc);
167 extern void     vorbis_comment_add(vorbis_comment *vc, char *comment); 
168 extern void     vorbis_comment_add_tag(vorbis_comment *vc, 
169                                        char *tag, char *contents);
170 extern char    *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
171 extern int      vorbis_comment_query_count(vorbis_comment *vc, char *tag);
172 extern void     vorbis_comment_clear(vorbis_comment *vc);
173
174 extern int      vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
175 extern int      vorbis_block_clear(vorbis_block *vb);
176 extern void     vorbis_dsp_clear(vorbis_dsp_state *v);
177
178 /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
179
180 extern int      vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
181 extern int      vorbis_analysis_headerout(vorbis_dsp_state *v,
182                                           vorbis_comment *vc,
183                                           ogg_packet *op,
184                                           ogg_packet *op_comm,
185                                           ogg_packet *op_code);
186 extern float  **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
187 extern int      vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
188 extern int      vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
189 extern int      vorbis_analysis(vorbis_block *vb,ogg_packet *op);
190
191 /* Vorbis PRIMITIVES: synthesis layer *******************************/
192 extern int      vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
193                                           ogg_packet *op);
194
195 extern int      vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
196 extern int      vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
197 extern int      vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
198 extern int      vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
199 extern int      vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
200
201 /* Vorbis ERRORS and return codes ***********************************/
202
203 #define OV_FALSE      -1  
204 #define OV_EOF        -2
205 #define OV_HOLE       -3
206
207 #define OV_EREAD      -128
208 #define OV_EFAULT     -129
209 #define OV_EIMPL      -130
210 #define OV_EINVAL     -131
211 #define OV_ENOTVORBIS -132
212 #define OV_EBADHEADER -133
213 #define OV_EVERSION   -134
214 #define OV_ENOTAUDIO  -135
215 #define OV_EBADPACKET -136
216 #define OV_EBADLINK   -137
217 #define OV_ENOSEEK    -138
218
219 #ifdef __cplusplus
220 }
221 #endif /* __cplusplus */
222
223 #endif
224