codec.h 8.2 KB

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