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-2003    *
10  * BY THE Xiph.Org FOUNDATION http://www.xiph.org/                  *
11  *                                                                  *
12  ********************************************************************
13 
14  function: libvorbis codec headers
15 
16  ********************************************************************/
17 
18 #ifndef _V_CODECI_H_
19 #define _V_CODECI_H_
20 
21 #define CHUNKSIZE 1024
22 
23 #include "codebook.h"
24 #include "ivorbiscodec.h"
25 
26 #define VI_TRANSFORMB 1
27 #define VI_WINDOWB 1
28 #define VI_TIMEB 1
29 #define VI_FLOORB 2
30 #define VI_RESB 3
31 #define VI_MAPB 1
32 
33 typedef void vorbis_info_floor;
34 
35 /* vorbis_dsp_state buffers the current vorbis audio
36    analysis/synthesis state.  The DSP state belongs to a specific
37    logical bitstream ****************************************************/
38 struct vorbis_dsp_state{
39   vorbis_info    *vi;
40   oggpack_buffer  opb;
41 
42   ogg_int32_t   **work;
43   ogg_int32_t   **mdctright;
44   int             out_begin;
45   int             out_end;
46 
47   long lW;
48   long W;
49 
50   ogg_int64_t granulepos;
51   ogg_int64_t sequence;
52   ogg_int64_t sample_count;
53 
54 };
55 
56 
57 /* Floor backend generic *****************************************/
58 
59 extern vorbis_info_floor *floor0_info_unpack(vorbis_info *,oggpack_buffer *);
60 extern void floor0_free_info(vorbis_info_floor *);
61 extern int floor0_memosize(vorbis_info_floor *);
62 extern ogg_int32_t *floor0_inverse1(struct vorbis_dsp_state *,
63            vorbis_info_floor *,ogg_int32_t *);
64 extern int floor0_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *,
65          ogg_int32_t *buffer,ogg_int32_t *);
66 
67 extern vorbis_info_floor *floor1_info_unpack(vorbis_info *,oggpack_buffer *);
68 extern void floor1_free_info(vorbis_info_floor *);
69 extern int floor1_memosize(vorbis_info_floor *);
70 extern ogg_int32_t *floor1_inverse1(struct vorbis_dsp_state *,
71            vorbis_info_floor *,ogg_int32_t *);
72 extern int floor1_inverse2 (struct vorbis_dsp_state *,vorbis_info_floor *,
73          ogg_int32_t *buffer,ogg_int32_t *);
74 
75 typedef struct{
76   int   order;
77   long  rate;
78   long  barkmap;
79 
80   int   ampbits;
81   int   ampdB;
82 
83   int   numbooks; /* <= 16 */
84   char  books[16];
85 
86 } vorbis_info_floor0;
87 
88 typedef struct{
89   char  class_dim;        /* 1 to 8 */
90   char  class_subs;       /* 0,1,2,3 (bits: 1<<n poss) */
91   unsigned char  class_book;       /* subs ^ dim entries */
92   unsigned char  class_subbook[8]; /* [VIF_CLASS][subs] */
93 } floor1class;
94 
95 typedef struct{
96   floor1class  *class;          /* [VIF_CLASS] */
97   char         *partitionclass; /* [VIF_PARTS]; 0 to 15 */
98   ogg_uint16_t *postlist;       /* [VIF_POSIT+2]; first two implicit */
99   char         *forward_index;  /* [VIF_POSIT+2]; */
100   char         *hineighbor;     /* [VIF_POSIT]; */
101   char         *loneighbor;     /* [VIF_POSIT]; */
102 
103   int          partitions;    /* 0 to 31 */
104   int          posts;
105   int          mult;          /* 1 2 3 or 4 */
106 
107 } vorbis_info_floor1;
108 
109 /* Residue backend generic *****************************************/
110 
111 typedef struct vorbis_info_residue{
112   int type;
113   unsigned char *stagemasks;
114   unsigned char *stagebooks;
115 
116 /* block-partitioned VQ coded straight residue */
117   long begin;
118   long end;
119 
120   /* first stage (lossless partitioning) */
121   int           grouping;         /* group n vectors per partition */
122   char          partitions;       /* possible codebooks for a partition */
123   unsigned char groupbook;        /* huffbook for partitioning */
124   char          stages;
125 } vorbis_info_residue;
126 
127 extern void res_clear_info(vorbis_info_residue *info);
128 extern int res_unpack(vorbis_info_residue *info,
129          vorbis_info *vi,oggpack_buffer *opb);
130 extern int res_inverse(vorbis_dsp_state *,vorbis_info_residue *info,
131           ogg_int32_t **in,int *nonzero,int ch);
132 
133 /* mode ************************************************************/
134 typedef struct {
135   unsigned char blockflag;
136   unsigned char mapping;
137 } vorbis_info_mode;
138 
139 /* Mapping backend generic *****************************************/
140 typedef struct coupling_step{
141   unsigned char mag;
142   unsigned char ang;
143 } coupling_step;
144 
145 typedef struct submap{
146   char floor;
147   char residue;
148 } submap;
149 
150 typedef struct vorbis_info_mapping{
151   int            submaps;
152 
153   unsigned char *chmuxlist;
154   submap        *submaplist;
155 
156   int            coupling_steps;
157   coupling_step *coupling;
158 } vorbis_info_mapping;
159 
160 extern int mapping_info_unpack(vorbis_info_mapping *,vorbis_info *,
161             oggpack_buffer *);
162 extern void mapping_clear_info(vorbis_info_mapping *);
163 extern int mapping_inverse(struct vorbis_dsp_state *,vorbis_info_mapping *);
164 
165 /* codec_setup_info contains all the setup information specific to the
166    specific compression/decompression mode in progress (eg,
167    psychoacoustic settings, channel setup, options, codebook
168    etc).
169 *********************************************************************/
170 
171 typedef struct codec_setup_info {
172 
173   /* Vorbis supports only short and long blocks, but allows the
174      encoder to choose the sizes */
175 
176   long blocksizes[2];
177 
178   /* modes are the primary means of supporting on-the-fly different
179      blocksizes, different channel mappings (LR or M/A),
180      different residue backends, etc.  Each mode consists of a
181      blocksize flag and a mapping (along with the mapping setup */
182 
183   int        modes;
184   int        maps;
185   int        floors;
186   int        residues;
187   int        books;
188 
189   vorbis_info_mode       *mode_param;
190   vorbis_info_mapping    *map_param;
191   char                   *floor_type;
192   vorbis_info_floor     **floor_param;
193   vorbis_info_residue    *residue_param;
194   codebook               *book_param;
195 
196 } codec_setup_info;
197 
198 extern vorbis_dsp_state *vorbis_dsp_create(vorbis_info *vi);
199 extern void     vorbis_dsp_destroy(vorbis_dsp_state *v);
200 extern int      vorbis_dsp_headerin(vorbis_info *vi,vorbis_comment *vc,
201            ogg_packet *op);
202 
203 extern int      vorbis_dsp_restart(vorbis_dsp_state *v);
204 extern int      vorbis_dsp_synthesis(vorbis_dsp_state *vd,
205             ogg_packet *op,int decodep);
206 extern int      vorbis_dsp_pcmout(vorbis_dsp_state *v,
207          ogg_int16_t *pcm,int samples);
208 extern int      vorbis_dsp_read(vorbis_dsp_state *v,int samples);
209 extern long     vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
210 
211 
212 
213 #endif
214