codec.h 8.2 KB

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