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