xref: /plan9/sys/src/games/mp3enc/quantize_pvt.h (revision 8f5875f3e9b20916b4c52ad4336922bc8653eb7b)
1 /*
2  *	quantize_pvt include file
3  *
4  *	Copyright (c) 1999 Takehiro TOMINAGA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef LAME_QUANTIZE_PVT_H
23 #define LAME_QUANTIZE_PVT_H
24 
25 #include "l3side.h"
26 #define IXMAX_VAL 8206  /* ix always <= 8191+15.    see count_bits() */
27 
28 /* buggy Winamp decoder cannot handle values > 8191 */
29 /* #define IXMAX_VAL 8191 */
30 
31 #define PRECALC_SIZE (IXMAX_VAL+2)
32 
33 
34 extern const int nr_of_sfb_block[6][3][4];
35 extern const char pretab[SBMAX_l];
36 extern const char slen1_tab[16];
37 extern const char slen2_tab[16];
38 
39 extern const scalefac_struct sfBandIndex[9];
40 
41 extern FLOAT8 pow43[PRECALC_SIZE];
42 extern FLOAT8 adj43[PRECALC_SIZE];
43 extern FLOAT8 adj43asm[PRECALC_SIZE];
44 
45 #define Q_MAX 330
46 
47 extern FLOAT8 pow20[Q_MAX];
48 extern FLOAT8 ipow20[Q_MAX];
49 
50 typedef struct calc_noise_result_t {
51     int     over_count;      /* number of quantization noise > masking */
52     int     tot_count;       /* all */
53     FLOAT8  over_noise;      /* sum of quantization noise > masking */
54     FLOAT8  tot_noise;       /* sum of all quantization noise */
55     FLOAT8  max_noise;       /* max quantization noise */
56     float   klemm_noise;
57     FLOAT8  dist_l[SBMAX_l];
58     FLOAT8  dist_s[3][SBMAX_s];
59 } calc_noise_result;
60 
61 void    compute_ath (lame_global_flags * gfp, FLOAT8 ATH_l[SBPSY_l],
62                      FLOAT8 ATH_s[SBPSY_l]);
63 
64 void    ms_convert (FLOAT8 xr[2][576], FLOAT8 xr_org[2][576]);
65 
66 int     on_pe (lame_global_flags *gfp, FLOAT8 pe[2][2], III_side_info_t * l3_side,
67                int targ_bits[2], int mean_bits, int gr);
68 
69 void    reduce_side (int targ_bits[2], FLOAT8 ms_ener_ratio, int mean_bits,
70                      int max_bits);
71 
72 
73 int     bin_search_StepSize (lame_internal_flags * gfc, gr_info * cod_info,
74                              int desired_rate, int start,
75                              const FLOAT8 xrpow[576], int l3enc[576]);
76 
77 int     inner_loop (lame_internal_flags * gfc, gr_info * cod_info, int max_bits,
78                     const FLOAT8 xrpow[576], int l3enc[576]);
79 
80 void    iteration_init (lame_global_flags *gfp);
81 
82 
83 int     calc_xmin (lame_global_flags *gfp, const FLOAT8 xr[576],
84                    const III_psy_ratio * ratio, const gr_info * cod_info,
85                    III_psy_xmin * l3_xmin);
86 
87 int     calc_noise (const lame_internal_flags * gfc, const FLOAT8 xr[576],
88                     const int ix[576], const gr_info * cod_info,
89                     const III_psy_xmin * l3_xmin,
90                     const III_scalefac_t * scalefac,
91                     III_psy_xmin * distort, calc_noise_result * res);
92 
93 void    set_frame_pinfo (lame_global_flags *gfp, FLOAT8 xr[2][2][576],
94                          III_psy_ratio ratio[2][2], int l3_enc[2][2][576],
95                          III_scalefac_t scalefac[2][2]);
96 
97 
98 void    quantize_xrpow (const FLOAT8 xr[576], int ix[576], FLOAT8 istep);
99 
100 void    quantize_xrpow_ISO (const FLOAT8 xr[576], int ix[576], FLOAT8 istep);
101 
102 
103 
104 /* takehiro.c */
105 
106 int     count_bits (lame_internal_flags * gfc, int *ix, const FLOAT8 xr[576],
107                     gr_info * cod_info);
108 
109 
110 void    best_huffman_divide (const lame_internal_flags * gfc, int gr, int ch,
111                              gr_info * cod_info, int *ix);
112 
113 void    best_scalefac_store (const lame_internal_flags * gfc, int gr, int ch,
114                              int l3_enc[2][2][576], III_side_info_t * l3_side,
115                              III_scalefac_t scalefac[2][2]);
116 
117 int     scale_bitcount (III_scalefac_t * scalefac, gr_info * cod_info);
118 
119 int     scale_bitcount_lsf (const lame_internal_flags *gfp, const III_scalefac_t * scalefac,
120                             gr_info * cod_info);
121 
122 void    huffman_init (lame_internal_flags * gfc);
123 
124 #define LARGE_BITS 100000
125 
126 #endif /* LAME_QUANTIZE_PVT_H */
127