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-2009 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
10 * *
11 ********************************************************************
12
13 function: libvorbis codec headers
14 last mod: $Id: codec_internal.h 16227 2009-07-08 06:58:46Z xiphmont $
15
16 ********************************************************************/
17
18 #ifndef _V_CODECI_H_
19 #define _V_CODECI_H_
20
21 #include "envelope.h"
22 #include "codebook.h"
23
24 #define BLOCKTYPE_IMPULSE 0
25 #define BLOCKTYPE_PADDING 1
26 #define BLOCKTYPE_TRANSITION 0
27 #define BLOCKTYPE_LONG 1
28
29 #define PACKETBLOBS 15
30
31 typedef struct vorbis_block_internal{
32 float **pcmdelay; /* this is a pointer into local storage */
33 float ampmax;
34 int blocktype;
35
36 oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
37 blob [PACKETBLOBS/2] points to
38 the oggpack_buffer in the
39 main vorbis_block */
40 } vorbis_block_internal;
41
42 typedef void vorbis_look_floor;
43 typedef void vorbis_look_residue;
44 typedef void vorbis_look_transform;
45
46 /* mode ************************************************************/
47 typedef struct {
48 int blockflag;
49 int windowtype;
50 int transformtype;
51 int mapping;
52 } vorbis_info_mode;
53
54 typedef void vorbis_info_floor;
55 typedef void vorbis_info_residue;
56 typedef void vorbis_info_mapping;
57
58 #include "psy.h"
59 #include "bitrate.h"
60
ilog(unsigned int v)61 static int ilog(unsigned int v){
62 int ret=0;
63 while(v){
64 ret++;
65 v>>=1;
66 }
67 return(ret);
68 }
69
ilog2(unsigned int v)70 static int ilog2(unsigned int v){
71 int ret=0;
72 if(v)--v;
73 while(v){
74 ret++;
75 v>>=1;
76 }
77 return(ret);
78 }
79
80
81 typedef struct private_state {
82 /* local lookup storage */
83 envelope_lookup *ve; /* envelope lookup */
84 int window[2];
85 vorbis_look_transform **transform[2]; /* block, type */
86 drft_lookup fft_look[2];
87
88 int modebits;
89 vorbis_look_floor **flr;
90 vorbis_look_residue **residue;
91 vorbis_look_psy *psy;
92 vorbis_look_psy_global *psy_g_look;
93
94 /* local storage, only used on the encoding side. This way the
95 application does not need to worry about freeing some packets'
96 memory and not others'; packet storage is always tracked.
97 Cleared next call to a _dsp_ function */
98 unsigned char *header;
99 unsigned char *header1;
100 unsigned char *header2;
101
102 bitrate_manager_state bms;
103
104 ogg_int64_t sample_count;
105 } private_state;
106
107 /* codec_setup_info contains all the setup information specific to the
108 specific compression/decompression mode in progress (eg,
109 psychoacoustic settings, channel setup, options, codebook
110 etc).
111 *********************************************************************/
112
113 #include "highlevel.h"
114 typedef struct codec_setup_info {
115
116 /* Vorbis supports only short and long blocks, but allows the
117 encoder to choose the sizes */
118
119 long blocksizes[2];
120
121 /* modes are the primary means of supporting on-the-fly different
122 blocksizes, different channel mappings (LR or M/A),
123 different residue backends, etc. Each mode consists of a
124 blocksize flag and a mapping (along with the mapping setup */
125
126 int modes;
127 int maps;
128 int floors;
129 int residues;
130 int books;
131 int psys; /* encode only */
132
133 vorbis_info_mode *mode_param[64];
134 int map_type[64];
135 vorbis_info_mapping *map_param[64];
136 int floor_type[64];
137 vorbis_info_floor *floor_param[64];
138 int residue_type[64];
139 vorbis_info_residue *residue_param[64];
140 static_codebook *book_param[256];
141 codebook *fullbooks;
142
143 vorbis_info_psy *psy_param[4]; /* encode only */
144 vorbis_info_psy_global psy_g_param;
145
146 bitrate_manager_info bi;
147 highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
148 highly redundant structure, but
149 improves clarity of program flow. */
150 int halfrate_flag; /* painless downsample for decode */
151 } codec_setup_info;
152
153 extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
154 extern void _vp_global_free(vorbis_look_psy_global *look);
155
156
157
158 typedef struct {
159 int sorted_index[VIF_POSIT+2];
160 int forward_index[VIF_POSIT+2];
161 int reverse_index[VIF_POSIT+2];
162
163 int hineighbor[VIF_POSIT];
164 int loneighbor[VIF_POSIT];
165 int posts;
166
167 int n;
168 int quant_q;
169 vorbis_info_floor1 *vi;
170
171 long phrasebits;
172 long postbits;
173 long frames;
174 } vorbis_look_floor1;
175
176
177
178 extern int *floor1_fit(vorbis_block *vb,vorbis_look_floor1 *look,
179 const float *logmdct, /* in */
180 const float *logmask);
181 extern int *floor1_interpolate_fit(vorbis_block *vb,vorbis_look_floor1 *look,
182 int *A,int *B,
183 int del);
184 extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
185 vorbis_look_floor1 *look,
186 int *post,int *ilogmask);
187 #endif
188