389
389
AacPsyChannel *pch = &pctx->ch[channel];
390
390
uint8_t grouping = 0;
391
391
int next_type = pch->next_window_seq;
392
FFPsyWindowInfo wi = { { 0 } };
394
memset(&wi, 0, sizeof(wi));
397
396
int switch_to_eight = 0;
400
399
int stay_short = 0;
401
400
for (i = 0; i < 8; i++) {
402
401
for (j = 0; j < 128; j++) {
403
v = iir_filter(la[(i*128+j)*ctx->avctx->channels], pch->iir_state);
402
v = iir_filter(la[i*128+j], pch->iir_state);
593
592
for (w = 0; w < wi->num_windows*16; w += 16) {
594
593
AacPsyBand *bands = &pch->band[w];
596
//5.4.2.3 "Spreading" & 5.4.3 "Spreaded Energy Calculation"
595
/* 5.4.2.3 "Spreading" & 5.4.3 "Spread Energy Calculation" */
597
596
spread_en[0] = bands[0].energy;
598
597
for (g = 1; g < num_bands; g++) {
599
598
bands[g].thr = FFMAX(bands[g].thr, bands[g-1].thr * coeffs[g].spread_hi[0]);
613
612
band->thr = FFMAX(PSY_3GPP_RPEMIN*band->thr, FFMIN(band->thr,
614
613
PSY_3GPP_RPELEV*pch->prev_band[w+g].thr_quiet));
616
/* 5.6.1.3.1 "Prepatory steps of the perceptual entropy calculation" */
615
/* 5.6.1.3.1 "Preparatory steps of the perceptual entropy calculation" */
617
616
pe += calc_pe_3gpp(band);
618
617
a += band->pe_const;
619
618
active_lines += band->active_lines;
776
775
ctx->next_window_seq = blocktype;
779
static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx,
780
const int16_t *audio, const int16_t *la,
781
int channel, int prev_type)
778
static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
779
const float *la, int channel, int prev_type)
783
781
AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data;
784
782
AacPsyChannel *pch = &pctx->ch[channel];
786
784
int uselongblock = 1;
787
785
int attacks[AAC_NUM_BLOCKS_SHORT + 1] = { 0 };
787
FFPsyWindowInfo wi = { { 0 } };
791
memset(&wi, 0, sizeof(wi));
793
790
float hpfsmpl[AAC_BLOCK_SIZE_LONG];
794
791
float const *pf = hpfsmpl;
795
792
float attack_intensity[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
796
793
float energy_subshort[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
797
794
float energy_short[AAC_NUM_BLOCKS_SHORT + 1] = { 0 };
798
int chans = ctx->avctx->channels;
799
const int16_t *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN) * chans;
795
const float *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN);
800
796
int j, att_sum = 0;
802
798
/* LAME comment: apply high pass filter of fs/4 */
803
799
for (i = 0; i < AAC_BLOCK_SIZE_LONG; i++) {
804
800
float sum1, sum2;
805
sum1 = firbuf[(i + ((PSY_LAME_FIR_LEN - 1) / 2)) * chans];
801
sum1 = firbuf[i + (PSY_LAME_FIR_LEN - 1) / 2];
807
803
for (j = 0; j < ((PSY_LAME_FIR_LEN - 1) / 2) - 1; j += 2) {
808
sum1 += psy_fir_coeffs[j] * (firbuf[(i + j) * chans] + firbuf[(i + PSY_LAME_FIR_LEN - j) * chans]);
809
sum2 += psy_fir_coeffs[j + 1] * (firbuf[(i + j + 1) * chans] + firbuf[(i + PSY_LAME_FIR_LEN - j - 1) * chans]);
804
sum1 += psy_fir_coeffs[j] * (firbuf[i + j] + firbuf[i + PSY_LAME_FIR_LEN - j]);
805
sum2 += psy_fir_coeffs[j + 1] * (firbuf[i + j + 1] + firbuf[i + PSY_LAME_FIR_LEN - j - 1]);
811
hpfsmpl[i] = sum1 + sum2;
807
/* NOTE: The LAME psymodel expects it's input in the range -32768 to 32768. Tuning this for normalized floats would be difficult. */
808
hpfsmpl[i] = (sum1 + sum2) * 32768.0f;
814
811
/* Calculate the energies of each sub-shortblock */
823
820
float const *const pfe = pf + AAC_BLOCK_SIZE_LONG / (AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS);
825
822
for (; pf < pfe; pf++)
823
p = FFMAX(p, fabsf(*pf));
828
824
pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p;
829
825
energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p;
830
/* FIXME: The indexes below are [i + 3 - 2] in the LAME source.
831
* Obviously the 3 and 2 have some significance, or this would be just [i + 1]
832
* (which is what we use here). What the 3 stands for is ambigious, as it is both
833
* number of short blocks, and the number of sub-short blocks.
834
* It seems that LAME is comparing each sub-block to sub-block + 1 in the
826
/* NOTE: The indexes below are [i + 3 - 2] in the LAME source.
827
* Obviously the 3 and 2 have some significance, or this would be just [i + 1]
828
* (which is what we use here). What the 3 stands for is ambiguous, as it is both
829
* number of short blocks, and the number of sub-short blocks.
830
* It seems that LAME is comparing each sub-block to sub-block + 1 in the
837
833
if (p > energy_subshort[i + 1])
838
834
p = p / energy_subshort[i + 1];