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