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-2000 *
9 * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: libvorbis codec headers
15 last mod: $Id: codec.h,v 1.12 2000/04/10 00:12:14 xiphmont Exp $
17 ********************************************************************/
19 #ifndef _vorbis_codec_h_
20 #define _vorbis_codec_h_
25 #endif /* __cplusplus */
30 #include <sys/types.h>
31 #include "vorbis/codebook.h"
32 #include "vorbis/internal.h"
34 typedef void vorbis_look_transform;
35 typedef void vorbis_info_time;
36 typedef void vorbis_look_time;
37 typedef void vorbis_info_floor;
38 typedef void vorbis_look_floor;
39 typedef void vorbis_info_residue;
40 typedef void vorbis_look_residue;
41 typedef void vorbis_info_mapping;
42 typedef void vorbis_look_mapping;
44 /* mode ************************************************************/
52 /* psychoacoustic setup ********************************************/
53 typedef struct vorbis_info_psy{
54 double maskthresh[MAX_BARK];
59 /* vorbis_info contains all the setup information specific to the
60 specific compression/decompression mode in progress (eg,
61 psychoacoustic settings, channel setup, options, codebook
63 *********************************************************************/
65 typedef struct vorbis_info{
70 /* The below bitrate declarations are *hints*.
71 Combinations of the three values carry the following implications:
73 all three set to the same value:
74 implies a fixed rate bitstream
76 implies a VBR stream that averages the nominal bitrate. No hard
78 upper and or lower set:
79 implies a VBR bitstream that obeys the bitrate limits. nominal
80 may also be set to give a nominal rate.
82 the coder does not care to speculate.
89 /* Vorbis supports only short and long blocks, but allows the
90 encoder to choose the sizes */
94 /* modes are the primary means of supporting on-the-fly different
95 blocksizes, different channel mappings (LR or mid-side),
96 different residue backends, etc. Each mode consists of a
97 blocksize flag and a mapping (along with the mapping setup */
105 int psys; /* encode only */
107 vorbis_info_mode *mode_param[64];
109 vorbis_info_mapping *map_param[64];
111 vorbis_info_time *time_param[64];
113 vorbis_info_floor *floor_param[64];
114 int residue_type[64];
115 vorbis_info_residue *residue_param[64];
116 static_codebook *book_param[256];
117 vorbis_info_psy *psy_param[64]; /* encode only */
119 /* for block long/sort tuning; encode only */
121 double preecho_thresh;
122 double preecho_clamp;
126 /* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
129 unsigned char *header;
135 /* ogg_stream_state contains the current encode/decode state of a logical
136 Ogg bitstream **********************************************************/
139 unsigned char *body_data; /* bytes from packet bodies */
140 long body_storage; /* storage elements allocated */
141 long body_fill; /* elements stored; fill mark */
142 long body_returned; /* elements of fill returned */
145 int *lacing_vals; /* The values that will go to the segment table */
146 int64_t *pcm_vals; /* pcm_pos values for headers. Not compact
147 this way, but it is simple coupled to the
152 long lacing_returned;
154 unsigned char header[282]; /* working space for header encode */
157 int e_o_s; /* set when we have buffered the last packet in the
159 int b_o_s; /* set after we've written the initial page
160 of a logical bitstream */
163 long packetno; /* sequence number for decode; the framing
164 knows where there's a hole in the data,
165 but we need coupling so that the codec
166 (which is in a seperate abstraction
167 layer) also knows about the gap */
172 /* ogg_packet is used to encapsulate the data and metadata belonging
173 to a single raw Ogg/Vorbis packet *************************************/
176 unsigned char *packet;
182 long packetno; /* sequence number for decode; the framing
183 knows where there's a hole in the data,
184 but we need coupling so that the codec
185 (which is in a seperate abstraction
186 layer) also knows about the gap */
201 /* vorbis_dsp_state buffers the current vorbis audio
202 analysis/synthesis state. The DSP state belongs to a specific
203 logical bitstream ****************************************************/
204 typedef struct vorbis_dsp_state{
216 int envelope_storage;
217 int envelope_current;
234 /* local lookup storage */
236 double **window[2][2][2]; /* block, leadin, leadout, type */
237 vorbis_look_transform **transform[2]; /* block, type */
239 /* backend lookups are tied to the mode, not the backend or naked mapping */
240 vorbis_look_mapping **mode;
242 /* local storage, only used on the encoding side. This way the
243 application does not need to worry about freeing some packets'
244 memory and not others'; packet storage is always tracked.
245 Cleared next call to a _dsp_ function */
252 /* vorbis_block is a single block of data to be processed as part of
253 the analysis/synthesis stream; it belongs to a specific logical
254 bitstream, but is independant from other vorbis_blocks belonging to
255 that logical bitstream. *************************************************/
259 struct alloc_chain *next;
262 typedef struct vorbis_block{
263 /* necessary stream state for linking to the framing abstraction */
264 double **pcm; /* this is a pointer into local storage */
276 vorbis_dsp_state *vd; /* For read-only access of configuration */
278 /* local storage to avoid remallocing; it's up to the mapping to
284 struct alloc_chain *reap;
286 /* bitmetrics for the frame */
294 #include "vorbis/backends.h"
296 /* vorbis_info contains all the setup information specific to the
297 specific compression/decompression mode in progress (eg,
298 psychoacoustic settings, channel setup, options, codebook
299 etc). vorbis_info and substructures are in backends.h.
300 *********************************************************************/
302 /* the comments are not part of vorbis_info so that vorbis_info can be
304 typedef struct vorbis_comment{
305 /* unlimited user comment fields. libvorbis writes 'libvorbis'
306 whatever vendor is set to in encode */
307 char **user_comments;
314 /* libvorbis encodes in two abstraction layers; first we perform DSP
315 and produce a packet (see docs/analysis.txt). The packet is then
316 coded into a framed OggSquish bitstream by the second layer (see
317 docs/framing.txt). Decode is the reverse process; we sync/frame
318 the bitstream and extract individual packets, then decode the
319 packet back into PCM audio.
321 The extra framing/packetizing is used in streaming formats, such as
322 files. Over the net (such as with UDP), the framing and
323 packetization aren't necessary as they're provided by the transport
324 and the streaming layer is not used */
326 /* OggSquish BITSREAM PRIMITIVES: encoding **************************/
328 extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
329 extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
331 /* OggSquish BITSREAM PRIMITIVES: decoding **************************/
333 extern int ogg_sync_init(ogg_sync_state *oy);
334 extern int ogg_sync_clear(ogg_sync_state *oy);
335 extern int ogg_sync_destroy(ogg_sync_state *oy);
336 extern int ogg_sync_reset(ogg_sync_state *oy);
338 extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
339 extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
340 extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
341 extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
342 extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
343 extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
345 /* OggSquish BITSREAM PRIMITIVES: general ***************************/
347 extern int ogg_stream_init(ogg_stream_state *os,int serialno);
348 extern int ogg_stream_clear(ogg_stream_state *os);
349 extern int ogg_stream_reset(ogg_stream_state *os);
350 extern int ogg_stream_destroy(ogg_stream_state *os);
351 extern int ogg_stream_eof(ogg_stream_state *os);
353 extern int ogg_page_version(ogg_page *og);
354 extern int ogg_page_continued(ogg_page *og);
355 extern int ogg_page_bos(ogg_page *og);
356 extern int ogg_page_eos(ogg_page *og);
357 extern int64_t ogg_page_frameno(ogg_page *og);
358 extern int ogg_page_serialno(ogg_page *og);
359 extern int ogg_page_pageno(ogg_page *og);
361 /* Vorbis PRIMITIVES: general ***************************************/
363 extern void vorbis_info_init(vorbis_info *vi);
364 extern void vorbis_info_clear(vorbis_info *vi);
365 extern void vorbis_comment_init(vorbis_comment *vc);
366 extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
367 extern void vorbis_comment_clear(vorbis_comment *vc);
369 extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
370 extern int vorbis_block_clear(vorbis_block *vb);
371 extern void vorbis_dsp_clear(vorbis_dsp_state *v);
373 /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
375 extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
376 extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
380 ogg_packet *op_code);
381 extern double **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
382 extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
383 extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
384 extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
386 /* Vorbis PRIMITIVES: synthesis layer *******************************/
387 extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
390 extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
391 extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
392 extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
393 extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,double ***pcm);
394 extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
399 #endif /* __cplusplus */