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.27 2000/08/23 10:27:14 xiphmont Exp $
17 ********************************************************************/
19 #ifndef _vorbis_codec_h_
20 #define _vorbis_codec_h_
25 #endif /* __cplusplus */
29 #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_echstate_floor;
40 typedef void vorbis_info_residue;
41 typedef void vorbis_look_residue;
42 typedef void vorbis_info_mapping;
43 typedef void vorbis_look_mapping;
45 /* mode ************************************************************/
53 /* psychoacoustic setup ********************************************/
56 typedef struct vorbis_info_psy{
62 double noisecull_barkwidth;
67 /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 */
68 /* x: 63 88 125 175 250 350 500 700 1k 1.4k 2k 2.8k 4k 5.6k 8k 11.5k 16k Hz */
69 /* y: 0 10 20 30 40 50 60 70 80 90 100 dB */
72 double toneatt[P_BANDS][P_LEVELS];
75 double peakatt[P_BANDS][P_LEVELS];
78 double noiseatt[P_BANDS][P_LEVELS];
87 /* vorbis_info contains all the setup information specific to the
88 specific compression/decompression mode in progress (eg,
89 psychoacoustic settings, channel setup, options, codebook
91 *********************************************************************/
93 typedef struct vorbis_info{
98 /* The below bitrate declarations are *hints*.
99 Combinations of the three values carry the following implications:
101 all three set to the same value:
102 implies a fixed rate bitstream
104 implies a VBR stream that averages the nominal bitrate. No hard
106 upper and or lower set:
107 implies a VBR bitstream that obeys the bitrate limits. nominal
108 may also be set to give a nominal rate.
110 the coder does not care to speculate.
114 long bitrate_nominal;
117 /* Vorbis supports only short and long blocks, but allows the
118 encoder to choose the sizes */
122 /* modes are the primary means of supporting on-the-fly different
123 blocksizes, different channel mappings (LR or mid-side),
124 different residue backends, etc. Each mode consists of a
125 blocksize flag and a mapping (along with the mapping setup */
133 int psys; /* encode only */
135 vorbis_info_mode *mode_param[64];
137 vorbis_info_mapping *map_param[64];
139 vorbis_info_time *time_param[64];
141 vorbis_info_floor *floor_param[64];
142 int residue_type[64];
143 vorbis_info_residue *residue_param[64];
144 static_codebook *book_param[256];
145 vorbis_info_psy *psy_param[64]; /* encode only */
147 /* for block long/sort tuning; encode only */
149 double preecho_thresh;
150 double preecho_clamp;
151 double preecho_minenergy;
154 /* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
157 unsigned char *header;
163 /* ogg_stream_state contains the current encode/decode state of a logical
164 Ogg bitstream **********************************************************/
167 unsigned char *body_data; /* bytes from packet bodies */
168 long body_storage; /* storage elements allocated */
169 long body_fill; /* elements stored; fill mark */
170 long body_returned; /* elements of fill returned */
173 int *lacing_vals; /* The values that will go to the segment table */
174 int64_t *pcm_vals; /* pcm_pos values for headers. Not compact
175 this way, but it is simple coupled to the
180 long lacing_returned;
182 unsigned char header[282]; /* working space for header encode */
185 int e_o_s; /* set when we have buffered the last packet in the
187 int b_o_s; /* set after we've written the initial page
188 of a logical bitstream */
191 int64_t packetno; /* sequence number for decode; the framing
192 knows where there's a hole in the data,
193 but we need coupling so that the codec
194 (which is in a seperate abstraction
195 layer) also knows about the gap */
200 /* ogg_packet is used to encapsulate the data and metadata belonging
201 to a single raw Ogg/Vorbis packet *************************************/
204 unsigned char *packet;
210 int64_t packetno; /* sequence number for decode; the framing
211 knows where there's a hole in the data,
212 but we need coupling so that the codec
213 (which is in a seperate abstraction
214 layer) also knows about the gap */
229 /* vorbis_dsp_state buffers the current vorbis audio
230 analysis/synthesis state. The DSP state belongs to a specific
231 logical bitstream ****************************************************/
232 typedef struct vorbis_dsp_state{
259 /* local lookup storage */
260 void *ve; /* envelope lookup */
261 double **window[2][2][2]; /* block, leadin, leadout, type */
262 vorbis_look_transform **transform[2]; /* block, type */
264 /* backend lookups are tied to the mode, not the backend or naked mapping */
265 vorbis_look_mapping **mode;
267 /* local storage, only used on the encoding side. This way the
268 application does not need to worry about freeing some packets'
269 memory and not others'; packet storage is always tracked.
270 Cleared next call to a _dsp_ function */
271 unsigned char *header;
272 unsigned char *header1;
273 unsigned char *header2;
277 /* vorbis_block is a single block of data to be processed as part of
278 the analysis/synthesis stream; it belongs to a specific logical
279 bitstream, but is independant from other vorbis_blocks belonging to
280 that logical bitstream. *************************************************/
284 struct alloc_chain *next;
287 typedef struct vorbis_block{
288 /* necessary stream state for linking to the framing abstraction */
289 double **pcm; /* this is a pointer into local storage */
301 vorbis_dsp_state *vd; /* For read-only access of configuration */
303 /* local storage to avoid remallocing; it's up to the mapping to
309 struct alloc_chain *reap;
311 /* bitmetrics for the frame */
319 #include "vorbis/backends.h"
321 /* vorbis_info contains all the setup information specific to the
322 specific compression/decompression mode in progress (eg,
323 psychoacoustic settings, channel setup, options, codebook
324 etc). vorbis_info and substructures are in backends.h.
325 *********************************************************************/
327 /* the comments are not part of vorbis_info so that vorbis_info can be
329 typedef struct vorbis_comment{
330 /* unlimited user comment fields. libvorbis writes 'libvorbis'
331 whatever vendor is set to in encode */
332 char **user_comments;
333 int *comment_lengths;
340 /* libvorbis encodes in two abstraction layers; first we perform DSP
341 and produce a packet (see docs/analysis.txt). The packet is then
342 coded into a framed OggSquish bitstream by the second layer (see
343 docs/framing.txt). Decode is the reverse process; we sync/frame
344 the bitstream and extract individual packets, then decode the
345 packet back into PCM audio.
347 The extra framing/packetizing is used in streaming formats, such as
348 files. Over the net (such as with UDP), the framing and
349 packetization aren't necessary as they're provided by the transport
350 and the streaming layer is not used */
352 /* OggSquish BITSREAM PRIMITIVES: encoding **************************/
354 extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
355 extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
356 extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
358 /* OggSquish BITSREAM PRIMITIVES: decoding **************************/
360 extern int ogg_sync_init(ogg_sync_state *oy);
361 extern int ogg_sync_clear(ogg_sync_state *oy);
362 extern int ogg_sync_destroy(ogg_sync_state *oy);
363 extern int ogg_sync_reset(ogg_sync_state *oy);
365 extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
366 extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
367 extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
368 extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
369 extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
370 extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
372 /* OggSquish BITSREAM PRIMITIVES: general ***************************/
374 extern int ogg_stream_init(ogg_stream_state *os,int serialno);
375 extern int ogg_stream_clear(ogg_stream_state *os);
376 extern int ogg_stream_reset(ogg_stream_state *os);
377 extern int ogg_stream_destroy(ogg_stream_state *os);
378 extern int ogg_stream_eof(ogg_stream_state *os);
380 extern int ogg_page_version(ogg_page *og);
381 extern int ogg_page_continued(ogg_page *og);
382 extern int ogg_page_bos(ogg_page *og);
383 extern int ogg_page_eos(ogg_page *og);
384 extern int64_t ogg_page_frameno(ogg_page *og);
385 extern int ogg_page_serialno(ogg_page *og);
386 extern int ogg_page_pageno(ogg_page *og);
388 /* Vorbis PRIMITIVES: general ***************************************/
390 extern void vorbis_info_init(vorbis_info *vi);
391 extern void vorbis_info_clear(vorbis_info *vi);
392 extern void vorbis_comment_init(vorbis_comment *vc);
393 extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
394 extern void vorbis_comment_add_tag(vorbis_comment *vc,
395 char *tag, char *contents);
396 extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
397 extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
398 extern void vorbis_comment_clear(vorbis_comment *vc);
400 extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
401 extern int vorbis_block_clear(vorbis_block *vb);
402 extern void vorbis_dsp_clear(vorbis_dsp_state *v);
404 /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
406 extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
407 extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
411 ogg_packet *op_code);
412 extern double **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
413 extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
414 extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
415 extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
417 /* Vorbis PRIMITIVES: synthesis layer *******************************/
418 extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
421 extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
422 extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
423 extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
424 extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,double ***pcm);
425 extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
429 #endif /* __cplusplus */