cannam@87: /******************************************************************** cannam@87: * * cannam@87: * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * cannam@87: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * cannam@87: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * cannam@87: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * cannam@87: * * cannam@87: * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 * cannam@87: * by the Xiph.Org Foundation http://www.xiph.org/ * cannam@87: cannam@87: ******************************************************************** cannam@87: cannam@87: function: libvorbis codec headers cannam@87: last mod: $Id: codec.h 17021 2010-03-24 09:29:41Z xiphmont $ cannam@87: cannam@87: ********************************************************************/ cannam@87: cannam@87: #ifndef _vorbis_codec_h_ cannam@87: #define _vorbis_codec_h_ cannam@87: cannam@87: #ifdef __cplusplus cannam@87: extern "C" cannam@87: { cannam@87: #endif /* __cplusplus */ cannam@87: cannam@87: #include cannam@87: cannam@87: typedef struct vorbis_info{ cannam@87: int version; cannam@87: int channels; cannam@87: long rate; cannam@87: cannam@87: /* The below bitrate declarations are *hints*. cannam@87: Combinations of the three values carry the following implications: cannam@87: cannam@87: all three set to the same value: cannam@87: implies a fixed rate bitstream cannam@87: only nominal set: cannam@87: implies a VBR stream that averages the nominal bitrate. No hard cannam@87: upper/lower limit cannam@87: upper and or lower set: cannam@87: implies a VBR bitstream that obeys the bitrate limits. nominal cannam@87: may also be set to give a nominal rate. cannam@87: none set: cannam@87: the coder does not care to speculate. cannam@87: */ cannam@87: cannam@87: long bitrate_upper; cannam@87: long bitrate_nominal; cannam@87: long bitrate_lower; cannam@87: long bitrate_window; cannam@87: cannam@87: void *codec_setup; cannam@87: } vorbis_info; cannam@87: cannam@87: /* vorbis_dsp_state buffers the current vorbis audio cannam@87: analysis/synthesis state. The DSP state belongs to a specific cannam@87: logical bitstream ****************************************************/ cannam@87: typedef struct vorbis_dsp_state{ cannam@87: int analysisp; cannam@87: vorbis_info *vi; cannam@87: cannam@87: float **pcm; cannam@87: float **pcmret; cannam@87: int pcm_storage; cannam@87: int pcm_current; cannam@87: int pcm_returned; cannam@87: cannam@87: int preextrapolate; cannam@87: int eofflag; cannam@87: cannam@87: long lW; cannam@87: long W; cannam@87: long nW; cannam@87: long centerW; cannam@87: cannam@87: ogg_int64_t granulepos; cannam@87: ogg_int64_t sequence; cannam@87: cannam@87: ogg_int64_t glue_bits; cannam@87: ogg_int64_t time_bits; cannam@87: ogg_int64_t floor_bits; cannam@87: ogg_int64_t res_bits; cannam@87: cannam@87: void *backend_state; cannam@87: } vorbis_dsp_state; cannam@87: cannam@87: typedef struct vorbis_block{ cannam@87: /* necessary stream state for linking to the framing abstraction */ cannam@87: float **pcm; /* this is a pointer into local storage */ cannam@87: oggpack_buffer opb; cannam@87: cannam@87: long lW; cannam@87: long W; cannam@87: long nW; cannam@87: int pcmend; cannam@87: int mode; cannam@87: cannam@87: int eofflag; cannam@87: ogg_int64_t granulepos; cannam@87: ogg_int64_t sequence; cannam@87: vorbis_dsp_state *vd; /* For read-only access of configuration */ cannam@87: cannam@87: /* local storage to avoid remallocing; it's up to the mapping to cannam@87: structure it */ cannam@87: void *localstore; cannam@87: long localtop; cannam@87: long localalloc; cannam@87: long totaluse; cannam@87: struct alloc_chain *reap; cannam@87: cannam@87: /* bitmetrics for the frame */ cannam@87: long glue_bits; cannam@87: long time_bits; cannam@87: long floor_bits; cannam@87: long res_bits; cannam@87: cannam@87: void *internal; cannam@87: cannam@87: } vorbis_block; cannam@87: cannam@87: /* vorbis_block is a single block of data to be processed as part of cannam@87: the analysis/synthesis stream; it belongs to a specific logical cannam@87: bitstream, but is independent from other vorbis_blocks belonging to cannam@87: that logical bitstream. *************************************************/ cannam@87: cannam@87: struct alloc_chain{ cannam@87: void *ptr; cannam@87: struct alloc_chain *next; cannam@87: }; cannam@87: cannam@87: /* vorbis_info contains all the setup information specific to the cannam@87: specific compression/decompression mode in progress (eg, cannam@87: psychoacoustic settings, channel setup, options, codebook cannam@87: etc). vorbis_info and substructures are in backends.h. cannam@87: *********************************************************************/ cannam@87: cannam@87: /* the comments are not part of vorbis_info so that vorbis_info can be cannam@87: static storage */ cannam@87: typedef struct vorbis_comment{ cannam@87: /* unlimited user comment fields. libvorbis writes 'libvorbis' cannam@87: whatever vendor is set to in encode */ cannam@87: char **user_comments; cannam@87: int *comment_lengths; cannam@87: int comments; cannam@87: char *vendor; cannam@87: cannam@87: } vorbis_comment; cannam@87: cannam@87: cannam@87: /* libvorbis encodes in two abstraction layers; first we perform DSP cannam@87: and produce a packet (see docs/analysis.txt). The packet is then cannam@87: coded into a framed OggSquish bitstream by the second layer (see cannam@87: docs/framing.txt). Decode is the reverse process; we sync/frame cannam@87: the bitstream and extract individual packets, then decode the cannam@87: packet back into PCM audio. cannam@87: cannam@87: The extra framing/packetizing is used in streaming formats, such as cannam@87: files. Over the net (such as with UDP), the framing and cannam@87: packetization aren't necessary as they're provided by the transport cannam@87: and the streaming layer is not used */ cannam@87: cannam@87: /* Vorbis PRIMITIVES: general ***************************************/ cannam@87: cannam@87: extern void vorbis_info_init(vorbis_info *vi); cannam@87: extern void vorbis_info_clear(vorbis_info *vi); cannam@87: extern int vorbis_info_blocksize(vorbis_info *vi,int zo); cannam@87: extern void vorbis_comment_init(vorbis_comment *vc); cannam@87: extern void vorbis_comment_add(vorbis_comment *vc, const char *comment); cannam@87: extern void vorbis_comment_add_tag(vorbis_comment *vc, cannam@87: const char *tag, const char *contents); cannam@87: extern char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count); cannam@87: extern int vorbis_comment_query_count(vorbis_comment *vc, const char *tag); cannam@87: extern void vorbis_comment_clear(vorbis_comment *vc); cannam@87: cannam@87: extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb); cannam@87: extern int vorbis_block_clear(vorbis_block *vb); cannam@87: extern void vorbis_dsp_clear(vorbis_dsp_state *v); cannam@87: extern double vorbis_granule_time(vorbis_dsp_state *v, cannam@87: ogg_int64_t granulepos); cannam@87: cannam@87: extern const char *vorbis_version_string(void); cannam@87: cannam@87: /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/ cannam@87: cannam@87: extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi); cannam@87: extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op); cannam@87: extern int vorbis_analysis_headerout(vorbis_dsp_state *v, cannam@87: vorbis_comment *vc, cannam@87: ogg_packet *op, cannam@87: ogg_packet *op_comm, cannam@87: ogg_packet *op_code); cannam@87: extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals); cannam@87: extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals); cannam@87: extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb); cannam@87: extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op); cannam@87: cannam@87: extern int vorbis_bitrate_addblock(vorbis_block *vb); cannam@87: extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, cannam@87: ogg_packet *op); cannam@87: cannam@87: /* Vorbis PRIMITIVES: synthesis layer *******************************/ cannam@87: extern int vorbis_synthesis_idheader(ogg_packet *op); cannam@87: extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc, cannam@87: ogg_packet *op); cannam@87: cannam@87: extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi); cannam@87: extern int vorbis_synthesis_restart(vorbis_dsp_state *v); cannam@87: extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op); cannam@87: extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op); cannam@87: extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb); cannam@87: extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm); cannam@87: extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm); cannam@87: extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples); cannam@87: extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op); cannam@87: cannam@87: extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag); cannam@87: extern int vorbis_synthesis_halfrate_p(vorbis_info *v); cannam@87: cannam@87: /* Vorbis ERRORS and return codes ***********************************/ cannam@87: cannam@87: #define OV_FALSE -1 cannam@87: #define OV_EOF -2 cannam@87: #define OV_HOLE -3 cannam@87: cannam@87: #define OV_EREAD -128 cannam@87: #define OV_EFAULT -129 cannam@87: #define OV_EIMPL -130 cannam@87: #define OV_EINVAL -131 cannam@87: #define OV_ENOTVORBIS -132 cannam@87: #define OV_EBADHEADER -133 cannam@87: #define OV_EVERSION -134 cannam@87: #define OV_ENOTAUDIO -135 cannam@87: #define OV_EBADPACKET -136 cannam@87: #define OV_EBADLINK -137 cannam@87: #define OV_ENOSEEK -138 cannam@87: cannam@87: #ifdef __cplusplus cannam@87: } cannam@87: #endif /* __cplusplus */ cannam@87: cannam@87: #endif cannam@87: