comparison mpegaudiodec.c @ 6138:c7a61f83de73 libavcodec

Factorize some code into functions, had this in my tree and will be needed for mp3 encoding.
author michael
date Fri, 11 Jan 2008 21:34:05 +0000
parents 5ef885b008c0
children dfdff1ca78a7
comparison
equal deleted inserted replaced
6137:5ef885b008c0 6138:c7a61f83de73
123 SCALE_GEN(4.0 / 5.0), /* 5 steps */ 123 SCALE_GEN(4.0 / 5.0), /* 5 steps */
124 SCALE_GEN(4.0 / 9.0), /* 9 steps */ 124 SCALE_GEN(4.0 / 9.0), /* 9 steps */
125 }; 125 };
126 126
127 static DECLARE_ALIGNED_16(MPA_INT, window[512]); 127 static DECLARE_ALIGNED_16(MPA_INT, window[512]);
128
129 /**
130 * Convert region offsets to region sizes and truncate
131 * size to big_values.
132 */
133 void ff_region_offset2size(GranuleDef *g){
134 int i, k, j=0;
135 g->region_size[2] = (576 / 2);
136 for(i=0;i<3;i++) {
137 k = FFMIN(g->region_size[i], g->big_values);
138 g->region_size[i] = k - j;
139 j = k;
140 }
141 }
142
143 void ff_init_short_region(MPADecodeContext *s, GranuleDef *g){
144 if (g->block_type == 2)
145 g->region_size[0] = (36 / 2);
146 else {
147 if (s->sample_rate_index <= 2)
148 g->region_size[0] = (36 / 2);
149 else if (s->sample_rate_index != 8)
150 g->region_size[0] = (54 / 2);
151 else
152 g->region_size[0] = (108 / 2);
153 }
154 g->region_size[1] = (576 / 2);
155 }
156
157 void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2){
158 int l;
159 g->region_size[0] =
160 band_index_long[s->sample_rate_index][ra1 + 1] >> 1;
161 /* should not overflow */
162 l = FFMIN(ra1 + ra2 + 2, 22);
163 g->region_size[1] =
164 band_index_long[s->sample_rate_index][l] >> 1;
165 }
166
167 void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g){
168 if (g->block_type == 2) {
169 if (g->switch_point) {
170 /* if switched mode, we handle the 36 first samples as
171 long blocks. For 8000Hz, we handle the 48 first
172 exponents as long blocks (XXX: check this!) */
173 if (s->sample_rate_index <= 2)
174 g->long_end = 8;
175 else if (s->sample_rate_index != 8)
176 g->long_end = 6;
177 else
178 g->long_end = 4; /* 8000 Hz */
179
180 g->short_start = 2 + (s->sample_rate_index != 8);
181 } else {
182 g->long_end = 0;
183 g->short_start = 0;
184 }
185 } else {
186 g->short_start = 13;
187 g->long_end = 22;
188 }
189 }
128 190
129 /* layer 1 unscaling */ 191 /* layer 1 unscaling */
130 /* n = number of bits of the mantissa minus 1 */ 192 /* n = number of bits of the mantissa minus 1 */
131 static inline int l1_unscale(int n, int mant, int scale_factor) 193 static inline int l1_unscale(int n, int mant, int scale_factor)
132 { 194 {
2006 g->switch_point = get_bits1(&s->gb); 2068 g->switch_point = get_bits1(&s->gb);
2007 for(i=0;i<2;i++) 2069 for(i=0;i<2;i++)
2008 g->table_select[i] = get_bits(&s->gb, 5); 2070 g->table_select[i] = get_bits(&s->gb, 5);
2009 for(i=0;i<3;i++) 2071 for(i=0;i<3;i++)
2010 g->subblock_gain[i] = get_bits(&s->gb, 3); 2072 g->subblock_gain[i] = get_bits(&s->gb, 3);
2011 /* compute huffman coded region sizes */ 2073 ff_init_short_region(s, g);
2012 if (g->block_type == 2)
2013 g->region_size[0] = (36 / 2);
2014 else {
2015 if (s->sample_rate_index <= 2)
2016 g->region_size[0] = (36 / 2);
2017 else if (s->sample_rate_index != 8)
2018 g->region_size[0] = (54 / 2);
2019 else
2020 g->region_size[0] = (108 / 2);
2021 }
2022 g->region_size[1] = (576 / 2);
2023 } else { 2074 } else {
2024 int region_address1, region_address2, l; 2075 int region_address1, region_address2;
2025 g->block_type = 0; 2076 g->block_type = 0;
2026 g->switch_point = 0; 2077 g->switch_point = 0;
2027 for(i=0;i<3;i++) 2078 for(i=0;i<3;i++)
2028 g->table_select[i] = get_bits(&s->gb, 5); 2079 g->table_select[i] = get_bits(&s->gb, 5);
2029 /* compute huffman coded region sizes */ 2080 /* compute huffman coded region sizes */
2030 region_address1 = get_bits(&s->gb, 4); 2081 region_address1 = get_bits(&s->gb, 4);
2031 region_address2 = get_bits(&s->gb, 3); 2082 region_address2 = get_bits(&s->gb, 3);
2032 dprintf(s->avctx, "region1=%d region2=%d\n", 2083 dprintf(s->avctx, "region1=%d region2=%d\n",
2033 region_address1, region_address2); 2084 region_address1, region_address2);
2034 g->region_size[0] = 2085 ff_init_long_region(s, g, region_address1, region_address2);
2035 band_index_long[s->sample_rate_index][region_address1 + 1] >> 1;
2036 l = region_address1 + region_address2 + 2;
2037 /* should not overflow */
2038 if (l > 22)
2039 l = 22;
2040 g->region_size[1] =
2041 band_index_long[s->sample_rate_index][l] >> 1;
2042 } 2086 }
2043 /* convert region offsets to region sizes and truncate 2087 ff_region_offset2size(g);
2044 size to big_values */ 2088 ff_compute_band_indexes(s, g);
2045 g->region_size[2] = (576 / 2);
2046 j = 0;
2047 for(i=0;i<3;i++) {
2048 k = FFMIN(g->region_size[i], g->big_values);
2049 g->region_size[i] = k - j;
2050 j = k;
2051 }
2052
2053 /* compute band indexes */
2054 if (g->block_type == 2) {
2055 if (g->switch_point) {
2056 /* if switched mode, we handle the 36 first samples as
2057 long blocks. For 8000Hz, we handle the 48 first
2058 exponents as long blocks (XXX: check this!) */
2059 if (s->sample_rate_index <= 2)
2060 g->long_end = 8;
2061 else if (s->sample_rate_index != 8)
2062 g->long_end = 6;
2063 else
2064 g->long_end = 4; /* 8000 Hz */
2065
2066 g->short_start = 2 + (s->sample_rate_index != 8);
2067 } else {
2068 g->long_end = 0;
2069 g->short_start = 0;
2070 }
2071 } else {
2072 g->short_start = 13;
2073 g->long_end = 22;
2074 }
2075 2089
2076 g->preflag = 0; 2090 g->preflag = 0;
2077 if (!s->lsf) 2091 if (!s->lsf)
2078 g->preflag = get_bits1(&s->gb); 2092 g->preflag = get_bits1(&s->gb);
2079 g->scalefac_scale = get_bits1(&s->gb); 2093 g->scalefac_scale = get_bits1(&s->gb);