Move wi.clipping computation outside of psy_lame_window, LFE
channels don't even call that, and make the LFE path also
initialize window_type[1] which is needed by analyze_channel
... | ... |
@@ -554,10 +554,11 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, |
554 | 554 |
if (!frame) |
555 | 555 |
la = NULL; |
556 | 556 |
if (tag == TYPE_LFE) { |
557 |
- wi[ch].window_type[0] = ONLY_LONG_SEQUENCE; |
|
557 |
+ wi[ch].window_type[0] = wi[ch].window_type[1] = ONLY_LONG_SEQUENCE; |
|
558 | 558 |
wi[ch].window_shape = 0; |
559 | 559 |
wi[ch].num_windows = 1; |
560 | 560 |
wi[ch].grouping[0] = 1; |
561 |
+ wi[ch].clipping[0] = 0; |
|
561 | 562 |
|
562 | 563 |
/* Only the lowest 12 coefficients are used in a LFE channel. |
563 | 564 |
* The expression below results in only the bottom 8 coefficients |
... | ... |
@@ -582,9 +583,22 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, |
582 | 582 |
ics->tns_max_bands = wi[ch].window_type[0] == EIGHT_SHORT_SEQUENCE ? |
583 | 583 |
ff_tns_max_bands_128 [s->samplerate_index]: |
584 | 584 |
ff_tns_max_bands_1024[s->samplerate_index]; |
585 |
- clip_avoidance_factor = 0.0f; |
|
585 |
+ |
|
586 | 586 |
for (w = 0; w < ics->num_windows; w++) |
587 | 587 |
ics->group_len[w] = wi[ch].grouping[w]; |
588 |
+ |
|
589 |
+ /* Calculate input sample maximums and evaluate clipping risk */ |
|
590 |
+ clip_avoidance_factor = 0.0f; |
|
591 |
+ for (w = 0; w < ics->num_windows; w++) { |
|
592 |
+ const float *wbuf = overlap + w * 128; |
|
593 |
+ const int wlen = 2048 / ics->num_windows; |
|
594 |
+ float max = 0; |
|
595 |
+ int j; |
|
596 |
+ /* mdct input is 2 * output */ |
|
597 |
+ for (j = 0; j < wlen; j++) |
|
598 |
+ max = FFMAX(max, fabsf(wbuf[j])); |
|
599 |
+ wi[ch].clipping[w] = max; |
|
600 |
+ } |
|
588 | 601 |
for (w = 0; w < ics->num_windows; w++) { |
589 | 602 |
if (wi[ch].clipping[w] > CLIP_AVOIDANCE_FACTOR) { |
590 | 603 |
ics->window_clipping[w] = 1; |
... | ... |
@@ -975,21 +975,6 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio, |
975 | 975 |
|
976 | 976 |
lame_apply_block_type(pch, &wi, uselongblock); |
977 | 977 |
|
978 |
- /* Calculate input sample maximums and evaluate clipping risk */ |
|
979 |
- if (audio) { |
|
980 |
- for (i = 0; i < AAC_NUM_BLOCKS_SHORT; i++) { |
|
981 |
- const float *wbuf = audio + i * AAC_BLOCK_SIZE_SHORT; |
|
982 |
- float max = 0; |
|
983 |
- int j; |
|
984 |
- for (j = 0; j < AAC_BLOCK_SIZE_SHORT; j++) |
|
985 |
- max = FFMAX(max, fabsf(wbuf[j])); |
|
986 |
- clippings[i] = max; |
|
987 |
- } |
|
988 |
- } else { |
|
989 |
- for (i = 0; i < 8; i++) |
|
990 |
- clippings[i] = 0; |
|
991 |
- } |
|
992 |
- |
|
993 | 978 |
wi.window_type[1] = prev_type; |
994 | 979 |
if (wi.window_type[0] != EIGHT_SHORT_SEQUENCE) { |
995 | 980 |
float clipping = 0.0f; |