home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 2002 January / STC_CD_01_2002.iso / APP / ANIPL218 / PROG / SLB / VORBIS / CODEC.H next >
C/C++ Source or Header  |  2001-11-24  |  7KB  |  228 lines

  1. /********************************************************************
  2.  *                                                                  *
  3.  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
  4.  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
  5.  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6.  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  7.  *                                                                  *
  8.  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
  9.  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  10.  
  11.  ********************************************************************
  12.  
  13.  function: libvorbis codec headers
  14.  last mod: $Id: codec.h,v 1.38 2001/05/27 06:43:59 xiphmont Exp $
  15.  
  16.  ********************************************************************/
  17.  
  18. #ifndef _vorbis_codec_h_
  19. #define _vorbis_codec_h_
  20.  
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif /* __cplusplus */
  25.  
  26. #include <ogg/ogg.h>
  27.  
  28. typedef struct vorbis_info{
  29.   int version;
  30.   int channels;
  31.   long rate;
  32.  
  33.   /* The below bitrate declarations are *hints*.
  34.      Combinations of the three values carry the following implications:
  35.      
  36.      all three set to the same value: 
  37.        implies a fixed rate bitstream
  38.      only nominal set: 
  39.        implies a VBR stream that averages the nominal bitrate.  No hard 
  40.        upper/lower limit
  41.      upper and or lower set: 
  42.        implies a VBR bitstream that obeys the bitrate limits. nominal 
  43.        may also be set to give a nominal rate.
  44.      none set:
  45.        the coder does not care to speculate.
  46.   */
  47.  
  48.   long bitrate_upper;
  49.   long bitrate_nominal;
  50.   long bitrate_lower;
  51.   long bitrate_window;
  52.  
  53.   void *codec_setup;
  54. } vorbis_info;
  55.  
  56. /* vorbis_dsp_state buffers the current vorbis audio
  57.    analysis/synthesis state.  The DSP state belongs to a specific
  58.    logical bitstream ****************************************************/
  59. typedef struct vorbis_dsp_state{
  60.   int analysisp;
  61.   vorbis_info *vi;
  62.  
  63.   float **pcm;
  64.   float **pcmret;
  65.   int      pcm_storage;
  66.   int      pcm_current;
  67.   int      pcm_returned;
  68.  
  69.   int  preextrapolate;
  70.   int  eofflag;
  71.  
  72.   long lW;
  73.   long W;
  74.   long nW;
  75.   long centerW;
  76.  
  77.   ogg_int64_t granulepos;
  78.   ogg_int64_t sequence;
  79.  
  80.   ogg_int64_t glue_bits;
  81.   ogg_int64_t time_bits;
  82.   ogg_int64_t floor_bits;
  83.   ogg_int64_t res_bits;
  84.  
  85.   void       *backend_state;
  86. } vorbis_dsp_state;
  87.  
  88. typedef struct vorbis_block{
  89.   /* necessary stream state for linking to the framing abstraction */
  90.   float  **pcm;       /* this is a pointer into local storage */ 
  91.   oggpack_buffer opb;
  92.   
  93.   long  lW;
  94.   long  W;
  95.   long  nW;
  96.   int   pcmend;
  97.   int   mode;
  98.  
  99.   int         eofflag;
  100.   ogg_int64_t granulepos;
  101.   ogg_int64_t sequence;
  102.   vorbis_dsp_state *vd; /* For read-only access of configuration */
  103.  
  104.   /* local storage to avoid remallocing; it's up to the mapping to
  105.      structure it */
  106.   void               *localstore;
  107.   long                localtop;
  108.   long                localalloc;
  109.   long                totaluse;
  110.   struct alloc_chain *reap;
  111.  
  112.   /* bitmetrics for the frame */
  113.   long glue_bits;
  114.   long time_bits;
  115.   long floor_bits;
  116.   long res_bits;
  117.  
  118.   void *internal;
  119.  
  120. } vorbis_block;
  121.  
  122. /* vorbis_block is a single block of data to be processed as part of
  123. the analysis/synthesis stream; it belongs to a specific logical
  124. bitstream, but is independant from other vorbis_blocks belonging to
  125. that logical bitstream. *************************************************/
  126.  
  127. struct alloc_chain{
  128.   void *ptr;
  129.   struct alloc_chain *next;
  130. };
  131.  
  132. /* vorbis_info contains all the setup information specific to the
  133.    specific compression/decompression mode in progress (eg,
  134.    psychoacoustic settings, channel setup, options, codebook
  135.    etc). vorbis_info and substructures are in backends.h.
  136. *********************************************************************/
  137.  
  138. /* the comments are not part of vorbis_info so that vorbis_info can be
  139.    static storage */
  140. typedef struct vorbis_comment{
  141.   /* unlimited user comment fields.  libvorbis writes 'libvorbis'
  142.      whatever vendor is set to in encode */
  143.   char **user_comments;
  144.   int   *comment_lengths;
  145.   int    comments;
  146.   char  *vendor;
  147.  
  148. } vorbis_comment;
  149.  
  150.  
  151. /* libvorbis encodes in two abstraction layers; first we perform DSP
  152.    and produce a packet (see docs/analysis.txt).  The packet is then
  153.    coded into a framed OggSquish bitstream by the second layer (see
  154.    docs/framing.txt).  Decode is the reverse process; we sync/frame
  155.    the bitstream and extract individual packets, then decode the
  156.    packet back into PCM audio.
  157.  
  158.    The extra framing/packetizing is used in streaming formats, such as
  159.    files.  Over the net (such as with UDP), the framing and
  160.    packetization aren't necessary as they're provided by the transport
  161.    and the streaming layer is not used */
  162.  
  163. /* Vorbis PRIMITIVES: general ***************************************/
  164.  
  165. extern void     vorbis_info_init(vorbis_info *vi);
  166. extern void     vorbis_info_clear(vorbis_info *vi);
  167. extern void     vorbis_comment_init(vorbis_comment *vc);
  168. extern void     vorbis_comment_add(vorbis_comment *vc, char *comment); 
  169. extern void     vorbis_comment_add_tag(vorbis_comment *vc, 
  170.                        char *tag, char *contents);
  171. extern char    *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  172. extern int      vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  173. extern void     vorbis_comment_clear(vorbis_comment *vc);
  174.  
  175. extern int      vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  176. extern int      vorbis_block_clear(vorbis_block *vb);
  177. extern void     vorbis_dsp_clear(vorbis_dsp_state *v);
  178.  
  179. /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
  180.  
  181. extern int      vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  182. extern int      vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  183. extern int      vorbis_analysis_headerout(vorbis_dsp_state *v,
  184.                       vorbis_comment *vc,
  185.                       ogg_packet *op,
  186.                       ogg_packet *op_comm,
  187.                       ogg_packet *op_code);
  188. extern float  **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  189. extern int      vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  190. extern int      vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  191. extern int      vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  192.  
  193. /* Vorbis PRIMITIVES: synthesis layer *******************************/
  194. extern int      vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  195.                       ogg_packet *op);
  196.  
  197. extern int      vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  198. extern int      vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  199. extern int      vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  200. extern int      vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  201. extern int      vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  202. extern long     vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  203.  
  204. /* Vorbis ERRORS and return codes ***********************************/
  205.  
  206. #define OV_FALSE      -1  
  207. #define OV_EOF        -2
  208. #define OV_HOLE       -3
  209.  
  210. #define OV_EREAD      -128
  211. #define OV_EFAULT     -129
  212. #define OV_EIMPL      -130
  213. #define OV_EINVAL     -131
  214. #define OV_ENOTVORBIS -132
  215. #define OV_EBADHEADER -133
  216. #define OV_EVERSION   -134
  217. #define OV_ENOTAUDIO  -135
  218. #define OV_EBADPACKET -136
  219. #define OV_EBADLINK   -137
  220. #define OV_ENOSEEK    -138
  221.  
  222. #ifdef __cplusplus
  223. }
  224. #endif /* __cplusplus */
  225.  
  226. #endif
  227.  
  228.