codec.h 7.6 KB

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