Originally committed as revision 14829 to svn://svn.ffmpeg.org/ffmpeg/trunk
Robert Swain authored on 2008/08/19 06:36:58... | ... |
@@ -605,6 +605,44 @@ static void decode_pulses(Pulse * pulse, GetBitContext * gb, const uint16_t * sw |
605 | 605 |
} |
606 | 606 |
|
607 | 607 |
/** |
608 |
+ * Decode Temporal Noise Shaping data; reference: table 4.48. |
|
609 |
+ * |
|
610 |
+ * @return Returns error status. 0 - OK, !0 - error |
|
611 |
+ */ |
|
612 |
+static int decode_tns(AACContext * ac, TemporalNoiseShaping * tns, |
|
613 |
+ GetBitContext * gb, const IndividualChannelStream * ics) { |
|
614 |
+ int w, filt, i, coef_len, coef_res, coef_compress; |
|
615 |
+ const int is8 = ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE; |
|
616 |
+ const int tns_max_order = is8 ? 7 : ac->m4ac.object_type == AOT_AAC_MAIN ? 20 : 12; |
|
617 |
+ for (w = 0; w < ics->num_windows; w++) { |
|
618 |
+ tns->n_filt[w] = get_bits(gb, 2 - is8); |
|
619 |
+ |
|
620 |
+ if (tns->n_filt[w]) |
|
621 |
+ coef_res = get_bits1(gb); |
|
622 |
+ |
|
623 |
+ for (filt = 0; filt < tns->n_filt[w]; filt++) { |
|
624 |
+ int tmp2_idx; |
|
625 |
+ tns->length[w][filt] = get_bits(gb, 6 - 2*is8); |
|
626 |
+ |
|
627 |
+ if ((tns->order[w][filt] = get_bits(gb, 5 - 2*is8)) > tns_max_order) { |
|
628 |
+ av_log(ac->avccontext, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.", |
|
629 |
+ tns->order[w][filt], tns_max_order); |
|
630 |
+ tns->order[w][filt] = 0; |
|
631 |
+ return -1; |
|
632 |
+ } |
|
633 |
+ tns->direction[w][filt] = get_bits1(gb); |
|
634 |
+ coef_compress = get_bits1(gb); |
|
635 |
+ coef_len = coef_res + 3 - coef_compress; |
|
636 |
+ tmp2_idx = 2*coef_compress + coef_res; |
|
637 |
+ |
|
638 |
+ for (i = 0; i < tns->order[w][filt]; i++) |
|
639 |
+ tns->coef[w][filt][i] = tns_tmp2_map[tmp2_idx][get_bits(gb, coef_len)]; |
|
640 |
+ } |
|
641 |
+ } |
|
642 |
+ return 0; |
|
643 |
+} |
|
644 |
+ |
|
645 |
+/** |
|
608 | 646 |
* Decode Mid/Side data; reference: table 4.54. |
609 | 647 |
* |
610 | 648 |
* @param ms_present Indicates mid/side stereo presence. [0] mask is all 0s; |
... | ... |
@@ -1066,6 +1104,25 @@ static int decode_extension_payload(AACContext * ac, GetBitContext * gb, int cnt |
1066 | 1066 |
return res; |
1067 | 1067 |
} |
1068 | 1068 |
|
1069 |
+ start = ics->swb_offset[FFMIN(bottom, mmm)]; |
|
1070 |
+ end = ics->swb_offset[FFMIN( top, mmm)]; |
|
1071 |
+ if ((size = end - start) <= 0) |
|
1072 |
+ continue; |
|
1073 |
+ if (tns->direction[w][filt]) { |
|
1074 |
+ inc = -1; start = end - 1; |
|
1075 |
+ } else { |
|
1076 |
+ inc = 1; |
|
1077 |
+ } |
|
1078 |
+ start += w * 128; |
|
1079 |
+ |
|
1080 |
+ // ar filter |
|
1081 |
+ for (m = 0; m < size; m++, start += inc) |
|
1082 |
+ for (i = 1; i <= FFMIN(m, order); i++) |
|
1083 |
+ coef[start] -= coef[start - i*inc] * lpc[i]; |
|
1084 |
+ } |
|
1085 |
+ } |
|
1086 |
+} |
|
1087 |
+ |
|
1069 | 1088 |
/** |
1070 | 1089 |
* Conduct IMDCT and windowing. |
1071 | 1090 |
*/ |
... | ... |
@@ -149,6 +149,18 @@ typedef struct { |
149 | 149 |
} IndividualChannelStream; |
150 | 150 |
|
151 | 151 |
/** |
152 |
+ * Temporal Noise Shaping |
|
153 |
+ */ |
|
154 |
+typedef struct { |
|
155 |
+ int present; |
|
156 |
+ int n_filt[8]; |
|
157 |
+ int length[8][4]; |
|
158 |
+ int direction[8][4]; |
|
159 |
+ int order[8][4]; |
|
160 |
+ float coef[8][4][TNS_MAX_ORDER]; |
|
161 |
+} TemporalNoiseShaping; |
|
162 |
+ |
|
163 |
+/** |
|
152 | 164 |
* Dynamic Range Control - decoded from the bitstream but not processed further. |
153 | 165 |
*/ |
154 | 166 |
typedef struct { |
... | ... |
@@ -171,4 +171,39 @@ static const uint8_t tns_max_bands_128[] = { |
171 | 171 |
}; |
172 | 172 |
// @} |
173 | 173 |
|
174 |
+/* @name tns_tmp2_map |
|
175 |
+ * Tables of the tmp2[] arrays of LPC coefficients used for TNS. |
|
176 |
+ * The suffix _M_N[] indicate the values of coef_compress and coef_res |
|
177 |
+ * respectively. |
|
178 |
+ * @{ |
|
179 |
+ */ |
|
180 |
+static const float tns_tmp2_map_1_3[4] = { |
|
181 |
+ 0.00000000, 0.43388373, -0.64278758, -0.34202015, |
|
182 |
+}; |
|
183 |
+ |
|
184 |
+static const float tns_tmp2_map_0_3[8] = { |
|
185 |
+ 0.00000000, 0.43388373, 0.78183150, 0.97492790, |
|
186 |
+ -0.98480773, -0.86602539, -0.64278758, -0.34202015, |
|
187 |
+}; |
|
188 |
+ |
|
189 |
+static const float tns_tmp2_map_1_4[8] = { |
|
190 |
+ 0.00000000, 0.20791170, 0.40673664, 0.58778524, |
|
191 |
+ -0.67369562, -0.52643216, -0.36124167, -0.18374951, |
|
192 |
+}; |
|
193 |
+ |
|
194 |
+static const float tns_tmp2_map_0_4[16] = { |
|
195 |
+ 0.00000000, 0.20791170, 0.40673664, 0.58778524, |
|
196 |
+ 0.74314481, 0.86602539, 0.95105654, 0.99452192, |
|
197 |
+ -0.99573416, -0.96182561, -0.89516330, -0.79801720, |
|
198 |
+ -0.67369562, -0.52643216, -0.36124167, -0.18374951, |
|
199 |
+}; |
|
200 |
+ |
|
201 |
+static const float *tns_tmp2_map[4] = { |
|
202 |
+ tns_tmp2_map_0_3, |
|
203 |
+ tns_tmp2_map_0_4, |
|
204 |
+ tns_tmp2_map_1_3, |
|
205 |
+ tns_tmp2_map_1_4 |
|
206 |
+}; |
|
207 |
+// @} |
|
208 |
+ |
|
174 | 209 |
#endif /* FFMPEG_AACDECTAB_H */ |