codec_internal.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /************************************************************************
  2. * Copyright (C) 2002-2009, Xiph.org Foundation
  3. * Copyright (C) 2010, Robin Watts for Pinknoise Productions Ltd
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the names of the Xiph.org Foundation nor Pinknoise
  17. * Productions Ltd nor the names of its contributors may be used to
  18. * endorse or promote products derived from this software without
  19. * specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ************************************************************************
  33. function: libvorbis codec headers
  34. ************************************************************************/
  35. #ifndef _V_CODECI_H_
  36. #define _V_CODECI_H_
  37. #define CHUNKSIZE 1024
  38. #include "codebook.h"
  39. #include "ivorbiscodec.h"
  40. #define VI_TRANSFORMB 1
  41. #define VI_WINDOWB 1
  42. #define VI_TIMEB 1
  43. #define VI_FLOORB 2
  44. #define VI_RESB 3
  45. #define VI_MAPB 1
  46. typedef void vorbis_info_floor;
  47. /* vorbis_dsp_state buffers the current vorbis audio
  48. analysis/synthesis state. The DSP state belongs to a specific
  49. logical bitstream ****************************************************/
  50. struct vorbis_dsp_state{
  51. vorbis_info *vi;
  52. oggpack_buffer opb;
  53. ogg_int32_t **work;
  54. ogg_int32_t **mdctright;
  55. int out_begin;
  56. int out_end;
  57. long lW;
  58. long W;
  59. ogg_int64_t granulepos;
  60. ogg_int64_t sequence;
  61. ogg_int64_t sample_count;
  62. };
  63. /* Floor backend generic *****************************************/
  64. extern vorbis_info_floor *floor0_info_unpack(vorbis_info *,oggpack_buffer *);
  65. extern void floor0_free_info(vorbis_info_floor *);
  66. extern int floor0_memosize(vorbis_info_floor *);
  67. extern ogg_int32_t *floor0_inverse1(struct vorbis_dsp_state *,
  68. vorbis_info_floor *,ogg_int32_t *);
  69. extern int floor0_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *,
  70. ogg_int32_t *buffer,ogg_int32_t *);
  71. extern vorbis_info_floor *floor1_info_unpack(vorbis_info *,oggpack_buffer *);
  72. extern void floor1_free_info(vorbis_info_floor *);
  73. extern int floor1_memosize(vorbis_info_floor *);
  74. extern ogg_int32_t *floor1_inverse1(struct vorbis_dsp_state *,
  75. vorbis_info_floor *,ogg_int32_t *);
  76. extern int floor1_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *,
  77. ogg_int32_t *buffer,ogg_int32_t *);
  78. typedef struct{
  79. int order;
  80. long rate;
  81. long barkmap;
  82. int ampbits;
  83. int ampdB;
  84. int numbooks; /* <= 16 */
  85. char books[16];
  86. } vorbis_info_floor0;
  87. typedef struct{
  88. char class_dim; /* 1 to 8 */
  89. char class_subs; /* 0,1,2,3 (bits: 1<<n poss) */
  90. unsigned char class_book; /* subs ^ dim entries */
  91. unsigned char class_subbook[8]; /* [VIF_CLASS][subs] */
  92. } floor1class;
  93. typedef struct{
  94. floor1class *klass; /* [VIF_CLASS] */
  95. ogg_uint8_t *partitionclass; /* [VIF_PARTS]; 0 to 15 */
  96. ogg_uint16_t *postlist; /* [VIF_POSIT+2]; first two implicit */
  97. ogg_uint8_t *forward_index; /* [VIF_POSIT+2]; */
  98. ogg_uint8_t *hineighbor; /* [VIF_POSIT]; */
  99. ogg_uint8_t *loneighbor; /* [VIF_POSIT]; */
  100. int partitions; /* 0 to 31 */
  101. int posts;
  102. int mult; /* 1 2 3 or 4 */
  103. } vorbis_info_floor1;
  104. /* Residue backend generic *****************************************/
  105. typedef struct vorbis_info_residue{
  106. int type;
  107. unsigned char *stagemasks;
  108. unsigned char *stagebooks;
  109. /* block-partitioned VQ coded straight residue */
  110. long begin;
  111. long end;
  112. /* first stage (lossless partitioning) */
  113. int grouping; /* group n vectors per partition */
  114. char partitions; /* possible codebooks for a partition */
  115. unsigned char groupbook; /* huffbook for partitioning */
  116. char stages;
  117. } vorbis_info_residue;
  118. extern void res_clear_info(vorbis_info_residue *info);
  119. extern int res_unpack(vorbis_info_residue *info,
  120. vorbis_info *vi,oggpack_buffer *opb);
  121. extern int res_inverse(vorbis_dsp_state *,vorbis_info_residue *info,
  122. ogg_int32_t **in,int *nonzero,int ch);
  123. /* mode ************************************************************/
  124. typedef struct {
  125. unsigned char blockflag;
  126. unsigned char mapping;
  127. } vorbis_info_mode;
  128. /* Mapping backend generic *****************************************/
  129. typedef struct coupling_step{
  130. unsigned char mag;
  131. unsigned char ang;
  132. } coupling_step;
  133. typedef struct submap{
  134. char floor;
  135. char residue;
  136. } submap;
  137. typedef struct vorbis_info_mapping{
  138. int submaps;
  139. unsigned char *chmuxlist;
  140. submap *submaplist;
  141. int coupling_steps;
  142. coupling_step *coupling;
  143. } vorbis_info_mapping;
  144. extern int mapping_info_unpack(vorbis_info_mapping *,vorbis_info *,
  145. oggpack_buffer *);
  146. extern void mapping_clear_info(vorbis_info_mapping *);
  147. extern int mapping_inverse(struct vorbis_dsp_state *,vorbis_info_mapping *);
  148. /* codec_setup_info contains all the setup information specific to the
  149. specific compression/decompression mode in progress (eg,
  150. psychoacoustic settings, channel setup, options, codebook
  151. etc).
  152. *********************************************************************/
  153. typedef struct codec_setup_info {
  154. /* Vorbis supports only short and long blocks, but allows the
  155. encoder to choose the sizes */
  156. long blocksizes[2];
  157. /* modes are the primary means of supporting on-the-fly different
  158. blocksizes, different channel mappings (LR or M/A),
  159. different residue backends, etc. Each mode consists of a
  160. blocksize flag and a mapping (along with the mapping setup */
  161. int modes;
  162. int maps;
  163. int floors;
  164. int residues;
  165. int books;
  166. vorbis_info_mode *mode_param;
  167. vorbis_info_mapping *map_param;
  168. char *floor_type;
  169. vorbis_info_floor **floor_param;
  170. vorbis_info_residue *residue_param;
  171. codebook *book_param;
  172. } codec_setup_info;
  173. extern int vorbis_dsp_init(vorbis_dsp_state *v, vorbis_info *vi);
  174. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  175. extern vorbis_dsp_state *vorbis_dsp_create(vorbis_info *vi);
  176. extern void vorbis_dsp_destroy(vorbis_dsp_state *v);
  177. extern int vorbis_dsp_headerin(vorbis_info *vi,vorbis_comment *vc,
  178. ogg_packet *op);
  179. extern int vorbis_dsp_restart(vorbis_dsp_state *v);
  180. extern int vorbis_dsp_synthesis(vorbis_dsp_state *vd,
  181. ogg_packet *op,int decodep);
  182. extern int vorbis_dsp_pcmout(vorbis_dsp_state *v,
  183. ogg_int16_t *pcm,int samples);
  184. extern int vorbis_dsp_read(vorbis_dsp_state *v,int samples);
  185. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  186. #endif