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