ivorbiscodec.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
  4. * *
  5. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  6. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  7. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  8. * *
  9. * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
  10. * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
  11. * *
  12. ********************************************************************
  13. function: libvorbis codec headers
  14. ********************************************************************/
  15. #ifndef _vorbis_codec_h_
  16. #define _vorbis_codec_h_
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif /* __cplusplus */
  21. #include <ogg/ogg.h>
  22. typedef struct vorbis_info{
  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. int analysisp;
  50. vorbis_info *vi;
  51. ogg_int32_t **pcm;
  52. ogg_int32_t **pcmret;
  53. int pcm_storage;
  54. int pcm_current;
  55. int pcm_returned;
  56. int preextrapolate;
  57. int eofflag;
  58. long lW;
  59. long W;
  60. long nW;
  61. long centerW;
  62. ogg_int64_t granulepos;
  63. ogg_int64_t sequence;
  64. void *backend_state;
  65. } vorbis_dsp_state;
  66. typedef struct vorbis_block{
  67. /* necessary stream state for linking to the framing abstraction */
  68. ogg_int32_t **pcm; /* this is a pointer into local storage */
  69. oggpack_buffer opb;
  70. long lW;
  71. long W;
  72. long nW;
  73. int pcmend;
  74. int mode;
  75. int eofflag;
  76. ogg_int64_t granulepos;
  77. ogg_int64_t sequence;
  78. vorbis_dsp_state *vd; /* For read-only access of configuration */
  79. /* local storage to avoid remallocing; it's up to the mapping to
  80. structure it */
  81. void *localstore;
  82. long localtop;
  83. long localalloc;
  84. long totaluse;
  85. struct alloc_chain *reap;
  86. } vorbis_block;
  87. /* vorbis_block is a single block of data to be processed as part of
  88. the analysis/synthesis stream; it belongs to a specific logical
  89. bitstream, but is independant from other vorbis_blocks belonging to
  90. that logical bitstream. *************************************************/
  91. struct alloc_chain{
  92. void *ptr;
  93. struct alloc_chain *next;
  94. };
  95. /* vorbis_info contains all the setup information specific to the
  96. specific compression/decompression mode in progress (eg,
  97. psychoacoustic settings, channel setup, options, codebook
  98. etc). vorbis_info and substructures are in backends.h.
  99. *********************************************************************/
  100. /* the comments are not part of vorbis_info so that vorbis_info can be
  101. static storage */
  102. typedef struct vorbis_comment{
  103. /* unlimited user comment fields. libvorbis writes 'libvorbis'
  104. whatever vendor is set to in encode */
  105. char **user_comments;
  106. int *comment_lengths;
  107. int comments;
  108. char *vendor;
  109. } vorbis_comment;
  110. /* libvorbis encodes in two abstraction layers; first we perform DSP
  111. and produce a packet (see docs/analysis.txt). The packet is then
  112. coded into a framed OggSquish bitstream by the second layer (see
  113. docs/framing.txt). Decode is the reverse process; we sync/frame
  114. the bitstream and extract individual packets, then decode the
  115. packet back into PCM audio.
  116. The extra framing/packetizing is used in streaming formats, such as
  117. files. Over the net (such as with UDP), the framing and
  118. packetization aren't necessary as they're provided by the transport
  119. and the streaming layer is not used */
  120. /* Vorbis PRIMITIVES: general ***************************************/
  121. extern void vorbis_info_init(vorbis_info *vi);
  122. extern void vorbis_info_clear(vorbis_info *vi);
  123. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  124. extern void vorbis_comment_init(vorbis_comment *vc);
  125. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  126. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  127. char *tag, char *contents);
  128. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  129. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  130. extern void vorbis_comment_clear(vorbis_comment *vc);
  131. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  132. extern int vorbis_block_clear(vorbis_block *vb);
  133. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  134. /* Vorbis PRIMITIVES: synthesis layer *******************************/
  135. extern int vorbis_synthesis_idheader(ogg_packet *op);
  136. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  137. ogg_packet *op);
  138. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  139. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  140. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  141. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  142. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  143. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,ogg_int32_t ***pcm);
  144. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  145. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  146. /* Vorbis ERRORS and return codes ***********************************/
  147. #define OV_FALSE -1
  148. #define OV_EOF -2
  149. #define OV_HOLE -3
  150. #define OV_EREAD -128
  151. #define OV_EFAULT -129
  152. #define OV_EIMPL -130
  153. #define OV_EINVAL -131
  154. #define OV_ENOTVORBIS -132
  155. #define OV_EBADHEADER -133
  156. #define OV_EVERSION -134
  157. #define OV_ENOTAUDIO -135
  158. #define OV_EBADPACKET -136
  159. #define OV_EBADLINK -137
  160. #define OV_ENOSEEK -138
  161. #ifdef __cplusplus
  162. }
  163. #endif /* __cplusplus */
  164. #endif