Mercurial > libavcodec.hg
comparison ac3.c @ 4684:6ec0afffc572 libavcodec
split ac3_parametric_bit_allocation into 3 separate functions
author | jbr |
---|---|
date | Sun, 18 Mar 2007 21:43:20 +0000 |
parents | acdd4b24f5c5 |
children | c7828f1ae244 |
comparison
equal
deleted
inserted
replaced
4683:b4dd7005d807 | 4684:6ec0afffc572 |
---|---|
48 } else { | 48 } else { |
49 return FFMAX(a - 128, 0); | 49 return FFMAX(a - 128, 0); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 /* AC3 bit allocation. The algorithm is the one described in the AC3 | 53 void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, |
54 spec. */ | 54 int16_t *bndpsd) |
55 void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, | 55 { |
56 int8_t *exp, int start, int end, | 56 int bin, i, j, k, end1, v; |
57 int snroffset, int fgain, int is_lfe, | |
58 int deltbae,int deltnseg, | |
59 uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba) | |
60 { | |
61 int bin,i,j,k,end1,v,bndstrt,bndend,lowcomp,begin; | |
62 int fastleak,slowleak,address,tmp; | |
63 int16_t psd[256]; /* scaled exponents */ | |
64 int16_t bndpsd[50]; /* interpolated exponents */ | |
65 int16_t excite[50]; /* excitation */ | |
66 int16_t mask[50]; /* masking value */ | |
67 | 57 |
68 /* exponent mapping to PSD */ | 58 /* exponent mapping to PSD */ |
69 for(bin=start;bin<end;bin++) { | 59 for(bin=start;bin<end;bin++) { |
70 psd[bin]=(3072 - (exp[bin] << 7)); | 60 psd[bin]=(3072 - (exp[bin] << 7)); |
71 } | 61 } |
84 j++; | 74 j++; |
85 } | 75 } |
86 bndpsd[k]=v; | 76 bndpsd[k]=v; |
87 k++; | 77 k++; |
88 } while (end > bndtab[k]); | 78 } while (end > bndtab[k]); |
79 } | |
80 | |
81 void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, | |
82 int start, int end, int fgain, int is_lfe, | |
83 int deltbae, int deltnseg, uint8_t *deltoffst, | |
84 uint8_t *deltlen, uint8_t *deltba, | |
85 int16_t *mask) | |
86 { | |
87 int16_t excite[50]; /* excitation */ | |
88 int bin, k; | |
89 int bndstrt, bndend, begin, end1, tmp; | |
90 int lowcomp, fastleak, slowleak; | |
89 | 91 |
90 /* excitation function */ | 92 /* excitation function */ |
91 bndstrt = masktab[start]; | 93 bndstrt = masktab[start]; |
92 bndend = masktab[end-1] + 1; | 94 bndend = masktab[end-1] + 1; |
93 | 95 |
164 mask[band] += delta; | 166 mask[band] += delta; |
165 band++; | 167 band++; |
166 } | 168 } |
167 } | 169 } |
168 } | 170 } |
169 | 171 } |
170 /* compute bit allocation */ | 172 |
173 void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, | |
174 int snroffset, int floor, uint8_t *bap) | |
175 { | |
176 int i, j, k, end1, v, address; | |
171 | 177 |
172 i = start; | 178 i = start; |
173 j = masktab[start]; | 179 j = masktab[start]; |
174 do { | 180 do { |
175 v = (FFMAX(mask[j] - snroffset - s->floor, 0) & 0x1FE0) + s->floor; | 181 v = (FFMAX(mask[j] - snroffset - floor, 0) & 0x1FE0) + floor; |
176 end1 = FFMIN(bndtab[j] + bndsz[j], end); | 182 end1 = FFMIN(bndtab[j] + bndsz[j], end); |
177 for (k = i; k < end1; k++) { | 183 for (k = i; k < end1; k++) { |
178 address = av_clip((psd[i] - v) >> 5, 0, 63); | 184 address = av_clip((psd[i] - v) >> 5, 0, 63); |
179 bap[i] = baptab[address]; | 185 bap[i] = baptab[address]; |
180 i++; | 186 i++; |
181 } | 187 } |
182 } while (end > bndtab[j++]); | 188 } while (end > bndtab[j++]); |
189 } | |
190 | |
191 /* AC3 bit allocation. The algorithm is the one described in the AC3 | |
192 spec. */ | |
193 void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, | |
194 int8_t *exp, int start, int end, | |
195 int snroffset, int fgain, int is_lfe, | |
196 int deltbae,int deltnseg, | |
197 uint8_t *deltoffst, uint8_t *deltlen, | |
198 uint8_t *deltba) | |
199 { | |
200 int16_t psd[256]; /* scaled exponents */ | |
201 int16_t bndpsd[50]; /* interpolated exponents */ | |
202 int16_t mask[50]; /* masking value */ | |
203 | |
204 ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, bndpsd); | |
205 | |
206 ff_ac3_bit_alloc_calc_mask(s, bndpsd, start, end, fgain, is_lfe, | |
207 deltbae, deltnseg, deltoffst, deltlen, deltba, | |
208 mask); | |
209 | |
210 ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snroffset, s->floor, bap); | |
183 } | 211 } |
184 | 212 |
185 /** | 213 /** |
186 * Initializes some tables. | 214 * Initializes some tables. |
187 * note: This function must remain thread safe because it is called by the | 215 * note: This function must remain thread safe because it is called by the |