diff --git a/Android.bp b/Android.bp index a94a176..4f80e91 100644 --- a/Android.bp +++ b/Android.bp @@ -133,8 +133,11 @@ cc_library_static { misc_undefined: [ "unsigned-integer-overflow", "signed-integer-overflow", + "bounds", ], - cfi: true, + // Enable CFI if this becomes a shared library. + // cfi: true, + blacklist: "libxaac_blacklist.txt", }, arch: { diff --git a/README.experimental b/README.experimental index 27fd798..515d685 100644 --- a/README.experimental +++ b/README.experimental @@ -1,5 +1,5 @@ This xaac codec (external/xaac) is experimental; it is not yet intended to be used on production devices. -This codec should not be configured into any production Android Pie -(Android 9) device that will be shipped. +This codec should not be configured into any production Android device +that is intended to be shipped. diff --git a/decoder/armv7/ixheaacd_apply_rot.s b/decoder/armv7/ixheaacd_apply_rot.s index ef3b13f..f6d91f5 100644 --- a/decoder/armv7/ixheaacd_apply_rot.s +++ b/decoder/armv7/ixheaacd_apply_rot.s @@ -25,7 +25,7 @@ ixheaacd_apply_rot_armv7: STMFD SP!, {R4-R12, R14} - LDR R5, =0x59e + MOVW R5, #0x59e MOV R4, #22 ADD R11, R0, R5 LOOP1: @@ -70,7 +70,7 @@ LOOP1: BGT LOOP1 - LDR R4, =0x53C + MOVW R4, #0x53C LDR R12, [R0, #44] ADD R11, R0, R4 MOV R4, #10 @@ -116,8 +116,8 @@ LOOP2: BGT LOOP2 - LDR R11, =0x6c2 - LDR R5, =0x564 + MOVW R11, #0x6c2 + MOVW R5, #0x564 LDRSH R14, [R0, R11] ADD R11, R0, R5 LDR R5, [SP, #44] diff --git a/decoder/armv7/ixheaacd_complex_fft_p2.s b/decoder/armv7/ixheaacd_complex_fft_p2.s index 89efa8a..564f304 100644 --- a/decoder/armv7/ixheaacd_complex_fft_p2.s +++ b/decoder/armv7/ixheaacd_complex_fft_p2.s @@ -20,8 +20,10 @@ ixheaacd_complex_fft_p2_asm: MOV r0, #0 FIRST_STAGE_R4: - LDR r4, =0x33333333 - LDR r5, =0x0F0F0F0F + MOVW r4, #0x3333 + MOVT r4, #0x3333 + MOVW r5, #0x0F0F + MOVT r5, #0x0F0F AND r6, r4, r0 AND r7, r4, r0, LSR #2 ORR r4, r7, r6, LSL #2 diff --git a/decoder/armv7/ixheaacd_complex_ifft_p2.s b/decoder/armv7/ixheaacd_complex_ifft_p2.s index 3a0ce5a..61765be 100644 --- a/decoder/armv7/ixheaacd_complex_ifft_p2.s +++ b/decoder/armv7/ixheaacd_complex_ifft_p2.s @@ -20,8 +20,10 @@ ixheaacd_complex_ifft_p2_asm: MOV r0, #0 FIRST_STAGE_R4: - LDR r4, =0x33333333 - LDR r5, =0x0F0F0F0F + MOVW r4, #0x3333 + MOVT r4, #0x3333 + MOVW r5, #0x0F0F + MOVT r5, #0x0F0F AND r6, r4, r0 AND r7, r4, r0, LSR #2 ORR r4, r7, r6, LSL #2 diff --git a/decoder/armv7/ixheaacd_conv_ergtoamplitude.s b/decoder/armv7/ixheaacd_conv_ergtoamplitude.s index f46464c..e7ab0ee 100644 --- a/decoder/armv7/ixheaacd_conv_ergtoamplitude.s +++ b/decoder/armv7/ixheaacd_conv_ergtoamplitude.s @@ -28,8 +28,8 @@ ixheaacd_conv_ergtoamplitude_armv7: LDR R5, [SP, #44] LDR R4, [SP, #40] - LDR R14, =0x1FF - LDR R10, =0x5A82 + MOVW R14, #0x1FF + MOVW R10, #0x5A82 LOOP1: diff --git a/decoder/armv7/ixheaacd_conv_ergtoamplitudelp.s b/decoder/armv7/ixheaacd_conv_ergtoamplitudelp.s index 193b116..95200d5 100644 --- a/decoder/armv7/ixheaacd_conv_ergtoamplitudelp.s +++ b/decoder/armv7/ixheaacd_conv_ergtoamplitudelp.s @@ -28,8 +28,8 @@ ixheaacd_conv_ergtoamplitudelp_armv7: LDR R5, [SP, #44] LDR R4, [SP, #40] - LDR R11, =0x5A82 - LDR R10, =0x1FF + MOVW R11, #0x5A82 + MOVW R10, #0x1FF LOOP1: diff --git a/decoder/armv7/ixheaacd_decorr_filter2.s b/decoder/armv7/ixheaacd_decorr_filter2.s index b6529ed..bddae5d 100644 --- a/decoder/armv7/ixheaacd_decorr_filter2.s +++ b/decoder/armv7/ixheaacd_decorr_filter2.s @@ -742,7 +742,7 @@ DE_COR_NEXT1: MOV r7, r13 LDR r3, [r0, #0x020] LDR r4, [r0, #0x028] - LDR r12, =0x620a + MOVW r12, #0x620a LDR r6, [r0, #0x024] STR r0, [r13, #-4]! STR r5, [r13, #-4]! diff --git a/decoder/armv7/ixheaacd_esbr_fwd_modulation.s b/decoder/armv7/ixheaacd_esbr_fwd_modulation.s index 98beeec..82fb546 100644 --- a/decoder/armv7/ixheaacd_esbr_fwd_modulation.s +++ b/decoder/armv7/ixheaacd_esbr_fwd_modulation.s @@ -63,7 +63,7 @@ LOOP1: LDR R4, [SP, #124] MOV R0, R1 MOV R1, R3 - ldr R5, =0x41FC + MOVW R5, #0x41FC ADD R2, R4, R5 ADD R3, R4, #0xB8 diff --git a/decoder/armv7/ixheaacd_fft32x32_ld2_armv7.s b/decoder/armv7/ixheaacd_fft32x32_ld2_armv7.s index f09ba65..80e62b3 100644 --- a/decoder/armv7/ixheaacd_fft32x32_ld2_armv7.s +++ b/decoder/armv7/ixheaacd_fft32x32_ld2_armv7.s @@ -198,9 +198,12 @@ ixheaacd_fft32x32_ld2_armv7: @Load twiddle factors - LDR r11, =2310960706 @0x89BE7642 - LDR r12, =3473158396 @0xCF0430FC - LDR r14, =2776455811 @0xA57D5A83 + MOVW r11, 0X7642 + MOVT r11, 0X89BE + MOVW r12, 0X30FC + MOVT r12, 0XCF04 + MOVW r14, 0X5A83 + MOVT r14, 0XA57D @Second Butterfly LDR r2, [r0, #32] @mul_0qr = inp_0qr = x[8] diff --git a/decoder/armv7/ixheaacd_fft_15_ld.s b/decoder/armv7/ixheaacd_fft_15_ld.s index df9e3e6..5e245b6 100644 --- a/decoder/armv7/ixheaacd_fft_15_ld.s +++ b/decoder/armv7/ixheaacd_fft_15_ld.s @@ -1,12 +1,5 @@ -.equ C53_VAL , -11904 -.equ SINMU_VAL , 28378 -.equ C51_52VAL , 0x79BC9D84 -.equ C54_55VAL , 0x478EB000 -.equ FFTOP_OFFSET , -1536 -.equ FFTOP_OFFSET1 , 256 - .text .p2align 2 .global ixheaacd_fft_15_ld_armv7 @@ -34,7 +27,8 @@ LOOP_FFT5: ADD r1, r4, r10 @ r1 = buf1a[2] + buf1a[8] SUB r4, r4, r10 @ r4 = buf1a[2] - buf1a[8]@ - LDR r10, = C54_55VAL + MOVW r10, #0xB000 + MOVT r10, #0x478E ADD r12, r6, r8 @ r3 = buf1a[4] + buf1a[6] SUB r8, r6, r8 @ r2 = buf1a[4] - buf1a[6] @@ -44,7 +38,8 @@ LOOP_FFT5: ADD r2, r2, r1 @ temp1 = inp[0] + r1@ SMULWB r1, r1, r10 @ mult32_shl(r1, C55) ADD r1, r2, r1, lsl #2 @ r1 = temp1 + ((mult32_shl(r1, C55)) << 1)@ - LDR r10, = C51_52VAL @ + MOVW r10, #0x9D84 + MOVT r10, #0x79BC STR r2, [lr], #4 @ *buf2++ = temp1@ SUB r12, r1, r6, LSL #1 @ r3 = r1 - t@ @@ -57,7 +52,8 @@ LOOP_FFT5: MOV r2, r2, LSL #1 SMULWB r4, r4, r10 @ mult32_shl(r4, C52) - LDR r10, = C53_VAL + MOVW r10, #0xD180 + MOVT r10, #0xFFFF ADD r4, r2, r4, LSL #2 @ r4 = t + (mult32_shl(r4, C52) << 1)@ SMULWB r8, r8, r10 @ mult32_shl(r2, C53) @@ -65,7 +61,8 @@ LOOP_FFT5: ADD r6, r5, r11 @ s1 = buf1a[3] + buf1a[9] SUB r8, r5, r11 @ s4 = buf1a[3] - buf1a[9] - LDR r10, = C54_55VAL + MOVW r10, #0xB000 + MOVT r10, #0x478E ADD r5, r7, r9 @ s3 = buf1a[5] + buf1a[7]@ SUB r7, r7, r9 @ s2 = buf1a[5] + buf1a[7]@ @@ -76,7 +73,8 @@ LOOP_FFT5: ADD r3, r3, r6 @ temp2 = buf1a[1] + s1 SMULWB r6, r6, r10 @ mult32_shl(s1, C55) ADD r6, r3, r6, lsl #2 @ s1 = temp1 + ((mult32_shl(s1, C55)) << 1)@ - LDR r10, = C51_52VAL @ + MOVW r10, #0x9D84 + MOVT r10, #0x79BC STR r3, [lr], #4 @ *buf2++ = temp2@ SUB r5, r6, r9, LSL #1 @ s3 = s1 - t@ @@ -90,7 +88,8 @@ LOOP_FFT5: SMULWB r8, r8, r10 @ mult32_shl(s4, C52) - LDR r10, = C53_VAL + MOVW r10, #0xD180 + MOVT r10, #0xFFFF ADD r8, r11, r8, LSL #2 @ s4 = t + (mult32_shl(s4, C52) << 1)@ SMULWB r7, r7, r10 @ mult32_shl(s2, C53) @@ -108,7 +107,8 @@ LOOP_FFT5: STMIA lr!, {r3, r9-r12} @ MOV r12, #384 @ - LDR r1, = FFTOP_OFFSET @ + MOVW r1, #0xFA00 + MOVT r1, #0xFFFF STMIA lr!, {r4-r6} @ @@ -126,7 +126,8 @@ LOOP_FFT5: ADD r1, r4, r10 @ r1 = buf1a[2] + buf1a[8] SUB r4, r4, r10 @ r4 = buf1a[2] - buf1a[8]@ - LDR r10, = C54_55VAL + MOVW r10, #0xB000 + MOVT r10, #0x478E ADD r12, r6, r8 @ r3 = buf1a[4] + buf1a[6] SUB r8, r6, r8 @ r2 = buf1a[4] - buf1a[6] @@ -136,7 +137,8 @@ LOOP_FFT5: ADD r2, r2, r1 @ temp1 = inp[0] + r1@ SMULWB r1, r1, r10 @ mult32_shl(r1, C55) ADD r1, r2, r1, lsl #2 @ r1 = temp1 + ((mult32_shl(r1, C55)) << 1)@ - LDR r10, = C51_52VAL @ + MOVW r10, #0x9D84 + MOVT r10, #0x79BC STR r2, [lr], #4 @ *buf2++ = temp1@ SUB r12, r1, r6, LSL #1 @ r3 = r1 - t@ @@ -149,7 +151,8 @@ LOOP_FFT5: SMULWB r4, r4, r10 @ mult32_shl(r4, C52) - LDR r10, = C53_VAL + MOVW r10, #0xD180 + MOVT r10, #0xFFFF ADD r4, r2, r4, LSL #2 @ r4 = t + (mult32_shl(r4, C52) << 1)@ SMULWB r8, r8, r10 @ mult32_shl(r2, C53) @@ -157,7 +160,8 @@ LOOP_FFT5: ADD r6, r5, r11 @ s1 = buf1a[3] + buf1a[9] SUB r8, r5, r11 @ s4 = buf1a[3] - buf1a[9] - LDR r10, = C54_55VAL + MOVW r10, #0xB000 + MOVT r10, #0x478E ADD r5, r7, r9 @ s3 = buf1a[5] + buf1a[7]@ SUB r7, r7, r9 @ s2 = buf1a[5] + buf1a[7]@ @@ -168,7 +172,8 @@ LOOP_FFT5: ADD r3, r3, r6 @ temp2 = buf1a[1] + s1 SMULWB r6, r6, r10 @ mult32_shl(s1, C55) ADD r6, r3, r6, lsl #2 @ s1 = temp1 + ((mult32_shl(s1, C55)) << 1)@ - LDR r10, = C51_52VAL @ + MOVW r10, #0x9D84 + MOVT r10, #0x79BC STR r3, [lr], #4 @ *buf2++ = temp2@ @@ -181,7 +186,8 @@ LOOP_FFT5: MOV r11, r11, LSL #1 SMULWB r8, r8, r10 @mult32_shl(s4, C52) - LDR r10, = C53_VAL + MOVW r10, #0xD180 + MOVT r10, #0xFFFF ADD r8, r11, r8, LSL #2 @s4 = t + (mult32_shl(s4, C52) << 1)@ SMULWB r7, r7, r10 @mult32_shl(s2, C53) @@ -195,7 +201,8 @@ LOOP_FFT5: SUB r4, r5, r4 @buf2[7] = s3 - r4 SUB r5, r1, r7 @buf2[8] = r1 - s2 ADD r6, r6, r2 @buf2[9] = s1 + r2 - LDR r1, = FFTOP_OFFSET @ + MOVW r1, #0xFA00 + MOVT r1, #0xFFFF STMIA lr!, {r3, r9-r12} MOV r12, #384 @ @@ -215,7 +222,8 @@ LOOP_FFT5: ADD r1, r4, r10 @ r1 = buf1a[2] + buf1a[8] SUB r4, r4, r10 @ r4 = buf1a[2] - buf1a[8]@ - LDR r10, = C54_55VAL + MOVW r10, #0xB000 + MOVT r10, #0x478E ADD r12, r6, r8 @ r3 = buf1a[4] + buf1a[6] SUB r8, r6, r8 @ r2 = buf1a[4] - buf1a[6] @@ -225,7 +233,8 @@ LOOP_FFT5: ADD r2, r2, r1 @ temp1 = inp[0] + r1@ SMULWB r1, r1, r10 @ mult32_shl(r1, C55) ADD r1, r2, r1, lsl #2 @ r1 = temp1 + ((mult32_shl(r1, C55)) << 1)@ - LDR r10, = C51_52VAL @ + MOVW r10, #0x9D84 + MOVT r10, #0x79BC STR r2, [lr], #4 @ *buf2++ = temp1@ SUB r12, r1, r6, LSL #1 @ r3 = r1 - t@ @@ -237,7 +246,8 @@ LOOP_FFT5: MOV r2, r2, LSL #1 SMULWB r4, r4, r10 @ mult32_shl(r4, C52) - LDR r10, = C53_VAL + MOVW r10, #0xD180 + MOVT r10, #0xFFFF ADD r4, r2, r4, LSL #2 @ r4 = t + (mult32_shl(r4, C52) << 1)@ SMULWB r8, r8, r10 @ mult32_shl(r2, C53) @@ -245,7 +255,8 @@ LOOP_FFT5: ADD r6, r5, r11 @ s1 = buf1a[3] + buf1a[9] SUB r8, r5, r11 @ s4 = buf1a[3] - buf1a[9] - LDR r10, = C54_55VAL + MOVW r10, #0xB000 + MOVT r10, #0x478E ADD r5, r7, r9 @ s3 = buf1a[5] + buf1a[7]@ SUB r7, r7, r9 @ s2 = buf1a[5] + buf1a[7]@ @@ -255,7 +266,8 @@ LOOP_FFT5: ADD r3, r3, r6 @ temp2 = buf1a[1] + s1 SMULWB r6, r6, r10 @ mult32_shl(s1, C55) ADD r6, r3, r6, lsl #2 @ s1 = temp1 + ((mult32_shl(s1, C55)) << 1)@ - LDR r10, = C51_52VAL @ + MOVW r10, #0x9D84 + MOVT r10, #0x79BC STR r3, [lr], #4 @ *buf2++ = temp2@ SUB r5, r6, r9, LSL #1 @ s3 = s1 - t@ @@ -267,7 +279,8 @@ LOOP_FFT5: MOV r11, r11, LSL #1 SMULWB r8, r8, r10 @mult32_shl(s4, C52) - LDR r10, = C53_VAL + MOVW r10, #0xD180 + MOVT r10, #0xFFFF ADD r8, r11, r8, LSL #2 @s4 = t + (mult32_shl(s4, C52) << 1)@ @@ -287,7 +300,7 @@ LOOP_FFT5: STMIA lr!, {r4-r6} @ SUB lr, lr, #120 @ - LDR r12, = SINMU_VAL @ + MOVW r12, # 28378 @ LDMFD r13!, {r10, r11} @ diff --git a/decoder/armv7/ixheaacd_imdct_using_fft.s b/decoder/armv7/ixheaacd_imdct_using_fft.s index 563c041..86689d8 100644 --- a/decoder/armv7/ixheaacd_imdct_using_fft.s +++ b/decoder/armv7/ixheaacd_imdct_using_fft.s @@ -33,13 +33,13 @@ ixheaacd_imdct_using_fft_armv7: @ LDR r6, [sp, #0x68+8] @ LDR r7, [sp, #0x68+12] - LDR r8, =11600 + MOVW r8, #11600 ADD r4, r0, r8 - LDR r8, =11856 + MOVW r8, #11856 ADD r5, r0, r8 - LDR r8, =11920 + MOVW r8, #11920 ADD r6, r0, r8 - LDR r8, =11936 + MOVW r8, #11936 ADD r7, r0, r8 @@ -278,7 +278,7 @@ RADIX_8_FIRST_LOOP: VUZP.16 d28, d29 VADD.S32 q4, q8, q7 - LDR r14, =0x5a82 + MOVW r14, #0x5a82 VSUB.S32 q11, q8, q7 @@ -615,7 +615,7 @@ RADIX_4_FIRST_ENDS: PUSH {r3} LSR r5, r5, #2 - LDR r14, =8528 + MOVW r14, #8528 ADD r0, r0, r14 OUTER_LOOP_R4: diff --git a/decoder/armv7/ixheaacd_inv_dit_fft_8pt.s b/decoder/armv7/ixheaacd_inv_dit_fft_8pt.s index 7ed90d9..a4fd00d 100644 --- a/decoder/armv7/ixheaacd_inv_dit_fft_8pt.s +++ b/decoder/armv7/ixheaacd_inv_dit_fft_8pt.s @@ -114,7 +114,7 @@ ixheaacd_inv_dit_fft_8pt_armv7: QADD r7, lr, r10 QSUB r10, lr, r10 - LDR r11, =0x00005a82 + MOVW r11, #0x00005a82 STR r10, [r2, #0x10] QSUB r10, r8, r0 diff --git a/decoder/armv7/ixheaacd_post_twiddle.s b/decoder/armv7/ixheaacd_post_twiddle.s index 4d9d2dd..fe48fda 100644 --- a/decoder/armv7/ixheaacd_post_twiddle.s +++ b/decoder/armv7/ixheaacd_post_twiddle.s @@ -32,7 +32,7 @@ ixheaacd_post_twiddle_armv7: ARM_PROLOGUE: CMP R3, #0x400 - LDR R6, =7500 + MOVW R6, #7500 ADD R2, R2, R6 BLT NEXT MOV R4, #50 @@ -43,8 +43,8 @@ ARM_PROLOGUE: B NEXT1 NEXT: - LDR R4, =0x192 - LDR R5, =0xfe6e + MOVW R4, #0x192 + MOVW R5, #0xfe6e MOV R6, #32 VDUP.16 D10, R4 diff --git a/decoder/armv7/ixheaacd_post_twiddle_overlap.s b/decoder/armv7/ixheaacd_post_twiddle_overlap.s index 391e1c6..24a5ba3 100644 --- a/decoder/armv7/ixheaacd_post_twiddle_overlap.s +++ b/decoder/armv7/ixheaacd_post_twiddle_overlap.s @@ -37,7 +37,7 @@ ixheaacd_post_twid_overlap_add_armv7: ADD R6, R6, R9 SUB R6, R6, #4 - LDR R8, =7500 + MOVW R8, #7500 ADD R2, R2, R8 diff --git a/decoder/armv7/ixheaacd_pre_twiddle_compute.s b/decoder/armv7/ixheaacd_pre_twiddle_compute.s index 6cc22aa..e65f1da 100644 --- a/decoder/armv7/ixheaacd_pre_twiddle_compute.s +++ b/decoder/armv7/ixheaacd_pre_twiddle_compute.s @@ -28,7 +28,7 @@ ixheaacd_pretwiddle_compute_armv7: STMFD sp!, {R4-R12} VPUSH {d8 - d15} - LDR R8, =7500 + MOVW R8, #7500 ADD R3, R3, R8 LDR R4, [sp, #100] LDR R5, [sp, #104] diff --git a/decoder/armv7/ixheaacd_qmf_dec_armv7.c b/decoder/armv7/ixheaacd_qmf_dec_armv7.c index 13b3f9d..d02d874 100644 --- a/decoder/armv7/ixheaacd_qmf_dec_armv7.c +++ b/decoder/armv7/ixheaacd_qmf_dec_armv7.c @@ -50,7 +50,7 @@ #include "ixheaacd_audioobjtypes.h" #define mult16x16_16(a, b) ixheaacd_mult16((a), (b)) -#define mac16x16(a, b, c) ixheaacd_mac16x16in32((a), (b), (c)) +#define mac16x16(a, b, c) ixheaacd_mac16x16in32_sat((a), (b), (c)) #define mpy_32x16(a, b) fixmuldiv2_32x16b((a), (b)) #define mpy_16x16(a, b) ixheaacd_mult16x16in32((a), (b)) #define mpy_32x32(a, b) ixheaacd_mult32((a), (b)) @@ -351,4 +351,4 @@ VOID ixheaacd_esbr_cos_sin_mod(WORD32 *subband, } p_sin = qmf_bank->esbr_alt_sin_twiddle; ixheaacd_esbr_cos_sin_mod_loop2(subband, p_sin, M); -} +} \ No newline at end of file diff --git a/decoder/armv7/ixheaacd_sbr_imdct_using_fft.s b/decoder/armv7/ixheaacd_sbr_imdct_using_fft.s index d398eb7..5fe89e0 100644 --- a/decoder/armv7/ixheaacd_sbr_imdct_using_fft.s +++ b/decoder/armv7/ixheaacd_sbr_imdct_using_fft.s @@ -282,7 +282,7 @@ RADIX_8_FIRST_LOOP: VUZP.16 d28, d29 VADD.S32 q4, q8, q7 - LDR r14, =0x5a82 + MOVW r14, #0x5a82 VSUB.S32 q11, q8, q7 diff --git a/decoder/armv8/ixheaacd_cos_sin_mod_loop1.s b/decoder/armv8/ixheaacd_cos_sin_mod_loop1.s index bbd55df..4a0d235 100644 --- a/decoder/armv8/ixheaacd_cos_sin_mod_loop1.s +++ b/decoder/armv8/ixheaacd_cos_sin_mod_loop1.s @@ -45,7 +45,7 @@ ixheaacd_cos_sin_mod_loop1: SUB x5, x5, #8 ASR x6, x1, #2 - LDR w19, =0 + MOV w19, #0 DUP V0.8h, w19 LOOP1: //first part @@ -83,7 +83,7 @@ LOOP1: ADD x3, x3, #8 ADD x7, x3, #248 ST2 {v2.s, v3.s}[2], [x7] - LDR w19, =0 + MOV w19, #0 DUP V0.8h, w19 //second part ld1 {v0.h}[0] , [x2] @@ -120,7 +120,7 @@ LOOP1: ADD x7, x5, #256 ST2 {v2.s, v3.s}[2], [x7] SUB x5, x5, #8 - LDR w19, =0 + MOV w19, #0 DUP V0.8h, w19 //Third part ld1 {v0.h}[0] , [x2] @@ -156,7 +156,7 @@ LOOP1: ADD x3, x3, #8 ADD x7, x3, #248 ST2 {v2.s, v3.s}[2], [x7] - LDR w19, =0 + MOV w19, #0 DUP V0.8h, w19 //Fourth part ld1 {v0.h}[0] , [x2] @@ -195,7 +195,7 @@ LOOP1: SUBS x6, x6, #1 ST2 {v2.s, v3.s}[2], [x7] SUB x5, x5, #8 - LDR w19, =0 + MOV w19, #0 DUP V0.8h, w19 BGT LOOP1 //VPOP {D8-D11} diff --git a/decoder/armv8/ixheaacd_cos_sin_mod_loop2.s b/decoder/armv8/ixheaacd_cos_sin_mod_loop2.s index a48a705..e51cd58 100644 --- a/decoder/armv8/ixheaacd_cos_sin_mod_loop2.s +++ b/decoder/armv8/ixheaacd_cos_sin_mod_loop2.s @@ -45,7 +45,7 @@ ixheaacd_cos_sin_mod_loop2: ADD x11, x10, x2, LSL #3 SUB x11, x11, #4 MOV x8, #-4 - LDR w19, =0 + MOV w19, #0 DUP V0.4s, w19 DUP V1.4s, w19 @@ -164,7 +164,7 @@ LOOP1: ST1 {v12.s}[2], [x11], x8 ST1 {v16.s}[2], [x10], #4 - LDR w19, =0 + MOV w19, #0 DUP V0.4s, w19 DUP V1.4s, w19 // second part diff --git a/decoder/armv8/ixheaacd_fft32x32_ld2_armv8.s b/decoder/armv8/ixheaacd_fft32x32_ld2_armv8.s index b20aa46..280164b 100644 --- a/decoder/armv8/ixheaacd_fft32x32_ld2_armv8.s +++ b/decoder/armv8/ixheaacd_fft32x32_ld2_armv8.s @@ -266,19 +266,19 @@ ixheaacd_fft32x32_ld2_armv8: //Load twiddle factors // LDR w11, =2310960706 //0x89BE7642 - LDR w11, =0x7642 + MOV w11, #0x7642 sxth w11, w11 - LDR w21, =0x89BE + MOV w21, #0x89BE sxth w21, w21 // LDR w12, =3473158396 //0xCF0430FC - LDR w12, =0x30FC + MOV w12, #0x30FC sxth w12, w12 - LDR w22, =0xCF04 + MOV w22, #0xCF04 sxth w22, w22 // LDR w14, =2776455811 //0xA57D5A83 - LDR w14, =0x5A83 + MOV w14, #0x5A83 sxth w14, w14 - LDR w24, =0xA57D + MOV w24, #0xA57D sxth w24, w24 //Second Butterfly diff --git a/decoder/armv8/ixheaacd_imdct_using_fft.s b/decoder/armv8/ixheaacd_imdct_using_fft.s index 9f2e204..8f8916a 100644 --- a/decoder/armv8/ixheaacd_imdct_using_fft.s +++ b/decoder/armv8/ixheaacd_imdct_using_fft.s @@ -55,13 +55,13 @@ ixheaacd_imdct_using_fft_armv8: push_v_regs - LDR X29, =11600 + MOV X29, #11600 ADD X4, X0, X29 - LDR X29, =11856 + MOV X29, #11856 ADD X5, X0, X29 - LDR X29, =11920 + MOV X29, #11920 ADD X6, X0, X29 - LDR X29, =11936 + MOV X29, #11936 ADD X7, X0, X29 COND_1: CMP X1, #0x400 @@ -611,7 +611,7 @@ RADIX_4_FIRST_ENDS: MOv x30, X3 LSR X5, X5, #2 - LDR X14, =8528 + MOV X14, #8528 ADD X0, X0, X14 OUTER_LOOP_R4: diff --git a/decoder/armv8/ixheaacd_inv_dit_fft_8pt.s b/decoder/armv8/ixheaacd_inv_dit_fft_8pt.s index 51deed7..197a825 100644 --- a/decoder/armv8/ixheaacd_inv_dit_fft_8pt.s +++ b/decoder/armv8/ixheaacd_inv_dit_fft_8pt.s @@ -20,7 +20,7 @@ .global ixheaacd_inv_dit_fft_8pt_armv8 ixheaacd_inv_dit_fft_8pt_armv8: push_v_regs - LDR w3, =0x5A820000 + MOV w3, #0x5A820000 DUP v0.2s, w3 MOV x5, #8 ADD x6, x0, #4 diff --git a/decoder/armv8/ixheaacd_post_twiddle.s b/decoder/armv8/ixheaacd_post_twiddle.s index 2e7f6d4..c28b9da 100644 --- a/decoder/armv8/ixheaacd_post_twiddle.s +++ b/decoder/armv8/ixheaacd_post_twiddle.s @@ -49,7 +49,7 @@ ixheaacd_post_twiddle_armv8: ARM_PROLOGUE: CMP w3, #0x400 - LDR x21, =7500 + MOV x21, #7500 ADD x2, x2, x21 BLT NEXT MOV w4, #50 diff --git a/decoder/armv8/ixheaacd_post_twiddle_overlap.s b/decoder/armv8/ixheaacd_post_twiddle_overlap.s index 8ddce48..b8ee331 100644 --- a/decoder/armv8/ixheaacd_post_twiddle_overlap.s +++ b/decoder/armv8/ixheaacd_post_twiddle_overlap.s @@ -65,7 +65,7 @@ ixheaacd_post_twid_overlap_add_armv8: ADD x6, x6, x9 SUB x6, x6, #4 - LDR w8, =7500 + MOV w8, #7500 sxtw x8, w8 ADD x2, x2, x8 @@ -185,9 +185,9 @@ ARM_PROLOGUE: BGE NEXT2 CMN x8, #1 NEXT2: - LDR x20, =0x80000000 + MOV x20, #0x80000000 csel x7, x20, x7, LT - LDR x20, =0x7fffffff + MOV x20, #0x7fffffff csel x7, x20, x7, GT LSL x20, x7, x11 csel x7, x20, x7, EQ @@ -200,9 +200,9 @@ NEXT2: BGE NEXT3 CMN x8, #1 NEXT3: - LDR x20, =0x80000000 + MOV x20, #0x80000000 csel x12, x20, x12, LT - LDR x20, =0x7fffffff + MOV x20, #0x7fffffff csel x12, x20, x12, GT LSL x20, x12, x11 csel x12, x20, x12, EQ diff --git a/decoder/armv8/ixheaacd_pre_twiddle.s b/decoder/armv8/ixheaacd_pre_twiddle.s index 7fae0bd..7c02ba5 100644 --- a/decoder/armv8/ixheaacd_pre_twiddle.s +++ b/decoder/armv8/ixheaacd_pre_twiddle.s @@ -59,7 +59,7 @@ ixheaacd_pretwiddle_compute_armv8: LSL x7, x4, #4 ADD x7, x2, x7 SUB x7, x7, #4 - LDR x22, =7500 + MOV x22, #7500 ADD x3, x3, x22 MVN w5, w5 ADD w5, w5, #1 diff --git a/decoder/armv8/ixheaacd_qmf_dec_armv8.c b/decoder/armv8/ixheaacd_qmf_dec_armv8.c index 8cfe002..112f138 100644 --- a/decoder/armv8/ixheaacd_qmf_dec_armv8.c +++ b/decoder/armv8/ixheaacd_qmf_dec_armv8.c @@ -48,7 +48,7 @@ #include "ixheaacd_audioobjtypes.h" #define mult16x16_16(a, b) ixheaacd_mult16((a), (b)) -#define mac16x16(a, b, c) ixheaacd_mac16x16in32((a), (b), (c)) +#define mac16x16(a, b, c) ixheaacd_mac16x16in32_sat((a), (b), (c)) #define mpy_32x16(a, b) fixmuldiv2_32x16b((a), (b)) #define mpy_16x16(a, b) ixheaacd_mult16x16in32((a), (b)) #define mpy_32x32(a, b) ixheaacd_mult32((a), (b)) @@ -99,9 +99,13 @@ VOID ixheaacd_dct3_32(WORD32 *input, WORD32 *output, twid_im = *twidle_fwd; twidle_fwd += 3; - *p_out++ = mac32x16in32_dual(temp1[0], twid_re, temp1[1], twid_im); - *p_out++ = msu32x16in32_dual(temp1[0], twid_im, temp1[1], twid_re); + + *p_out++ = ixheaacd_mult32x16in32(temp1[0], twid_re) + + ixheaacd_mult32x16in32(temp1[1], twid_im); + *p_out++ = -ixheaacd_mult32x16in32(temp1[1], twid_re) + + ixheaacd_mult32x16in32(temp1[0], twid_im); } + twid_re = *twidle_fwd++; twid_im = *twidle_fwd; @@ -114,11 +118,14 @@ VOID ixheaacd_dct3_32(WORD32 *input, WORD32 *output, temp1[0] = temp1[1]; - temp2[2] = mac32x16in32_dual(temp1[0], twid_re, temp1[1], twid_im); - temp2[3] = msu32x16in32_dual(temp1[0], twid_im, temp1[1], twid_re); + temp2[2] = ixheaacd_mult32x16in32(temp1[0], twid_re) + + ixheaacd_mult32x16in32(temp1[1], twid_im); + temp2[3] = -ixheaacd_mult32x16in32(temp1[1], twid_re) + + ixheaacd_mult32x16in32(temp1[0], twid_im); ptr_forward = output; ptr_reverse = &output[DCT3_LEN - 1]; + temp2[0] = *ptr_forward++; temp2[1] = *ptr_forward--; @@ -152,8 +159,11 @@ VOID ixheaacd_dct3_32(WORD32 *input, WORD32 *output, temp1[2] = temp2[1] + temp2[3]; temp1[3] = (temp2[1] - temp2[3]); - temp1[4] = mac32x16in32_dual(temp1[0], twid_re, temp1[2], twid_im); - temp1[5] = msu32x16in32_dual(temp1[0], twid_im, temp1[2], twid_re); + + temp1[4] = ixheaacd_mult32x16in32(temp1[0], twid_re) + + ixheaacd_mult32x16in32(temp1[2], twid_im); + temp1[5] = -ixheaacd_mult32x16in32(temp1[2], twid_re) + + ixheaacd_mult32x16in32(temp1[0], twid_im); temp1[1] >>= 1; temp1[3] >>= 1; @@ -169,7 +179,7 @@ VOID ixheaacd_dct3_32(WORD32 *input, WORD32 *output, temp2[3] = *ptr_reverse--; temp2[2] = *ptr_reverse++; - twid_re = *twidle_rev; + twid_re = -*twidle_rev; twidle_rev -= 2; twid_im = *twidle_fwd; twidle_fwd += 2; @@ -180,8 +190,10 @@ VOID ixheaacd_dct3_32(WORD32 *input, WORD32 *output, temp1[2] = temp2[1] + temp2[3]; temp1[3] = (temp2[1] - temp2[3]); - temp1[4] = -mac32x16in32_dual(temp1[0], twid_re, temp1[2], twid_im); - temp1[5] = msu32x16in32_dual(temp1[0], twid_im, temp1[2], twid_re); + temp1[4] = ixheaacd_mult32x16in32(temp1[0], twid_re) - + ixheaacd_mult32x16in32(temp1[2], twid_im); + temp1[5] = ixheaacd_mult32x16in32(temp1[2], twid_re) + + ixheaacd_mult32x16in32(temp1[0], twid_im); temp1[1] >>= 1; temp1[3] >>= 1; @@ -1322,4 +1334,4 @@ VOID ixheaacd_radix4bfly(const WORD16 *w, WORD32 *x, WORD32 index1, x += fft_jmp; w_ptr = w_ptr - fft_jmp; } -} +} \ No newline at end of file diff --git a/decoder/drc_src/impd_drc_api.c b/decoder/drc_src/impd_drc_api.c index 0b40d94..4fea3de 100644 --- a/decoder/drc_src/impd_drc_api.c +++ b/decoder/drc_src/impd_drc_api.c @@ -64,8 +64,41 @@ IA_ERRORCODE impd_drc_set_default_config(ia_drc_api_struct *p_obj_drc); IA_ERRORCODE impd_drc_set_struct_pointer(ia_drc_api_struct *p_obj_drc); IA_ERRORCODE impd_process_time_domain(ia_drc_api_struct *p_obj_drc); +#define SUBBAND_BUF_SIZE \ + NUM_ELE_IN_CPLX_NUM *MAX_CHANNEL_COUNT * sizeof(FLOAT32 *) + \ + (MAX_SUBBAND_DELAY + MAX_DRC_FRAME_SIZE) * MAX_CHANNEL_COUNT * \ + sizeof(FLOAT32) * NUM_ELE_IN_CPLX_NUM + #define NUM_DRC_TABLES 4 -#define SCRATCH_MEM_SIZE 1024 * 256 * 64 +#define SCRATCH_MEM_SIZE \ + (AUDIO_CODEC_FRAME_SIZE_MAX * MAX_CHANNEL_COUNT * sizeof(FLOAT32) * \ + NUM_ELE_IN_CPLX_NUM) + +#define PERSIST_MEM_SIZE \ + (sizeof(ia_drc_state_struct) + sizeof(ia_drc_bits_dec_struct) + \ + sizeof(ia_drc_gain_dec_struct) * 2 + \ + sizeof(ia_drc_loudness_info_set_struct) + sizeof(ia_drc_gain_struct) + \ + sizeof(ia_drc_interface_struct) + sizeof(ia_drc_config) + \ + sizeof(ia_drc_sel_pro_struct) + sizeof(ia_drc_sel_proc_params_struct) + \ + sizeof(ia_drc_sel_proc_output_struct) + \ + sizeof(ia_drc_peak_limiter_struct) + sizeof(ia_drc_peak_limiter_struct) + \ + sizeof(ia_drc_qmf_filt_struct) + ANALY_BUF_SIZE + SYNTH_BUF_SIZE + \ + PEAK_LIM_BUF_SIZE + MAX_BS_BUF_SIZE + /*DRC Config Bitstream*/ \ + MAX_DRC_CONFG_BUF_SIZE + /*DRC loudness info Bitstream*/ \ + MAX_LOUD_INFO_BUF_SIZE + /*DRC interface Bitstream*/ \ + MAX_INTERFACE_BUF_SIZE + \ + NUM_GAIN_DEC_INSTANCES * \ + (SEL_DRC_COUNT * sizeof(ia_interp_buf_struct) * MAX_GAIN_ELE_COUNT + \ + sizeof(ia_eq_set_struct) + /*non_interleaved_audio*/ \ + MAX_CHANNEL_COUNT * sizeof(FLOAT32 *) + \ + MAX_DRC_FRAME_SIZE * sizeof(FLOAT32) * \ + MAX_CHANNEL_COUNT + /*audio_in_out_buf ptr*/ \ + MAX_CHANNEL_COUNT * sizeof(FLOAT32 *) + /*audio_io_buffer_delayed*/ \ + MAX_CHANNEL_COUNT * sizeof(FLOAT32 *) + \ + MAX_DRC_FRAME_SIZE * sizeof(FLOAT32) * \ + MAX_CHANNEL_COUNT + /*subband band buffer ptr*/ \ + NUM_ELE_IN_CPLX_NUM * MAX_CHANNEL_COUNT * sizeof(FLOAT32 *) + \ + SUBBAND_BUF_SIZE + (PARAM_DRC_MAX_BUF_SZ * MAX_CHANNEL_COUNT))) IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_drc_dec_obj, WORD32 i_cmd, WORD32 i_idx, pVOID pv_value) { @@ -111,8 +144,7 @@ IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_drc_dec_obj, WORD32 i_cmd, WORD32 i_idx, break; } case IA_API_CMD_GET_API_SIZE: { - *pui_value = sizeof(ia_drc_api_struct) + - (sizeof(ia_drc_state_struct) + 8) + 8080 * 1024; + *pui_value = sizeof(ia_drc_api_struct); break; } @@ -120,7 +152,8 @@ IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_drc_dec_obj, WORD32 i_cmd, WORD32 i_idx, switch (i_idx) { case IA_CMD_TYPE_INIT_SET_BUFF_PTR: { p_obj_drc->p_state->persistant_ptr = - p_obj_drc->pp_mem[IA_DRC_PERSIST_IDX]; + (UWORD8 *)p_obj_drc->pp_mem[IA_DRC_PERSIST_IDX] + + sizeof(ia_drc_state_struct); impd_drc_set_struct_pointer(p_obj_drc); break; @@ -130,11 +163,6 @@ IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_drc_dec_obj, WORD32 i_cmd, WORD32 i_idx, break; } case IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS: { - p_obj_drc->p_state = - (ia_drc_state_struct *)((SIZE_T)p_obj_drc + 8000 * 1024); - p_obj_drc->p_mem_info = - (ia_mem_info_struct *)((SIZE_T)p_obj_drc + 8002 * 1024); - p_obj_drc->pp_mem = (pVOID)((SIZE_T)p_obj_drc + 8006 * 1024); impd_drc_fill_mem_tables(p_obj_drc); break; } @@ -402,9 +430,18 @@ IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_drc_dec_obj, WORD32 i_cmd, WORD32 i_idx, break; } case IA_API_CMD_GET_MEMTABS_SIZE: { + *pui_value = + (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) * (NUM_DRC_TABLES); break; } case IA_API_CMD_SET_MEMTABS_PTR: { + if (ps_value == NULL) return IA_DRC_DEC_API_FATAL_MEM_ALLOC; + memset(ps_value, 0, + (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) * (NUM_DRC_TABLES)); + p_obj_drc->p_mem_info = (ia_mem_info_struct *)(ps_value); + p_obj_drc->pp_mem = + (pVOID)((SIZE_T)p_obj_drc->p_mem_info + + (NUM_DRC_TABLES * sizeof(*(p_obj_drc->p_mem_info)))); break; } case IA_API_CMD_GET_N_MEMTABS: { @@ -418,7 +455,9 @@ IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_drc_dec_obj, WORD32 i_cmd, WORD32 i_idx, case IA_API_CMD_EXECUTE: { switch (i_idx) { case IA_CMD_TYPE_DO_EXECUTE: { - if (p_obj_drc->str_config.dec_type == DEC_TYPE_TD) { + if (!p_obj_drc->p_state->ui_init_done) { + error_code = IA_FATAL_ERROR; + } else if (p_obj_drc->str_config.dec_type == DEC_TYPE_TD) { error_code = impd_process_time_domain(p_obj_drc); } else if (p_obj_drc->str_config.dec_type == DEC_TYPE_QMF64) { error_code = impd_init_process_audio_main_qmf(p_obj_drc); @@ -524,8 +563,6 @@ IA_ERRORCODE impd_drc_mem_api(ia_drc_api_struct *p_obj_drc, WORD32 i_cmd, break; } case IA_API_CMD_SET_MEM_PTR: { - pWORD8 pbtemp; - UWORD32 sz; if (pv_value == 0) { return (-1); } @@ -533,10 +570,11 @@ IA_ERRORCODE impd_drc_mem_api(ia_drc_api_struct *p_obj_drc, WORD32 i_cmd, return (-1); } p_obj_drc->pp_mem[i_idx] = pv_value; - pbtemp = p_obj_drc->pp_mem[i_idx]; - sz = p_obj_drc->p_mem_info[i_idx].ui_size; - - memset(pbtemp, 0, sz); + memset(p_obj_drc->pp_mem[i_idx], 0, p_obj_drc->p_mem_info[i_idx].ui_size); + if (IA_MEMTYPE_PERSIST == i_idx) { + p_obj_drc->p_state = pv_value; + } + break; } case IA_API_CMD_SET_MEM_PLACEMENT: { } @@ -548,7 +586,8 @@ IA_ERRORCODE impd_drc_fill_mem_tables(ia_drc_api_struct *p_obj_drc) { ia_mem_info_struct *p_mem_info; { p_mem_info = &p_obj_drc->p_mem_info[IA_DRC_PERSIST_IDX]; - p_mem_info->ui_size = 64 * 1024 * 1024; + memset(p_mem_info, 0, sizeof(*p_mem_info)); + p_mem_info->ui_size = PERSIST_MEM_SIZE; p_mem_info->ui_alignment = 8; p_mem_info->ui_type = IA_MEMTYPE_PERSIST; p_mem_info->ui_placement[0] = 0; @@ -559,6 +598,7 @@ IA_ERRORCODE impd_drc_fill_mem_tables(ia_drc_api_struct *p_obj_drc) { } { p_mem_info = &p_obj_drc->p_mem_info[IA_DRC_INPUT_IDX]; + memset(p_mem_info, 0, sizeof(*p_mem_info)); p_mem_info->ui_size = p_obj_drc->str_config.frame_size * (p_obj_drc->str_config.pcm_size >> 3) * p_obj_drc->str_config.num_ch_in; @@ -572,6 +612,7 @@ IA_ERRORCODE impd_drc_fill_mem_tables(ia_drc_api_struct *p_obj_drc) { } { p_mem_info = &p_obj_drc->p_mem_info[IA_DRC_OUTPUT_IDX]; + memset(p_mem_info, 0, sizeof(*p_mem_info)); p_mem_info->ui_size = p_obj_drc->str_config.frame_size * (p_obj_drc->str_config.pcm_size >> 3) * p_obj_drc->str_config.num_ch_in; @@ -585,6 +626,7 @@ IA_ERRORCODE impd_drc_fill_mem_tables(ia_drc_api_struct *p_obj_drc) { } { p_mem_info = &p_obj_drc->p_mem_info[IA_DRC_SCRATCH_IDX]; + memset(p_mem_info, 0, sizeof(*p_mem_info)); p_mem_info->ui_size = SCRATCH_MEM_SIZE; p_mem_info->ui_alignment = 8; p_mem_info->ui_type = IA_MEMTYPE_SCRATCH; diff --git a/decoder/drc_src/impd_drc_common.h b/decoder/drc_src/impd_drc_common.h index 2da2542..2afe708 100644 --- a/decoder/drc_src/impd_drc_common.h +++ b/decoder/drc_src/impd_drc_common.h @@ -30,9 +30,10 @@ extern "C" { #define ENABLE_ADDITIONAL_TESTS 1 -#define SPEAKER_POS_COUNT_MAX 128 +#define SPEAKER_POS_COUNT_MAX (8) // 128 #define DOWNMIX_COEFF_COUNT_MAX 32 * 32 -#define MAX_CHANNEL_COUNT 128 +#define MAX_CHANNEL_COUNT (8) // 128 +#define MAX_SUBBAND_CHANNEL_COUNT (128) #define BAND_COUNT_MAX 8 #define SEQUENCE_COUNT_MAX 24 #define GAIN_SET_COUNT_MAX SEQUENCE_COUNT_MAX @@ -50,6 +51,42 @@ extern "C" { #define DOWNMIX_ID_COUNT_MAX 8 #define MAX_SIGNAL_DELAY 4500 +#define NUM_ELE_IN_CPLX_NUM 2 +#define MAX_BS_BUF_SIZE 768 +#define MAX_DRC_CONFG_BUF_SIZE MAX_BS_BUF_SIZE +#define MAX_LOUD_INFO_BUF_SIZE MAX_BS_BUF_SIZE +#define MAX_INTERFACE_BUF_SIZE MAX_BS_BUF_SIZE +#define MAX_GAIN_ELE_COUNT 15 /*MAX 4-bit Value*/ + +#define NUM_GAIN_DEC_INSTANCES 2 + +#define MAX_DRC_FRAME_SIZE AUDIO_CODEC_FRAME_SIZE_MAX +#define ANALY_BUF_SIZE \ + (AUDIO_CODEC_FRAME_SIZE_MAX * MAX_CHANNEL_COUNT * sizeof(FLOAT32) * \ + NUM_ELE_IN_CPLX_NUM) +#define SYNTH_BUF_SIZE \ + (AUDIO_CODEC_FRAME_SIZE_MAX * MAX_CHANNEL_COUNT * sizeof(FLOAT32) * \ + NUM_ELE_IN_CPLX_NUM) +#define PEAK_LIM_BUF_SIZE \ + (AUDIO_CODEC_FRAME_SIZE_MAX * MAX_CHANNEL_COUNT * sizeof(FLOAT32) * \ + NUM_ELE_IN_CPLX_NUM) + +/*7 bits read from the bitstream*/ +#define MAX_PARAM_DRC_LOOK_AHEAD_VAL 127 + +#define MAX_PARAM_DRC_LIM_ATTACK_VAL MAX_PARAM_DRC_LOOK_AHEAD_VAL +#define MAX_SAMP_FREQ_IN_KHZ 96 +#define MAX_ATTACK_VAL (MAX_PARAM_DRC_LOOK_AHEAD_VAL * MAX_SAMP_FREQ_IN_KHZ) + +/*int(sqrt(MAX_ATTACK_VAL + 1))*/ +#define MAX_SEC_LEN 110 +#define MAX_NUMBUF_SEC_VAL (MAX_ATTACK_VAL / MAX_SEC_LEN) + +/*(MAX_NUMBUF_SEC_VAL * MAX_SEC_LEN)*/ +#define PARAM_DRC_MAX_BUF_SZ 110 + +#define MAX_SUBBAND_DELAY (MAX_SIGNAL_DELAY / AUDIO_CODEC_SUBBAND_COUNT_QMF64) + #define DRC_BAND_COUNT_MAX BAND_COUNT_MAX #define SPLIT_CHARACTERISTIC_COUNT_MAX 8 #define GAIN_SET_COUNT_MAX SEQUENCE_COUNT_MAX @@ -150,6 +187,7 @@ extern "C" { #define PARAM_DRC_TYPE_LIM_THRESHOLD_DEFAULT (-1.f) #define PARAM_DRC_TYPE_LIM_ATTACK_DEFAULT 5 #define PARAM_DRC_TYPE_LIM_RELEASE_DEFAULT 50 +#define MAX_LOUDNESS_INFO_COUNT (16) #define MAX_LOUDNESS_INFO_COUNT (16) @@ -200,7 +238,7 @@ typedef struct ia_drc_sel_proc_output_struct { WORD32 target_channel_count; WORD32 target_layout; WORD32 downmix_matrix_present; - FLOAT32 downmix_matrix[MAX_CHANNEL_COUNT][MAX_CHANNEL_COUNT]; + FLOAT32 downmix_matrix[MAX_SUBBAND_CHANNEL_COUNT][MAX_SUBBAND_CHANNEL_COUNT]; FLOAT32 boost; FLOAT32 compress; diff --git a/decoder/drc_src/impd_drc_dynamic_payload.c b/decoder/drc_src/impd_drc_dynamic_payload.c index f93f49e..dca5466 100644 --- a/decoder/drc_src/impd_drc_dynamic_payload.c +++ b/decoder/drc_src/impd_drc_dynamic_payload.c @@ -1082,6 +1082,9 @@ WORD32 impd_parse_eq_instructions( str_eq_instructions->eq_set_id = (temp >> 5) & 0x3F; + if (str_eq_instructions->eq_set_id >= EQ_INSTRUCTIONS_COUNT_MAX) + return UNEXPECTED_ERROR; + str_eq_instructions->eq_set_complexity_level = (temp >> 1) & 0x0F; dmix_id_present = temp & 0x01; diff --git a/decoder/drc_src/impd_drc_eq.c b/decoder/drc_src/impd_drc_eq.c index 4acc37b..3ebb366 100644 --- a/decoder/drc_src/impd_drc_eq.c +++ b/decoder/drc_src/impd_drc_eq.c @@ -1342,30 +1342,28 @@ WORD32 impd_process_eq_set_time_domain(ia_eq_set_struct* pstr_eq_set, WORD32 channel, FLOAT32* ptr_audio_in, FLOAT32* ptr_audio_out, WORD32 frame_size) { - WORD32 g = pstr_eq_set->eq_ch_group_of_channel[channel], i, j; - // FLOAT32 sum = 0.0f; - // FLOAT32 temp1 = 0.0f; + WORD32 i, j, g = 0; - if (pstr_eq_set == NULL || g < 0) return 0; + if (pstr_eq_set == NULL) return 0; - if (pstr_eq_set->domain | EQ_FILTER_DOMAIN_TIME) { - for (i = 0; i < frame_size; i++) { - impd_eq_filt_element_process( - (pstr_eq_set->filt_cascade_td[g].pstr_eq_filt_block), channel, - ptr_audio_in[i], &ptr_audio_out[i], - pstr_eq_set->filt_cascade_td[g].block_count); + g = pstr_eq_set->eq_ch_group_of_channel[channel]; - for (j = 0; j < pstr_eq_set->filt_cascade_td[g].num_ph_align_filt; j++) { - impd_phase_align_filt_process( - &pstr_eq_set->filt_cascade_td[g].ph_alignment_filt[j], channel, - &ptr_audio_out[i]); - } + if (g < 0) return 0; - ptr_audio_out[i] = ptr_audio_out[i] * - pstr_eq_set->filt_cascade_td[g].cascade_gain_linear; + for (i = 0; i < frame_size; i++) { + impd_eq_filt_element_process( + (pstr_eq_set->filt_cascade_td[g].pstr_eq_filt_block), channel, + ptr_audio_in[i], &ptr_audio_out[i], + pstr_eq_set->filt_cascade_td[g].block_count); + + for (j = 0; j < pstr_eq_set->filt_cascade_td[g].num_ph_align_filt; j++) { + impd_phase_align_filt_process( + &pstr_eq_set->filt_cascade_td[g].ph_alignment_filt[j], channel, + &ptr_audio_out[i]); } - } else { - return -1; + + ptr_audio_out[i] = + ptr_audio_out[i] * pstr_eq_set->filt_cascade_td[g].cascade_gain_linear; } return 0; } diff --git a/decoder/drc_src/impd_drc_eq.h b/decoder/drc_src/impd_drc_eq.h index dfcf0aa..d45e7ed 100644 --- a/decoder/drc_src/impd_drc_eq.h +++ b/decoder/drc_src/impd_drc_eq.h @@ -24,7 +24,6 @@ #endif #define EQ_CHANNEL_COUNT_MAX 8 -#define EQ_AUDIO_DELAY_MAX 1024 #define EQ_FIR_FILTER_SIZE_MAX 128 #define EQ_SUBBAND_COUNT_MAX 256 #define EQ_INTERMEDIATE_2ND_ORDER_PARAMS_COUNT_MAX 32 @@ -38,6 +37,10 @@ #define EQ_FILTER_DOMAIN_TIME (1 << 0) #define EQ_FILTER_DOMAIN_SUBBAND (1 << 1) +#define EQ_REAL_ZERO_CNT 63 /*Max Value of a 6 bit number*/ +#define EQ_GENERIC_ZERO_CNT 63 /*Max Value of a 6 bit number*/ +#define EQ_AUDIO_DELAY_MAX (EQ_REAL_ZERO_CNT + (EQ_GENERIC_ZERO_CNT * 2)) + #ifdef __cplusplus extern "C" { #endif diff --git a/decoder/drc_src/impd_drc_gain_decoder.c b/decoder/drc_src/impd_drc_gain_decoder.c index 4b48f54..829f576 100644 --- a/decoder/drc_src/impd_drc_gain_decoder.c +++ b/decoder/drc_src/impd_drc_gain_decoder.c @@ -187,7 +187,7 @@ IA_ERRORCODE impd_init_drc_decode_post_config( } p_drc_gain_dec_structs->eq_set = (ia_eq_set_struct*)*mem_ptr; - *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + sizeof(ia_eq_set_struct) + 32); + *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + sizeof(ia_eq_set_struct)); if (err_code) return (err_code); @@ -217,14 +217,13 @@ IA_ERRORCODE impd_init_drc_decode_post_config( p_drc_gain_dec_structs->audio_band_buffer.non_interleaved_audio = *mem_ptr; *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + - (maxMultibandAudioSignalCount * sizeof(FLOAT32*)) + 32); + (maxMultibandAudioSignalCount * sizeof(FLOAT32*))); for (i = 0; i < maxMultibandAudioSignalCount; i++) { p_drc_gain_dec_structs->audio_band_buffer.non_interleaved_audio[i] = *mem_ptr; - *mem_ptr = - (pVOID)((SIZE_T)*mem_ptr + - (p_drc_params_struct->drc_frame_size * sizeof(FLOAT32)) + 32); + *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + + (p_drc_params_struct->drc_frame_size * sizeof(FLOAT32))); } p_drc_gain_dec_structs->audio_band_buffer.multiband_audio_sig_count = maxMultibandAudioSignalCount; @@ -235,21 +234,18 @@ IA_ERRORCODE impd_init_drc_decode_post_config( if (p_drc_params_struct->sub_band_domain_mode == SUBBAND_DOMAIN_MODE_OFF && p_audio_in_out_buf->audio_delay_samples) { p_audio_in_out_buf->audio_io_buffer_delayed = *mem_ptr; - *mem_ptr = - (pVOID)((SIZE_T)*mem_ptr + - (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*)) + 32); + *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + + (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*))); p_audio_in_out_buf->audio_in_out_buf = *mem_ptr; - *mem_ptr = - (pVOID)((SIZE_T)*mem_ptr + - (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*)) + 32); + *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + + (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*))); for (i = 0; i < p_audio_in_out_buf->audio_num_chan; i++) { p_audio_in_out_buf->audio_io_buffer_delayed[i] = *mem_ptr; *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + ((p_audio_in_out_buf->frame_size + p_audio_in_out_buf->audio_delay_samples) * - sizeof(FLOAT32*)) + - 32); + sizeof(FLOAT32*))); p_audio_in_out_buf->audio_in_out_buf[i] = &p_audio_in_out_buf->audio_io_buffer_delayed [i][p_audio_in_out_buf->audio_delay_samples]; @@ -258,35 +254,29 @@ IA_ERRORCODE impd_init_drc_decode_post_config( if (p_drc_params_struct->sub_band_domain_mode != SUBBAND_DOMAIN_MODE_OFF && p_audio_in_out_buf->audio_delay_sub_band_samples) { p_audio_in_out_buf->audio_buffer_delayed_real = *mem_ptr; - *mem_ptr = - (pVOID)((SIZE_T)*mem_ptr + - (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*)) + 32); + *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + + (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*))); p_audio_in_out_buf->audio_buffer_delayed_imag = *mem_ptr; - *mem_ptr = - (pVOID)((SIZE_T)*mem_ptr + - (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*)) + 32); + *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + + (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*))); p_audio_in_out_buf->audio_real_buff = *mem_ptr; - *mem_ptr = - (pVOID)((SIZE_T)*mem_ptr + - (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*)) + 32); + *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + + (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*))); p_audio_in_out_buf->audio_imag_buff = *mem_ptr; - *mem_ptr = - (pVOID)((SIZE_T)*mem_ptr + - (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*)) + 32); + *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + + (p_audio_in_out_buf->audio_num_chan * sizeof(FLOAT32*))); for (i = 0; i < p_audio_in_out_buf->audio_num_chan; i++) { p_audio_in_out_buf->audio_buffer_delayed_real[i] = *mem_ptr; *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + ((p_audio_in_out_buf->audio_sub_band_frame_size + p_audio_in_out_buf->audio_delay_sub_band_samples) * - sizeof(FLOAT32*)) + - 32); + sizeof(FLOAT32*))); p_audio_in_out_buf->audio_buffer_delayed_imag[i] = *mem_ptr; *mem_ptr = (pVOID)((SIZE_T)*mem_ptr + ((p_audio_in_out_buf->audio_sub_band_frame_size + p_audio_in_out_buf->audio_delay_sub_band_samples) * - sizeof(FLOAT32*)) + - 32); + sizeof(FLOAT32*))); p_audio_in_out_buf->audio_real_buff[i] = &p_audio_in_out_buf->audio_buffer_delayed_real diff --git a/decoder/drc_src/impd_drc_init.c b/decoder/drc_src/impd_drc_init.c index cd6d467..b4711c8 100644 --- a/decoder/drc_src/impd_drc_init.c +++ b/decoder/drc_src/impd_drc_init.c @@ -22,7 +22,7 @@ #include #include "impd_type_def.h" #include "impd_error_standards.h" - +#include #include "impd_drc_extr_delta_coded_info.h" #include "impd_drc_common.h" #include "impd_drc_struct.h" @@ -62,8 +62,6 @@ impd_drc_dec_interface_add_effect_type( ia_drc_interface_struct *pstr_drc_interface, WORD32 drc_effect_type, WORD32 target_loudness, WORD32 loud_norm); -#define NUM_GAIN_DEC_INSTANCES 2 - #define BITSTREAM_FILE_FORMAT_SPLIT 1 #define LIM_DEFAULT_THRESHOLD (0.89125094f) @@ -91,6 +89,7 @@ static WORD32 impd_match_downmix(WORD32 downmix_id, WORD32 dec_downmix_id) { } IA_ERRORCODE impd_drc_set_default_config(ia_drc_api_struct *p_obj_drc) { + memset(p_obj_drc, 0, sizeof(*p_obj_drc)); p_obj_drc->str_config.bitstream_file_format = 0; p_obj_drc->str_config.dec_type = 0; p_obj_drc->str_config.sub_band_domain_mode = 0; @@ -279,79 +278,73 @@ IA_ERRORCODE impd_drc_set_struct_pointer(ia_drc_api_struct *p_obj_drc) { p_obj_drc->str_payload.pstr_bitstream_dec = (ia_drc_bits_dec_struct *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + sizeof(ia_drc_bits_dec_struct) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_bits_dec_struct); p_obj_drc->str_payload.pstr_gain_dec[0] = (ia_drc_gain_dec_struct *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + sizeof(ia_drc_gain_dec_struct) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_gain_dec_struct); p_obj_drc->str_payload.pstr_gain_dec[1] = (ia_drc_gain_dec_struct *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + sizeof(ia_drc_gain_dec_struct) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_gain_dec_struct); p_obj_drc->str_payload.pstr_loudness_info = (ia_drc_loudness_info_set_struct *)persistant_ptr; - persistant_ptr = - (SIZE_T)persistant_ptr + sizeof(ia_drc_loudness_info_set_struct) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_loudness_info_set_struct); p_obj_drc->str_payload.pstr_drc_gain = (ia_drc_gain_struct *)persistant_ptr; - ; - persistant_ptr = (SIZE_T)persistant_ptr + sizeof(ia_drc_gain_struct) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_gain_struct); p_obj_drc->str_payload.pstr_drc_interface = (ia_drc_interface_struct *)persistant_ptr; - persistant_ptr = - (SIZE_T)persistant_ptr + sizeof(ia_drc_interface_struct) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_interface_struct); p_obj_drc->str_payload.pstr_drc_config = (ia_drc_config *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + sizeof(ia_drc_config) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_config); p_obj_drc->str_payload.pstr_selection_proc = (ia_drc_sel_pro_struct *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + sizeof(ia_drc_sel_pro_struct) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_sel_pro_struct); p_obj_drc->str_bit_handler.it_bit_buf = (UWORD8 *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + 32 * 1024; /*varify the sizelater*/ + persistant_ptr = persistant_ptr + MAX_BS_BUF_SIZE; p_obj_drc->str_payload.pstr_drc_sel_proc_params = (ia_drc_sel_proc_params_struct *)persistant_ptr; - persistant_ptr = - (SIZE_T)persistant_ptr + sizeof(ia_drc_sel_proc_params_struct); + persistant_ptr = persistant_ptr + sizeof(ia_drc_sel_proc_params_struct); p_obj_drc->str_payload.pstr_drc_sel_proc_output = (ia_drc_sel_proc_output_struct *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + - sizeof(ia_drc_sel_proc_output_struct) + 16 * 1024; + persistant_ptr = persistant_ptr + sizeof(ia_drc_sel_proc_output_struct); p_obj_drc->str_bit_handler.bitstream_drc_config = (UWORD8 *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + 8 * 1024; + persistant_ptr = persistant_ptr + MAX_BS_BUF_SIZE; p_obj_drc->str_bit_handler.bitstream_loudness_info = (UWORD8 *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + 8 * 1024; + persistant_ptr = persistant_ptr + MAX_BS_BUF_SIZE; p_obj_drc->str_bit_handler.bitstream_unidrc_interface = (UWORD8 *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + 8 * 1024; + persistant_ptr = persistant_ptr + MAX_BS_BUF_SIZE; p_obj_drc->str_payload.pstr_peak_limiter = (ia_drc_peak_limiter_struct *)persistant_ptr; - persistant_ptr = - (SIZE_T)persistant_ptr + sizeof(ia_drc_peak_limiter_struct) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_peak_limiter_struct); p_obj_drc->str_payload.pstr_peak_limiter->buffer = (FLOAT32 *)((SIZE_T)p_obj_drc->str_payload.pstr_peak_limiter + - sizeof(ia_drc_peak_limiter_struct) + 32); - persistant_ptr = (SIZE_T)persistant_ptr + 16 * 1024; + sizeof(ia_drc_peak_limiter_struct)); + persistant_ptr = persistant_ptr + PEAK_LIM_BUF_SIZE; p_obj_drc->str_payload.pstr_qmf_filter = (ia_drc_qmf_filt_struct *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + sizeof(ia_drc_qmf_filt_struct) + 32; + persistant_ptr = persistant_ptr + sizeof(ia_drc_qmf_filt_struct); p_obj_drc->str_payload.pstr_qmf_filter->ana_buff = (FLOAT64 *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + 16 * 1024; + persistant_ptr = persistant_ptr + ANALY_BUF_SIZE; p_obj_drc->str_payload.pstr_qmf_filter->syn_buff = (FLOAT64 *)persistant_ptr; - persistant_ptr = (SIZE_T)persistant_ptr + 16 * 1024; + persistant_ptr = persistant_ptr + SYNTH_BUF_SIZE; p_obj_drc->p_state->persistant_ptr = (pVOID)persistant_ptr; return IA_NO_ERROR; @@ -464,6 +457,7 @@ IA_ERRORCODE impd_drc_init(ia_drc_api_struct *p_obj_drc) { p_obj_drc->str_bit_handler.num_bytes_bs_drc_config); if (err_code == 1) { + memset(p_obj_drc->str_payload.pstr_drc_config, 0, sizeof(ia_drc_config)); err_code = impd_drc_set_default_bitstream_config( p_obj_drc->str_payload.pstr_drc_config); p_obj_drc->str_payload.pstr_drc_config->channel_layout diff --git a/decoder/drc_src/impd_drc_parametric_dec.c b/decoder/drc_src/impd_drc_parametric_dec.c index 5b3cb4e..e4b3b4a 100644 --- a/decoder/drc_src/impd_drc_parametric_dec.c +++ b/decoder/drc_src/impd_drc_parametric_dec.c @@ -206,11 +206,11 @@ WORD32 impd_init_parametric_drc_feed_fwd( return 0; } -WORD32 impd_init_parametric_drc_lim( +VOID impd_init_parametric_drc_lim( ia_drc_config* pstr_drc_config, WORD32 instance_idx, WORD32 ch_count_from_dwnmix_id, ia_parametric_drc_params_struct* p_parametricdrc_params, pVOID* mem_ptr) { - WORD32 err = 0, i = 0; + WORD32 i = 0; UWORD32 j; UWORD32 attack, sec_len; @@ -290,10 +290,6 @@ WORD32 impd_init_parametric_drc_lim( j++) { pstr_parametric_lim_type_drc_params->max_buf[j] = 0.f; } - - if (err) return (err); - - return 0; } WORD32 impd_init_parametric_drcInstance( @@ -332,11 +328,9 @@ WORD32 impd_init_parametric_drcInstance( p_parametricdrc_params->str_parametric_drc_instance_params[instance_idx] .str_spline_nodes.num_nodes = p_parametricdrc_params->drc_frame_size; - err = impd_init_parametric_drc_lim(pstr_drc_config, instance_idx, - ch_count_from_dwnmix_id, - p_parametricdrc_params, mem_ptr); - - if (err) return (err); + impd_init_parametric_drc_lim(pstr_drc_config, instance_idx, + ch_count_from_dwnmix_id, + p_parametricdrc_params, mem_ptr); } else { return (UNEXPECTED_ERROR); diff --git a/decoder/drc_src/impd_drc_selection_process.c b/decoder/drc_src/impd_drc_selection_process.c index 53f76b0..57f8b9c 100644 --- a/decoder/drc_src/impd_drc_selection_process.c +++ b/decoder/drc_src/impd_drc_selection_process.c @@ -170,27 +170,26 @@ impd_drc_uni_sel_proc_process( for (i = SUB_DRC_COUNT - 1; i >= 0; i--) { WORD32 drc_instructions_index = pstr_drc_uni_sel_proc->drc_instructions_index[i]; - ia_drc_instructions_struct str_drc_instruction_str; + if (drc_instructions_index < 0) continue; - str_drc_instruction_str = - pstr_drc_uni_sel_proc->drc_config - .str_drc_instruction_str[drc_instructions_index]; + ia_drc_instructions_struct* str_drc_instruction_str = + &(pstr_drc_uni_sel_proc->drc_config + .str_drc_instruction_str[drc_instructions_index]); - if (drc_instructions_index >= 0 && - str_drc_instruction_str.drc_set_id > 0) { + if (str_drc_instruction_str->drc_set_id > 0) { pstr_drc_uni_sel_proc->uni_drc_sel_proc_output .sel_drc_set_ids[activeDrcSetIndex] = - str_drc_instruction_str.drc_set_id; + str_drc_instruction_str->drc_set_id; - if ((i == 3) && (str_drc_instruction_str.drc_set_effect & + if ((i == 3) && (str_drc_instruction_str->drc_set_effect & (EFFECT_BIT_DUCK_SELF | EFFECT_BIT_DUCK_OTHER))) { pstr_drc_uni_sel_proc->uni_drc_sel_proc_output .sel_downmix_ids[activeDrcSetIndex] = 0; } else { - if (str_drc_instruction_str.drc_apply_to_dwnmix == 1) { + if (str_drc_instruction_str->drc_apply_to_dwnmix == 1) { pstr_drc_uni_sel_proc->uni_drc_sel_proc_output .sel_downmix_ids[activeDrcSetIndex] = - str_drc_instruction_str.downmix_id[0]; + str_drc_instruction_str->downmix_id[0]; } else { pstr_drc_uni_sel_proc->uni_drc_sel_proc_output .sel_downmix_ids[activeDrcSetIndex] = 0; @@ -235,10 +234,12 @@ impd_drc_uni_sel_proc_process( .loudness_norm_gain_modification_db; } for (i = 0; i < 2; i++) { - pstr_drc_uni_sel_proc->uni_drc_sel_proc_output.sel_eq_set_ids[i] = - pstr_drc_uni_sel_proc->drc_config.str_drc_config_ext - .str_eq_instructions[pstr_drc_uni_sel_proc->eq_inst_index[i]] - .eq_set_id; + if (pstr_drc_uni_sel_proc->eq_inst_index[i] >= 0) { + pstr_drc_uni_sel_proc->uni_drc_sel_proc_output.sel_eq_set_ids[i] = + pstr_drc_uni_sel_proc->drc_config.str_drc_config_ext + .str_eq_instructions[pstr_drc_uni_sel_proc->eq_inst_index[i]] + .eq_set_id; + } } if (pstr_drc_uni_sel_proc->loud_eq_inst_index_sel >= 0) { pstr_drc_uni_sel_proc->uni_drc_sel_proc_output.sel_loud_eq_id = @@ -695,7 +696,7 @@ WORD32 impd_manage_drc_complexity(ia_drc_sel_pro_struct* pstr_drc_uni_sel_proc, &pstr_drc_uni_sel_proc->uni_drc_sel_proc_params; impd_select_drc_coeff3(pstr_drc_config, &str_p_loc_drc_coefficients_uni_drc); - + if (str_p_loc_drc_coefficients_uni_drc == NULL) return UNEXPECTED_ERROR; for (i = 0; i < pstr_drc_config->drc_instructions_uni_drc_count; i++) { str_drc_instruction_str = &pstr_drc_config->str_drc_instruction_str[i]; if (str_drc_instruction_str->no_independent_use) continue; @@ -900,6 +901,8 @@ WORD32 impd_manage_complexity(ia_drc_sel_pro_struct* pstr_drc_uni_sel_proc, impd_select_drc_coeff3(pstr_drc_config, &str_p_loc_drc_coefficients_uni_drc); + if (str_p_loc_drc_coefficients_uni_drc == NULL) return UNEXPECTED_ERROR; + for (p = 0; p < 4; p++) { if (pstr_drc_uni_sel_proc->uni_drc_sel_proc_output.sel_drc_set_ids[p] <= 0) continue; diff --git a/decoder/drc_src/impd_drc_selection_process_drcset_selection.c b/decoder/drc_src/impd_drc_selection_process_drcset_selection.c index b91df9a..7e2bb62 100644 --- a/decoder/drc_src/impd_drc_selection_process_drcset_selection.c +++ b/decoder/drc_src/impd_drc_selection_process_drcset_selection.c @@ -736,7 +736,7 @@ WORD32 impd_drc_set_preselection( ia_drc_instructions_struct* str_drc_instruction_str = NULL; impd_select_drc_coeff3(pstr_drc_config, &str_p_loc_drc_coefficients_uni_drc); - + if (str_p_loc_drc_coefficients_uni_drc == NULL) return UNEXPECTED_ERROR; k = 0; for (d = 0; d < num_downmix_id_requests; d++) { err = impd_find_eq_set_no_compression( diff --git a/decoder/drc_src/impd_drc_static_payload.c b/decoder/drc_src/impd_drc_static_payload.c index 871a452..95f5aeb 100644 --- a/decoder/drc_src/impd_drc_static_payload.c +++ b/decoder/drc_src/impd_drc_static_payload.c @@ -1377,6 +1377,9 @@ impd_parse_loudness_measure(ia_bit_buf_struct* it_bit_buff, if (it_bit_buff->error) return it_bit_buff->error; loudness_measure->measurement_system = (temp >> 2) & 0xf; + if (loudness_measure->measurement_system > MEASUREMENT_SYSTEM_RESERVED_E) + return (UNEXPECTED_ERROR); + /* Parsed but unused */ loudness_measure->reliability = temp & 3; return (0); @@ -1538,6 +1541,9 @@ impd_parse_gain_set_params(ia_bit_buf_struct* it_bit_buff, WORD32 version, *gain_seq_idx = (*gain_seq_idx) + 1; } } + + if (*gain_seq_idx >= SEQUENCE_COUNT_MAX) return UNEXPECTED_ERROR; + gain_set_params->gain_params[i].gain_seq_idx = *gain_seq_idx; err = impd_parse_gain_set_params_characteristics( it_bit_buff, version, &(gain_set_params->gain_params[i])); @@ -2013,6 +2019,8 @@ impd_parse_drc_instructions_uni_drc( str_drc_instruction_str->drc_set_id = impd_read_bits_buf(it_bit_buff, 6); if (it_bit_buff->error) return it_bit_buff->error; + if (str_drc_instruction_str->drc_set_id >= DRC_INSTRUCTIONS_COUNT_MAX) + return UNEXPECTED_ERROR; if (version == 0) { str_drc_instruction_str->drc_set_complexity_level = DRC_COMPLEXITY_LEVEL_MAX; @@ -2144,6 +2152,8 @@ impd_parse_drc_instructions_uni_drc( WORD32 bs_gain_set_idx; bs_gain_set_idx = impd_read_bits_buf(it_bit_buff, 6); if (it_bit_buff->error) return it_bit_buff->error; + if ((bs_gain_set_idx == 0) || (bs_gain_set_idx > GAIN_SET_COUNT_MAX)) + return UNEXPECTED_ERROR; str_drc_instruction_str->gain_set_index[c] = bs_gain_set_idx - 1; impd_dec_ducking_scaling( it_bit_buff, @@ -2295,6 +2305,9 @@ impd_parse_drc_instructions_uni_drc( bs_gain_set_idx = (temp >> 1) & 0x7f; repeat_gain_set_idx = temp & 1; + if ((bs_gain_set_idx == 0) || (bs_gain_set_idx > GAIN_SET_COUNT_MAX)) + return UNEXPECTED_ERROR; + str_drc_instruction_str->gain_set_index[c] = bs_gain_set_idx - 1; c++; diff --git a/decoder/drc_src/impd_drc_struct.h b/decoder/drc_src/impd_drc_struct.h index 0ee8fd8..16e2191 100644 --- a/decoder/drc_src/impd_drc_struct.h +++ b/decoder/drc_src/impd_drc_struct.h @@ -430,7 +430,7 @@ typedef struct { WORD32 method_def; FLOAT32 method_val; WORD32 measurement_system; - WORD32 reliability; + WORD32 reliability; /* Parsed but unused */ } ia_loudness_measure_struct; typedef struct { diff --git a/decoder/generic/ixheaacd_qmf_dec_generic.c b/decoder/generic/ixheaacd_qmf_dec_generic.c index 20e19a8..4b5120f 100644 --- a/decoder/generic/ixheaacd_qmf_dec_generic.c +++ b/decoder/generic/ixheaacd_qmf_dec_generic.c @@ -82,12 +82,12 @@ VOID ixheaacd_dct3_32(WORD32 *input, WORD32 *output, for (n = 1; n < DCT3_LEN / 2; n++) { temp1[0] = *ptr_forward++; temp1[1] = *ptr_reverse--; - temp1[0] = ixheaacd_add32(ixheaacd_shr32(temp1[0], LP_SHIFT_VAL), + temp1[0] = ixheaacd_add32_sat(ixheaacd_shr32(temp1[0], LP_SHIFT_VAL), ixheaacd_shr32(temp1[1], LP_SHIFT_VAL)); temp1[2] = *(ptr_forward - 33); temp1[3] = *(ptr_reverse - 31); - temp1[1] = ixheaacd_sub32(ixheaacd_shr32(temp1[2], LP_SHIFT_VAL), + temp1[1] = ixheaacd_sub32_sat(ixheaacd_shr32(temp1[2], LP_SHIFT_VAL), ixheaacd_shr32(temp1[3], LP_SHIFT_VAL)); twid_re = *twidle_fwd++; @@ -107,7 +107,7 @@ VOID ixheaacd_dct3_32(WORD32 *input, WORD32 *output, temp1[1] = *ptr_reverse--; temp1[0] = *(ptr_reverse - 31); - temp1[1] = ixheaacd_sub32(ixheaacd_shr32(temp1[1], LP_SHIFT_VAL), + temp1[1] = ixheaacd_sub32_sat(ixheaacd_shr32(temp1[1], LP_SHIFT_VAL), ixheaacd_shr32(temp1[0], LP_SHIFT_VAL)); temp1[0] = temp1[1]; @@ -292,7 +292,7 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, wim = *p_sin_cos++; wre = *p_sin_cos++; - *psubband_t++ = ixheaacd_add32(ixheaacd_mult32x16in32(re, wre), + *psubband_t++ = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wre), ixheaacd_mult32x16in32(im, wim)); *psubband_t++ = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wre), ixheaacd_mult32x16in32(re, wim)); @@ -302,7 +302,7 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, *psubband_t2++ = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wim), ixheaacd_mult32x16in32(re, wre)); - *psubband_t2++ = ixheaacd_add32(ixheaacd_mult32x16in32(re, wim), + *psubband_t2++ = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wim), ixheaacd_mult32x16in32(im, wre)); re = *psubband1--; @@ -313,13 +313,13 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, *psubband1_t-- = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wre), ixheaacd_mult32x16in32(re, wim)); - *psubband1_t-- = ixheaacd_add32(ixheaacd_mult32x16in32(re, wre), + *psubband1_t-- = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wre), ixheaacd_mult32x16in32(im, wim)); re = *psubband12--; im = *psubband2++; - *psubband1_t2-- = ixheaacd_add32(ixheaacd_mult32x16in32(re, wim), + *psubband1_t2-- = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wim), ixheaacd_mult32x16in32(im, wre)); *psubband1_t2-- = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wim), ixheaacd_mult32x16in32(re, wre)); @@ -330,7 +330,7 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, wim = *p_sin_cos++; wre = *p_sin_cos++; - *psubband_t++ = ixheaacd_add32(ixheaacd_mult32x16in32(re, wre), + *psubband_t++ = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wre), ixheaacd_mult32x16in32(im, wim)); *psubband_t++ = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wre), ixheaacd_mult32x16in32(re, wim)); @@ -340,7 +340,7 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, *psubband_t2++ = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wim), ixheaacd_mult32x16in32(re, wre)); - *psubband_t2++ = ixheaacd_add32(ixheaacd_mult32x16in32(re, wim), + *psubband_t2++ = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wim), ixheaacd_mult32x16in32(im, wre)); re = *psubband1--; @@ -351,14 +351,14 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, *psubband1_t-- = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wre), ixheaacd_mult32x16in32(re, wim)); - *psubband1_t-- = ixheaacd_add32(ixheaacd_mult32x16in32(re, wre), + *psubband1_t-- = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wre), ixheaacd_mult32x16in32(im, wim)); re = *psubband12--; im = *psubband2++; ; - *psubband1_t2-- = ixheaacd_add32(ixheaacd_mult32x16in32(re, wim), + *psubband1_t2-- = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wim), ixheaacd_mult32x16in32(im, wre)); *psubband1_t2-- = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wim), ixheaacd_mult32x16in32(re, wre)); @@ -399,7 +399,7 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, im = *psubband1; - *psubband1-- = ixheaacd_add32(ixheaacd_mult32x16in32(re, wre), + *psubband1-- = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wre), ixheaacd_mult32x16in32(im, wim)); *psubband++ = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wre), ixheaacd_mult32x16in32(re, wim)); @@ -417,7 +417,7 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, im = *psubband12; - *psubband2++ = ixheaacd_negate32_sat(ixheaacd_add32( + *psubband2++ = ixheaacd_negate32_sat(ixheaacd_add32_sat( ixheaacd_mult32x16in32(re, wre), ixheaacd_mult32x16in32(im, wim))); *psubband12-- = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(re, wim), ixheaacd_mult32x16in32(im, wre)); @@ -429,7 +429,7 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, re2 = *psubband1; - *psubband++ = ixheaacd_add32(ixheaacd_mult32x16in32(re, wim), + *psubband++ = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re, wim), ixheaacd_mult32x16in32(im, wre)); *psubband1-- = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wim), ixheaacd_mult32x16in32(re, wre)); @@ -440,7 +440,7 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, re3 = *psubband12; - *psubband12-- = ixheaacd_negate32_sat(ixheaacd_add32( + *psubband12-- = ixheaacd_negate32_sat(ixheaacd_add32_sat( ixheaacd_mult32x16in32(re, wim), ixheaacd_mult32x16in32(im, wre))); *psubband2++ = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(re, wre), ixheaacd_mult32x16in32(im, wim)); @@ -449,14 +449,14 @@ VOID ixheaacd_cos_sin_mod(WORD32 *subband, wre = *p_sin++; im = psubband1[0]; - *psubband1-- = ixheaacd_add32(ixheaacd_mult32x16in32(re2, wre), + *psubband1-- = ixheaacd_add32_sat(ixheaacd_mult32x16in32(re2, wre), ixheaacd_mult32x16in32(im, wim)); *psubband++ = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(im, wre), ixheaacd_mult32x16in32(re2, wim)); im = psubband12[0]; - *psubband2++ = ixheaacd_negate32_sat(ixheaacd_add32( + *psubband2++ = ixheaacd_negate32_sat(ixheaacd_add32_sat( ixheaacd_mult32x16in32(re3, wre), ixheaacd_mult32x16in32(im, wim))); *psubband12-- = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(re3, wim), ixheaacd_mult32x16in32(im, wre)); @@ -480,7 +480,7 @@ VOID ixheaacd_fwd_modulation(const WORD32 *p_time_in1, WORD32 *real_subband, *t_real_subband++ = ixheaacd_sub32_sat(temp1, temp2); - *t_imag_subband++ = ixheaacd_add32(temp1, temp2); + *t_imag_subband++ = ixheaacd_add32_sat(temp1, temp2); } ixheaacd_cos_sin_mod(real_subband, qmf_bank, qmf_dec_tables_ptr->w_16, @@ -496,7 +496,7 @@ VOID ixheaacd_fwd_modulation(const WORD32 *p_time_in1, WORD32 *real_subband, im = *imag_subband; cosh = *tcos++; sinh = *tcos++; - *real_subband++ = ixheaacd_add32(ixheaacd_mult32x16in32_shl(re, cosh), + *real_subband++ = ixheaacd_add32_sat(ixheaacd_mult32x16in32_shl(re, cosh), ixheaacd_mult32x16in32_shl(im, sinh)); *imag_subband++ = ixheaacd_sub32_sat(ixheaacd_mult32x16in32_shl(im, cosh), ixheaacd_mult32x16in32_shl(re, sinh)); @@ -511,13 +511,13 @@ VOID ixheaacd_sbr_qmfanal32_winadd(WORD16 *inp1, WORD16 *inp2, WORD16 *p_qmf1, WORD32 accu; accu = ixheaacd_mult16x16in32(inp1[n + 0], p_qmf1[2 * (n + 0)]); - accu = ixheaacd_add32( + accu = ixheaacd_add32_sat( accu, ixheaacd_mult16x16in32(inp1[n + 64], p_qmf1[2 * (n + 64)])); - accu = ixheaacd_add32( + accu = ixheaacd_add32_sat( accu, ixheaacd_mult16x16in32(inp1[n + 128], p_qmf1[2 * (n + 128)])); - accu = ixheaacd_add32( + accu = ixheaacd_add32_sat( accu, ixheaacd_mult16x16in32(inp1[n + 192], p_qmf1[2 * (n + 192)])); - accu = ixheaacd_add32( + accu = ixheaacd_add32_sat( accu, ixheaacd_mult16x16in32(inp1[n + 256], p_qmf1[2 * (n + 256)])); p_out[n] = accu; @@ -537,13 +537,13 @@ VOID ixheaacd_sbr_qmfanal32_winadd(WORD16 *inp1, WORD16 *inp2, WORD16 *p_qmf1, p_out[n + 1] = accu; accu = ixheaacd_mult16x16in32(inp2[n + 0], p_qmf2[2 * (n + 0)]); - accu = ixheaacd_add32( + accu = ixheaacd_add32_sat( accu, ixheaacd_mult16x16in32(inp2[n + 64], p_qmf2[2 * (n + 64)])); - accu = ixheaacd_add32( + accu = ixheaacd_add32_sat( accu, ixheaacd_mult16x16in32(inp2[n + 128], p_qmf2[2 * (n + 128)])); - accu = ixheaacd_add32( + accu = ixheaacd_add32_sat( accu, ixheaacd_mult16x16in32(inp2[n + 192], p_qmf2[2 * (n + 192)])); - accu = ixheaacd_add32( + accu = ixheaacd_add32_sat( accu, ixheaacd_mult16x16in32(inp2[n + 256], p_qmf2[2 * (n + 256)])); p_out[n + 32] = accu; @@ -776,34 +776,34 @@ VOID ixheaacd_esbr_radix4bfly(const WORD32 *w, WORD32 *x, WORD32 index1, x_l1_0 = x[l1]; x_l2_0 = x[l2]; - xh0_0 = x_0 + x_l1_0; - xl0_0 = x_0 - x_l1_0; + xh0_0 = ixheaacd_add32_sat(x_0, x_l1_0); + xl0_0 = ixheaacd_sub32_sat(x_0, x_l1_0); - xh20_0 = x_h2_0 + x_l2_0; - xl20_0 = x_h2_0 - x_l2_0; + xh20_0 = ixheaacd_add32_sat(x_h2_0, x_l2_0); + xl20_0 = ixheaacd_sub32_sat(x_h2_0, x_l2_0); - x[0] = xh0_0 + xh20_0; - xt0_0 = xh0_0 - xh20_0; + x[0] = ixheaacd_add32_sat(xh0_0, xh20_0); + xt0_0 = ixheaacd_sub32_sat(xh0_0, xh20_0); x_1 = x[1]; x_h2_1 = x[h2 + 1]; x_l1_1 = x[l1 + 1]; x_l2_1 = x[l2 + 1]; - xh1_0 = x_1 + x_l1_1; - xl1_0 = x_1 - x_l1_1; + xh1_0 = ixheaacd_add32_sat(x_1, x_l1_1); + xl1_0 = ixheaacd_sub32_sat(x_1, x_l1_1); - xh21_0 = x_h2_1 + x_l2_1; - xl21_0 = x_h2_1 - x_l2_1; + xh21_0 = ixheaacd_add32_sat(x_h2_1, x_l2_1); + xl21_0 = ixheaacd_sub32_sat(x_h2_1, x_l2_1); - x[1] = xh1_0 + xh21_0; - yt0_0 = xh1_0 - xh21_0; + x[1] = ixheaacd_add32_sat(xh1_0, xh21_0); + yt0_0 = ixheaacd_sub32_sat(xh1_0, xh21_0); - xt1_0 = xl0_0 + xl21_0; - xt2_0 = xl0_0 - xl21_0; + xt1_0 = ixheaacd_add32_sat(xl0_0, xl21_0); + xt2_0 = ixheaacd_sub32_sat(xl0_0, xl21_0); - yt2_0 = xl1_0 + xl20_0; - yt1_0 = xl1_0 - xl20_0; + yt2_0 = ixheaacd_add32_sat(xl1_0, xl20_0); + yt1_0 = ixheaacd_sub32_sat(xl1_0, xl20_0); mul_11 = ixheaacd_mult64(xt2_0, co30); mul_3 = ixheaacd_mult64(yt2_0, si30); @@ -873,14 +873,14 @@ VOID ixheaacd_esbr_postradixcompute2(WORD32 *ptr_y, WORD32 *ptr_x, x_6 = *x0++; x_7 = *x0++; - n00 = x_0 + x_2; - n01 = x_1 + x_3; - n20 = x_0 - x_2; - n21 = x_1 - x_3; - n10 = x_4 + x_6; - n11 = x_5 + x_7; - n30 = x_4 - x_6; - n31 = x_5 - x_7; + n00 = ixheaacd_add32_sat(x_0, x_2); + n01 = ixheaacd_add32_sat(x_1, x_3); + n20 = ixheaacd_sub32_sat(x_0, x_2); + n21 = ixheaacd_sub32_sat(x_1, x_3); + n10 = ixheaacd_add32_sat(x_4, x_6); + n11 = ixheaacd_add32_sat(x_5, x_7); + n30 = ixheaacd_sub32_sat(x_4, x_6); + n31 = ixheaacd_sub32_sat(x_5, x_7); y0[h2] = n00; y0[h2 + 1] = n01; @@ -900,14 +900,14 @@ VOID ixheaacd_esbr_postradixcompute2(WORD32 *ptr_y, WORD32 *ptr_x, x_e = *x2++; x_f = *x2++; - n02 = x_8 + x_a; - n03 = x_9 + x_b; - n22 = x_8 - x_a; - n23 = x_9 - x_b; - n12 = x_c + x_e; - n13 = x_d + x_f; - n32 = x_c - x_e; - n33 = x_d - x_f; + n02 = ixheaacd_add32_sat(x_8, x_a); + n03 = ixheaacd_add32_sat(x_9, x_b); + n22 = ixheaacd_sub32_sat(x_8, x_a); + n23 = ixheaacd_sub32_sat(x_9, x_b); + n12 = ixheaacd_add32_sat(x_c, x_e); + n13 = ixheaacd_add32_sat(x_d, x_f); + n32 = ixheaacd_sub32_sat(x_c, x_e); + n33 = ixheaacd_sub32_sat(x_d, x_f); y0[h2 + 2] = n02; y0[h2 + 3] = n03; @@ -963,23 +963,23 @@ VOID ixheaacd_esbr_postradixcompute4(WORD32 *ptr_y, WORD32 *ptr_x, x_6 = *x0++; x_7 = *x0++; - xh0_0 = x_0 + x_4; - xh1_0 = x_1 + x_5; - xl0_0 = x_0 - x_4; - xl1_0 = x_1 - x_5; - xh0_1 = x_2 + x_6; - xh1_1 = x_3 + x_7; - xl0_1 = x_2 - x_6; - xl1_1 = x_3 - x_7; + xh0_0 = ixheaacd_add32_sat(x_0, x_4); + xh1_0 = ixheaacd_add32_sat(x_1, x_5); + xl0_0 = ixheaacd_sub32_sat(x_0, x_4); + xl1_0 = ixheaacd_sub32_sat(x_1, x_5); + xh0_1 = ixheaacd_add32_sat(x_2, x_6); + xh1_1 = ixheaacd_add32_sat(x_3, x_7); + xl0_1 = ixheaacd_sub32_sat(x_2, x_6); + xl1_1 = ixheaacd_sub32_sat(x_3, x_7); - n00 = xh0_0 + xh0_1; - n01 = xh1_0 + xh1_1; - n10 = xl0_0 + xl1_1; - n11 = xl1_0 - xl0_1; - n20 = xh0_0 - xh0_1; - n21 = xh1_0 - xh1_1; - n30 = xl0_0 - xl1_1; - n31 = xl1_0 + xl0_1; + n00 = ixheaacd_add32_sat(xh0_0, xh0_1); + n01 = ixheaacd_add32_sat(xh1_0, xh1_1); + n10 = ixheaacd_add32_sat(xl0_0, xl1_1); + n11 = ixheaacd_sub32_sat(xl1_0, xl0_1); + n20 = ixheaacd_sub32_sat(xh0_0, xh0_1); + n21 = ixheaacd_sub32_sat(xh1_0, xh1_1); + n30 = ixheaacd_sub32_sat(xl0_0, xl1_1); + n31 = ixheaacd_add32_sat(xl1_0, xl0_1); y0[h2] = n00; y0[h2 + 1] = n01; @@ -999,23 +999,23 @@ VOID ixheaacd_esbr_postradixcompute4(WORD32 *ptr_y, WORD32 *ptr_x, x_e = *x2++; x_f = *x2++; - xh0_2 = x_8 + x_c; - xh1_2 = x_9 + x_d; - xl0_2 = x_8 - x_c; - xl1_2 = x_9 - x_d; - xh0_3 = x_a + x_e; - xh1_3 = x_b + x_f; - xl0_3 = x_a - x_e; - xl1_3 = x_b - x_f; + xh0_2 = ixheaacd_add32_sat(x_8, x_c); + xh1_2 = ixheaacd_add32_sat(x_9, x_d); + xl0_2 = ixheaacd_sub32_sat(x_8, x_c); + xl1_2 = ixheaacd_sub32_sat(x_9, x_d); + xh0_3 = ixheaacd_add32_sat(x_a, x_e); + xh1_3 = ixheaacd_add32_sat(x_b, x_f); + xl0_3 = ixheaacd_sub32_sat(x_a, x_e); + xl1_3 = ixheaacd_sub32_sat(x_b, x_f); - n02 = xh0_2 + xh0_3; - n03 = xh1_2 + xh1_3; - n12 = xl0_2 + xl1_3; - n13 = xl1_2 - xl0_3; - n22 = xh0_2 - xh0_3; - n23 = xh1_2 - xh1_3; - n32 = xl0_2 - xl1_3; - n33 = xl1_2 + xl0_3; + n02 = ixheaacd_add32_sat(xh0_2, xh0_3); + n03 = ixheaacd_add32_sat(xh1_2, xh1_3); + n12 = ixheaacd_add32_sat(xl0_2, xl1_3); + n13 = ixheaacd_sub32_sat(xl1_2, xl0_3); + n22 = ixheaacd_sub32_sat(xh0_2, xh0_3); + n23 = ixheaacd_sub32_sat(xh1_2, xh1_3); + n32 = ixheaacd_sub32_sat(xl0_2, xl1_3); + n33 = ixheaacd_add32_sat(xl1_2, xl0_3); y0[h2 + 2] = n02; y0[h2 + 3] = n03; @@ -1349,7 +1349,7 @@ VOID ixheaacd_esbr_fwd_modulation( *t_real_subband++ = ixheaacd_sub32_sat(temp1, temp2); - *t_imag_subband++ = ixheaacd_add32(temp1, temp2); + *t_imag_subband++ = ixheaacd_add32_sat(temp1, temp2); } ixheaacd_esbr_cos_sin_mod(real_subband, qmf_bank, @@ -1386,26 +1386,26 @@ VOID ixheaacd_sbr_qmfsyn64_winadd(WORD16 *tmp1, WORD16 *tmp2, WORD16 *inp1, for (k = 0; k < 64; k++) { WORD32 syn_out = rounding_fac; - syn_out = ixheaacd_add32(syn_out, + syn_out = ixheaacd_add32_sat(syn_out, ixheaacd_mult16x16in32(tmp1[0 + k], inp1[k + 0])); - syn_out = ixheaacd_add32( + syn_out = ixheaacd_add32_sat( syn_out, ixheaacd_mult16x16in32(tmp1[256 + k], inp1[k + 128])); - syn_out = ixheaacd_add32( + syn_out = ixheaacd_add32_sat( syn_out, ixheaacd_mult16x16in32(tmp1[512 + k], inp1[k + 256])); - syn_out = ixheaacd_add32( + syn_out = ixheaacd_add32_sat( syn_out, ixheaacd_mult16x16in32(tmp1[768 + k], inp1[k + 384])); - syn_out = ixheaacd_add32( + syn_out = ixheaacd_add32_sat( syn_out, ixheaacd_mult16x16in32(tmp1[1024 + k], inp1[k + 512])); - syn_out = ixheaacd_add32( + syn_out = ixheaacd_add32_sat( syn_out, ixheaacd_mult16x16in32(tmp2[128 + k], inp1[k + 64])); - syn_out = ixheaacd_add32( + syn_out = ixheaacd_add32_sat( syn_out, ixheaacd_mult16x16in32(tmp2[384 + k], inp1[k + 192])); - syn_out = ixheaacd_add32( + syn_out = ixheaacd_add32_sat( syn_out, ixheaacd_mult16x16in32(tmp2[640 + k], inp1[k + 320])); - syn_out = ixheaacd_add32( + syn_out = ixheaacd_add32_sat( syn_out, ixheaacd_mult16x16in32(tmp2[896 + k], inp1[k + 448])); - syn_out = ixheaacd_add32( + syn_out = ixheaacd_add32_sat( syn_out, ixheaacd_mult16x16in32(tmp2[1152 + k], inp1[k + 576])); sample_buffer[ch_fac * k] = (ixheaacd_shl32_sat(syn_out, shift) >> 16); @@ -1488,19 +1488,19 @@ VOID ixheaacd_shiftrountine_with_rnd(WORD32 *qmf_real, WORD32 *qmf_imag, r1 = *qmf_real++; i1 = *qmf_imag++; - timag = ixheaacd_add32(i1, r1); + timag = ixheaacd_add32_sat(i1, r1); timag = (ixheaacd_shl32_sat(timag, shift)); filter_states_rev[j] = ixheaacd_round16(timag); - treal = ixheaacd_sub32(i2, r2); + treal = ixheaacd_sub32_sat(i2, r2); treal = (ixheaacd_shl32_sat(treal, shift)); filter_states[j] = ixheaacd_round16(treal); - treal = ixheaacd_sub32(i1, r1); + treal = ixheaacd_sub32_sat(i1, r1); treal = (ixheaacd_shl32_sat(treal, shift)); *filter_states++ = ixheaacd_round16(treal); - timag = ixheaacd_add32(i2, r2); + timag = ixheaacd_add32_sat(i2, r2); ; timag = (ixheaacd_shl32_sat(timag, shift)); *filter_states_rev++ = ixheaacd_round16(timag); @@ -1521,19 +1521,19 @@ VOID ixheaacd_shiftrountine_with_rnd_eld(WORD32 *qmf_real, WORD32 *qmf_imag, r1 = *qmf_real++; i1 = *qmf_imag++; - timag = ixheaacd_negate32(ixheaacd_add32(i1, r1)); + timag = ixheaacd_negate32(ixheaacd_add32_sat(i1, r1)); timag = (ixheaacd_shl32_sat(timag, shift)); filter_states_rev[j] = ixheaacd_round16(timag); - treal = ixheaacd_sub32(r2, i2); + treal = ixheaacd_sub32_sat(r2, i2); treal = (ixheaacd_shl32_sat(treal, shift)); filter_states[j] = ixheaacd_round16(treal); - treal = ixheaacd_sub32(r1, i1); + treal = ixheaacd_sub32_sat(r1, i1); treal = (ixheaacd_shl32_sat(treal, shift)); *filter_states++ = ixheaacd_round16(treal); - timag = ixheaacd_negate32(ixheaacd_add32(i2, r2)); + timag = ixheaacd_negate32(ixheaacd_add32_sat(i2, r2)); timag = (ixheaacd_shl32_sat(timag, shift)); *filter_states_rev++ = ixheaacd_round16(timag); } @@ -1553,19 +1553,19 @@ VOID ixheaacd_shiftrountine_with_rnd_hq(WORD32 *qmf_real, WORD32 *qmf_imag, r1 = *qmf_real++; i1 = *qmf_imag++; - timag = ixheaacd_add32(i1, r1); + timag = ixheaacd_add32_sat(i1, r1); timag = (ixheaacd_shl32_sat(timag, shift)); filter_states_rev[j] = timag; - treal = ixheaacd_sub32(i2, r2); + treal = ixheaacd_sub32_sat(i2, r2); treal = (ixheaacd_shl32_sat(treal, shift)); filter_states[j] = treal; - treal = ixheaacd_sub32(i1, r1); + treal = ixheaacd_sub32_sat(i1, r1); treal = (ixheaacd_shl32_sat(treal, shift)); *filter_states++ = treal; - timag = ixheaacd_add32(i2, r2); + timag = ixheaacd_add32_sat(i2, r2); timag = (ixheaacd_shl32_sat(timag, shift)); *filter_states_rev++ = timag; } @@ -1613,34 +1613,34 @@ VOID ixheaacd_radix4bfly(const WORD16 *w, WORD32 *x, WORD32 index1, x_l1_0 = x[l1]; x_l2_0 = x[l2]; - xh0_0 = x_0 + x_l1_0; - xl0_0 = x_0 - x_l1_0; + xh0_0 = ixheaacd_add32_sat(x_0, x_l1_0); + xl0_0 = ixheaacd_sub32_sat(x_0, x_l1_0); - xh20_0 = x_h2_0 + x_l2_0; - xl20_0 = x_h2_0 - x_l2_0; + xh20_0 = ixheaacd_add32_sat(x_h2_0, x_l2_0); + xl20_0 = ixheaacd_sub32_sat(x_h2_0, x_l2_0); - x[0] = xh0_0 + xh20_0; - xt0_0 = xh0_0 - xh20_0; + x[0] = ixheaacd_add32_sat(xh0_0, xh20_0); + xt0_0 = ixheaacd_sub32_sat(xh0_0, xh20_0); x_1 = x[1]; x_h2_1 = x[h2 + 1]; x_l1_1 = x[l1 + 1]; x_l2_1 = x[l2 + 1]; - xh1_0 = x_1 + x_l1_1; - xl1_0 = x_1 - x_l1_1; + xh1_0 = ixheaacd_add32_sat(x_1, x_l1_1); + xl1_0 = ixheaacd_sub32_sat(x_1, x_l1_1); - xh21_0 = x_h2_1 + x_l2_1; - xl21_0 = x_h2_1 - x_l2_1; + xh21_0 = ixheaacd_add32_sat(x_h2_1, x_l2_1); + xl21_0 = ixheaacd_sub32_sat(x_h2_1, x_l2_1); - x[1] = xh1_0 + xh21_0; - yt0_0 = xh1_0 - xh21_0; + x[1] = ixheaacd_add32_sat(xh1_0, xh21_0); + yt0_0 = ixheaacd_sub32_sat(xh1_0, xh21_0); - xt1_0 = xl0_0 + xl21_0; - xt2_0 = xl0_0 - xl21_0; + xt1_0 = ixheaacd_add32_sat(xl0_0, xl21_0); + xt2_0 = ixheaacd_sub32_sat(xl0_0, xl21_0); - yt2_0 = xl1_0 + xl20_0; - yt1_0 = xl1_0 - xl20_0; + yt2_0 = ixheaacd_add32_sat(xl1_0, xl20_0); + yt1_0 = ixheaacd_sub32_sat(xl1_0, xl20_0); mul_11 = ixheaacd_mult32x16in32(xt2_0, co30); mul_3 = ixheaacd_mult32x16in32(yt2_0, si30); @@ -1712,23 +1712,23 @@ VOID ixheaacd_postradixcompute4(WORD32 *ptr_y, WORD32 *ptr_x, x_6 = *x0++; x_7 = *x0++; - xh0_0 = x_0 + x_4; - xh1_0 = x_1 + x_5; - xl0_0 = x_0 - x_4; - xl1_0 = x_1 - x_5; - xh0_1 = x_2 + x_6; - xh1_1 = x_3 + x_7; - xl0_1 = x_2 - x_6; - xl1_1 = x_3 - x_7; + xh0_0 = ixheaacd_add32_sat(x_0, x_4); + xh1_0 = ixheaacd_add32_sat(x_1, x_5); + xl0_0 = ixheaacd_sub32_sat(x_0, x_4); + xl1_0 = ixheaacd_sub32_sat(x_1, x_5); + xh0_1 = ixheaacd_add32_sat(x_2, x_6); + xh1_1 = ixheaacd_add32_sat(x_3, x_7); + xl0_1 = ixheaacd_sub32_sat(x_2, x_6); + xl1_1 = ixheaacd_sub32_sat(x_3, x_7); - n00 = xh0_0 + xh0_1; - n01 = xh1_0 + xh1_1; - n10 = xl0_0 + xl1_1; - n11 = xl1_0 - xl0_1; - n20 = xh0_0 - xh0_1; - n21 = xh1_0 - xh1_1; - n30 = xl0_0 - xl1_1; - n31 = xl1_0 + xl0_1; + n00 = ixheaacd_add32_sat(xh0_0, xh0_1); + n01 = ixheaacd_add32_sat(xh1_0, xh1_1); + n10 = ixheaacd_add32_sat(xl0_0, xl1_1); + n11 = ixheaacd_sub32_sat(xl1_0, xl0_1); + n20 = ixheaacd_sub32_sat(xh0_0, xh0_1); + n21 = ixheaacd_sub32_sat(xh1_0, xh1_1); + n30 = ixheaacd_sub32_sat(xl0_0, xl1_1); + n31 = ixheaacd_add32_sat(xl1_0, xl0_1); y0[h2] = n00; y0[h2 + 1] = n01; @@ -1748,23 +1748,23 @@ VOID ixheaacd_postradixcompute4(WORD32 *ptr_y, WORD32 *ptr_x, x_e = *x2++; x_f = *x2++; - xh0_2 = x_8 + x_c; - xh1_2 = x_9 + x_d; - xl0_2 = x_8 - x_c; - xl1_2 = x_9 - x_d; - xh0_3 = x_a + x_e; - xh1_3 = x_b + x_f; - xl0_3 = x_a - x_e; - xl1_3 = x_b - x_f; + xh0_2 = ixheaacd_add32_sat(x_8, x_c); + xh1_2 = ixheaacd_add32_sat(x_9, x_d); + xl0_2 = ixheaacd_sub32_sat(x_8, x_c); + xl1_2 = ixheaacd_sub32_sat(x_9, x_d); + xh0_3 = ixheaacd_add32_sat(x_a, x_e); + xh1_3 = ixheaacd_add32_sat(x_b, x_f); + xl0_3 = ixheaacd_sub32_sat(x_a, x_e); + xl1_3 = ixheaacd_sub32_sat(x_b, x_f); - n02 = xh0_2 + xh0_3; - n03 = xh1_2 + xh1_3; - n12 = xl0_2 + xl1_3; - n13 = xl1_2 - xl0_3; - n22 = xh0_2 - xh0_3; - n23 = xh1_2 - xh1_3; - n32 = xl0_2 - xl1_3; - n33 = xl1_2 + xl0_3; + n02 = ixheaacd_add32_sat(xh0_2, xh0_3); + n03 = ixheaacd_add32_sat(xh1_2, xh1_3); + n12 = ixheaacd_add32_sat(xl0_2, xl1_3); + n13 = ixheaacd_sub32_sat(xl1_2, xl0_3); + n22 = ixheaacd_sub32_sat(xh0_2, xh0_3); + n23 = ixheaacd_sub32_sat(xh1_2, xh1_3); + n32 = ixheaacd_sub32_sat(xl0_2, xl1_3); + n33 = ixheaacd_add32_sat(xl1_2, xl0_3); y0[h2 + 2] = n02; y0[h2 + 3] = n03; @@ -1816,14 +1816,14 @@ VOID ixheaacd_postradixcompute2(WORD32 *ptr_y, WORD32 *ptr_x, x_6 = *x0++; x_7 = *x0++; - n00 = x_0 + x_2; - n01 = x_1 + x_3; - n20 = x_0 - x_2; - n21 = x_1 - x_3; - n10 = x_4 + x_6; - n11 = x_5 + x_7; - n30 = x_4 - x_6; - n31 = x_5 - x_7; + n00 = ixheaacd_add32_sat(x_0, x_2); + n01 = ixheaacd_add32_sat(x_1, x_3); + n20 = ixheaacd_sub32_sat(x_0, x_2); + n21 = ixheaacd_sub32_sat(x_1, x_3); + n10 = ixheaacd_add32_sat(x_4, x_6); + n11 = ixheaacd_add32_sat(x_5, x_7); + n30 = ixheaacd_sub32_sat(x_4, x_6); + n31 = ixheaacd_sub32_sat(x_5, x_7); y0[h2] = n00; y0[h2 + 1] = n01; @@ -1843,14 +1843,14 @@ VOID ixheaacd_postradixcompute2(WORD32 *ptr_y, WORD32 *ptr_x, x_e = *x2++; x_f = *x2++; - n02 = x_8 + x_a; - n03 = x_9 + x_b; - n22 = x_8 - x_a; - n23 = x_9 - x_b; - n12 = x_c + x_e; - n13 = x_d + x_f; - n32 = x_c - x_e; - n33 = x_d - x_f; + n02 = ixheaacd_add32_sat(x_8, x_a); + n03 = ixheaacd_add32_sat(x_9, x_b); + n22 = ixheaacd_sub32_sat(x_8, x_a); + n23 = ixheaacd_sub32_sat(x_9, x_b); + n12 = ixheaacd_add32_sat(x_c, x_e); + n13 = ixheaacd_add32_sat(x_d, x_f); + n32 = ixheaacd_sub32_sat(x_c, x_e); + n33 = ixheaacd_sub32_sat(x_d, x_f); y0[h2 + 2] = n02; y0[h2 + 3] = n03; diff --git a/decoder/ixheaacd_aac_imdct.c b/decoder/ixheaacd_aac_imdct.c index 68d5bf3..88b23eb 100644 --- a/decoder/ixheaacd_aac_imdct.c +++ b/decoder/ixheaacd_aac_imdct.c @@ -2246,55 +2246,59 @@ VOID ixheaacd_fft_15_ld_dec(WORD32 *inp, WORD32 *op, WORD32 *fft3out, *buf1++ = inp[384]; *buf1++ = inp[385]; - r1 = buf1a[2] + buf1a[8]; - r4 = buf1a[2] - buf1a[8]; - r3 = buf1a[4] + buf1a[6]; - r2 = buf1a[4] - buf1a[6]; + r1 = ixheaacd_add32_sat(buf1a[2], buf1a[8]); + r4 = ixheaacd_sub32_sat(buf1a[2], buf1a[8]); + r3 = ixheaacd_add32_sat(buf1a[4], buf1a[6]); + r2 = ixheaacd_sub32_sat(buf1a[4], buf1a[6]); - t = ixheaacd_mult32_shl((r1 - r3), cos_54); + t = ixheaacd_mult32_shl(ixheaacd_sub32_sat(r1, r3), cos_54); - r1 = r1 + r3; + r1 = ixheaacd_add32_sat(r1, r3); - temp1 = buf1a[0] + r1; + temp1 = ixheaacd_add32_sat(buf1a[0], r1); - r1 = temp1 + ((ixheaacd_mult32_shl(r1, cos_55)) << 1); + r1 = ixheaacd_add32_sat( + temp1, ixheaacd_shl32_sat((ixheaacd_mult32_shl(r1, cos_55)), 1)); - r3 = r1 - t; - r1 = r1 + t; + r3 = ixheaacd_sub32_sat(r1, t); + r1 = ixheaacd_add32_sat(r1, t); - t = ixheaacd_mult32_shl((r4 + r2), cos_51); - r4 = t + (ixheaacd_mult32_shl(r4, cos_52) << 1); - r2 = t + ixheaacd_mult32_shl(r2, cos_53); + t = ixheaacd_mult32_shl(ixheaacd_add32_sat(r4, r2), cos_51); + r4 = ixheaacd_add32_sat( + t, ixheaacd_shl32_sat(ixheaacd_mult32_shl(r4, cos_52), 1)); + r2 = ixheaacd_add32_sat(t, ixheaacd_mult32_shl(r2, cos_53)); - s1 = buf1a[3] + buf1a[9]; - s4 = buf1a[3] - buf1a[9]; - s3 = buf1a[5] + buf1a[7]; - s2 = buf1a[5] - buf1a[7]; + s1 = ixheaacd_add32_sat(buf1a[3], buf1a[9]); + s4 = ixheaacd_sub32_sat(buf1a[3], buf1a[9]); + s3 = ixheaacd_add32_sat(buf1a[5], buf1a[7]); + s2 = ixheaacd_sub32_sat(buf1a[5], buf1a[7]); - t = ixheaacd_mult32_shl((s1 - s3), cos_54); - s1 = s1 + s3; + t = ixheaacd_mult32_shl(ixheaacd_sub32_sat(s1, s3), cos_54); + s1 = ixheaacd_add32_sat(s1, s3); - temp2 = buf1a[1] + s1; + temp2 = ixheaacd_add32_sat(buf1a[1], s1); - s1 = temp2 + ((ixheaacd_mult32_shl(s1, cos_55)) << 1); + s1 = ixheaacd_add32_sat( + temp2, ixheaacd_shl32_sat((ixheaacd_mult32_shl(s1, cos_55)), 1)); - s3 = s1 - t; - s1 = s1 + t; + s3 = ixheaacd_sub32_sat(s1, t); + s1 = ixheaacd_add32_sat(s1, t); - t = ixheaacd_mult32_shl((s4 + s2), cos_51); - s4 = t + ((ixheaacd_mult32_shl(s4, cos_52)) << 1); - s2 = t + (ixheaacd_mult32_shl(s2, cos_53)); + t = ixheaacd_mult32_shl(ixheaacd_add32_sat(s4, s2), cos_51); + s4 = ixheaacd_add32_sat( + t, ixheaacd_shl32_sat((ixheaacd_mult32_shl(s4, cos_52)), 1)); + s2 = ixheaacd_add32_sat(t, (ixheaacd_mult32_shl(s2, cos_53))); *buf2++ = temp1; *buf2++ = temp2; - *buf2++ = r1 + s2; - *buf2++ = s1 - r2; - *buf2++ = r3 - s4; - *buf2++ = s3 + r4; - *buf2++ = r3 + s4; - *buf2++ = s3 - r4; - *buf2++ = r1 - s2; - *buf2++ = s1 + r2; + *buf2++ = ixheaacd_add32_sat(r1, s2); + *buf2++ = ixheaacd_sub32_sat(s1, r2); + *buf2++ = ixheaacd_sub32_sat(r3, s4); + *buf2++ = ixheaacd_add32_sat(s3, r4); + *buf2++ = ixheaacd_add32_sat(r3, s4); + *buf2++ = ixheaacd_sub32_sat(s3, r4); + *buf2++ = ixheaacd_sub32_sat(r1, s2); + *buf2++ = ixheaacd_add32_sat(s1, r2); buf1a = buf1; *buf1++ = inp[160]; @@ -2312,56 +2316,60 @@ VOID ixheaacd_fft_15_ld_dec(WORD32 *inp, WORD32 *op, WORD32 *fft3out, *buf1++ = inp[64]; *buf1++ = inp[65]; - r1 = buf1a[2] + buf1a[8]; - r4 = buf1a[2] - buf1a[8]; - r3 = buf1a[4] + buf1a[6]; - r2 = buf1a[4] - buf1a[6]; + r1 = ixheaacd_add32_sat(buf1a[2], buf1a[8]); + r4 = ixheaacd_sub32_sat(buf1a[2], buf1a[8]); + r3 = ixheaacd_add32_sat(buf1a[4], buf1a[6]); + r2 = ixheaacd_sub32_sat(buf1a[4], buf1a[6]); - t = ixheaacd_mult32_shl((r1 - r3), cos_54); + t = ixheaacd_mult32_shl(ixheaacd_sub32_sat(r1, r3), cos_54); - r1 = r1 + r3; + r1 = ixheaacd_add32_sat(r1, r3); - temp1 = buf1a[0] + r1; + temp1 = ixheaacd_add32_sat(buf1a[0], r1); - r1 = temp1 + ((ixheaacd_mult32_shl(r1, cos_55)) << 1); + r1 = ixheaacd_add32_sat( + temp1, ixheaacd_shl32_sat((ixheaacd_mult32_shl(r1, cos_55)), 1)); - r3 = r1 - t; - r1 = r1 + t; + r3 = ixheaacd_sub32_sat(r1, t); + r1 = ixheaacd_add32_sat(r1, t); - t = ixheaacd_mult32_shl((r4 + r2), cos_51); - r4 = t + (ixheaacd_mult32_shl(r4, cos_52) << 1); - r2 = t + ixheaacd_mult32_shl(r2, cos_53); + t = ixheaacd_mult32_shl(ixheaacd_add32_sat(r4, r2), cos_51); + r4 = ixheaacd_add32_sat( + t, ixheaacd_shl32_sat(ixheaacd_mult32_shl(r4, cos_52), 1)); + r2 = ixheaacd_add32_sat(t, ixheaacd_mult32_shl(r2, cos_53)); - s1 = buf1a[3] + buf1a[9]; - s4 = buf1a[3] - buf1a[9]; - s3 = buf1a[5] + buf1a[7]; - s2 = buf1a[5] - buf1a[7]; + s1 = ixheaacd_add32_sat(buf1a[3], buf1a[9]); + s4 = ixheaacd_sub32_sat(buf1a[3], buf1a[9]); + s3 = ixheaacd_add32_sat(buf1a[5], buf1a[7]); + s2 = ixheaacd_sub32_sat(buf1a[5], buf1a[7]); - t = ixheaacd_mult32_shl((s1 - s3), cos_54); + t = ixheaacd_mult32_shl(ixheaacd_sub32_sat(s1, s3), cos_54); - s1 = s1 + s3; + s1 = ixheaacd_add32_sat(s1, s3); - temp2 = buf1a[1] + s1; + temp2 = ixheaacd_add32_sat(buf1a[1], s1); - s1 = temp2 + ((ixheaacd_mult32_shl(s1, cos_55)) << 1); + s1 = ixheaacd_add32_sat( + temp2, ixheaacd_shl32_sat((ixheaacd_mult32_shl(s1, cos_55)), 1)); - s3 = s1 - t; - s1 = s1 + t; + s3 = ixheaacd_sub32_sat(s1, t); + s1 = ixheaacd_add32_sat(s1, t); - t = ixheaacd_mult32_shl((s4 + s2), cos_51); - s4 = t + ((ixheaacd_mult32_shl(s4, cos_52)) << 1); - s2 = t + (ixheaacd_mult32_shl(s2, cos_53)); + t = ixheaacd_mult32_shl(ixheaacd_add32_sat(s4, s2), cos_51); + s4 = ixheaacd_add32_sat( + t, ixheaacd_shl32_sat((ixheaacd_mult32_shl(s4, cos_52)), 1)); + s2 = ixheaacd_add32_sat(t, (ixheaacd_mult32_shl(s2, cos_53))); *buf2++ = temp1; *buf2++ = temp2; - *buf2++ = r1 + s2; - *buf2++ = s1 - r2; - *buf2++ = r3 - s4; - *buf2++ = s3 + r4; - *buf2++ = r3 + s4; - *buf2++ = s3 - r4; - *buf2++ = r1 - s2; - *buf2++ = s1 + r2; + *buf2++ = ixheaacd_add32_sat(r1, s2); + *buf2++ = ixheaacd_sub32_sat(s1, r2); + *buf2++ = ixheaacd_sub32_sat(r3, s4); + *buf2++ = ixheaacd_add32_sat(s3, r4); + *buf2++ = ixheaacd_add32_sat(r3, s4); + *buf2++ = ixheaacd_sub32_sat(s3, r4); + *buf2++ = ixheaacd_sub32_sat(r1, s2); + *buf2++ = ixheaacd_add32_sat(s1, r2); buf1a = buf1; ; @@ -2380,56 +2388,60 @@ VOID ixheaacd_fft_15_ld_dec(WORD32 *inp, WORD32 *op, WORD32 *fft3out, *buf1++ = inp[224]; *buf1++ = inp[225]; - r1 = buf1a[2] + buf1a[8]; - r4 = buf1a[2] - buf1a[8]; - r3 = buf1a[4] + buf1a[6]; - r2 = buf1a[4] - buf1a[6]; + r1 = ixheaacd_add32_sat(buf1a[2], buf1a[8]); + r4 = ixheaacd_sub32_sat(buf1a[2], buf1a[8]); + r3 = ixheaacd_add32_sat(buf1a[4], buf1a[6]); + r2 = ixheaacd_sub32_sat(buf1a[4], buf1a[6]); - t = ixheaacd_mult32_shl((r1 - r3), cos_54); + t = ixheaacd_mult32_shl(ixheaacd_sub32_sat(r1, r3), cos_54); - r1 = r1 + r3; + r1 = ixheaacd_add32_sat(r1, r3); - temp1 = buf1a[0] + r1; + temp1 = ixheaacd_add32_sat(buf1a[0], r1); - r1 = temp1 + ((ixheaacd_mult32_shl(r1, cos_55)) << 1); + r1 = ixheaacd_add32_sat( + temp1, ixheaacd_shl32_sat((ixheaacd_mult32_shl(r1, cos_55)), 1)); - r3 = r1 - t; - r1 = r1 + t; + r3 = ixheaacd_sub32_sat(r1, t); + r1 = ixheaacd_add32_sat(r1, t); - t = ixheaacd_mult32_shl((r4 + r2), cos_51); - r4 = t + (ixheaacd_mult32_shl(r4, cos_52) << 1); - r2 = t + ixheaacd_mult32_shl(r2, cos_53); + t = ixheaacd_mult32_shl(ixheaacd_add32_sat(r4, r2), cos_51); + r4 = ixheaacd_add32_sat( + t, ixheaacd_shl32_sat(ixheaacd_mult32_shl(r4, cos_52), 1)); + r2 = ixheaacd_add32_sat(t, ixheaacd_mult32_shl(r2, cos_53)); - s1 = buf1a[3] + buf1a[9]; - s4 = buf1a[3] - buf1a[9]; - s3 = buf1a[5] + buf1a[7]; - s2 = buf1a[5] - buf1a[7]; + s1 = ixheaacd_add32_sat(buf1a[3], buf1a[9]); + s4 = ixheaacd_sub32_sat(buf1a[3], buf1a[9]); + s3 = ixheaacd_add32_sat(buf1a[5], buf1a[7]); + s2 = ixheaacd_sub32_sat(buf1a[5], buf1a[7]); - t = ixheaacd_mult32_shl((s1 - s3), cos_54); + t = ixheaacd_mult32_shl(ixheaacd_sub32_sat(s1, s3), cos_54); - s1 = s1 + s3; + s1 = ixheaacd_add32_sat(s1, s3); - temp2 = buf1a[1] + s1; + temp2 = ixheaacd_add32_sat(buf1a[1], s1); - s1 = temp2 + ((ixheaacd_mult32_shl(s1, cos_55)) << 1); + s1 = ixheaacd_add32_sat( + temp2, ixheaacd_shl32_sat((ixheaacd_mult32_shl(s1, cos_55)), 1)); - s3 = s1 - t; - s1 = s1 + t; + s3 = ixheaacd_sub32_sat(s1, t); + s1 = ixheaacd_add32_sat(s1, t); - t = ixheaacd_mult32_shl((s4 + s2), cos_51); - s4 = t + ((ixheaacd_mult32_shl(s4, cos_52)) << 1); - s2 = t + (ixheaacd_mult32_shl(s2, cos_53)); + t = ixheaacd_mult32_shl(ixheaacd_add32_sat(s4, s2), cos_51); + s4 = ixheaacd_add32_sat( + t, ixheaacd_shl32_sat((ixheaacd_mult32_shl(s4, cos_52)), 1)); + s2 = ixheaacd_add32_sat(t, (ixheaacd_mult32_shl(s2, cos_53))); *buf2++ = temp1; *buf2++ = temp2; - *buf2++ = r1 + s2; - *buf2++ = s1 - r2; - *buf2++ = r3 - s4; - *buf2++ = s3 + r4; - *buf2++ = r3 + s4; - *buf2++ = s3 - r4; - *buf2++ = r1 - s2; - *buf2++ = s1 + r2; + *buf2++ = ixheaacd_add32_sat(r1, s2); + *buf2++ = ixheaacd_sub32_sat(s1, r2); + *buf2++ = ixheaacd_sub32_sat(r3, s4); + *buf2++ = ixheaacd_add32_sat(s3, r4); + *buf2++ = ixheaacd_add32_sat(r3, s4); + *buf2++ = ixheaacd_sub32_sat(s3, r4); + *buf2++ = ixheaacd_sub32_sat(r1, s2); + *buf2++ = ixheaacd_add32_sat(s1, r2); buf1a = buf1; ; } @@ -2445,14 +2457,14 @@ VOID ixheaacd_fft_15_ld_dec(WORD32 *inp, WORD32 *op, WORD32 *fft3out, xr_2 = fft3outptr[20]; xi_2 = fft3outptr[21]; - x01_real = ixheaacd_add32(xr_0, xr_1); - x_01_imag = ixheaacd_add32(xi_0, xi_1); + x01_real = ixheaacd_add32_sat(xr_0, xr_1); + x_01_imag = ixheaacd_add32_sat(xi_0, xi_1); - add_r = ixheaacd_add32(xr_1, xr_2); - add_i = ixheaacd_add32(xi_1, xi_2); + add_r = ixheaacd_add32_sat(xr_1, xr_2); + add_i = ixheaacd_add32_sat(xi_1, xi_2); - sub_r = ixheaacd_sub32(xr_1, xr_2); - sub_i = ixheaacd_sub32(xi_1, xi_2); + sub_r = ixheaacd_sub32_sat(xr_1, xr_2); + sub_i = ixheaacd_sub32_sat(xi_1, xi_2); p1 = add_r >> 1; @@ -2461,21 +2473,21 @@ VOID ixheaacd_fft_15_ld_dec(WORD32 *inp, WORD32 *op, WORD32 *fft3out, p4 = add_i >> 1; - temp = ixheaacd_sub32(xr_0, p1); - temp1 = ixheaacd_add32(xi_0, p3); - temp2 = ixheaacd_sub32(xi_0, p3); + temp = ixheaacd_sub32_sat(xr_0, p1); + temp1 = ixheaacd_add32_sat(xi_0, p3); + temp2 = ixheaacd_sub32_sat(xi_0, p3); idx = re_arr_tab_sml_240_ptr[n++] << 1; - op[idx] = ixheaacd_add32(x01_real, xr_2); - op[idx + 1] = ixheaacd_add32(x_01_imag, xi_2); + op[idx] = ixheaacd_add32_sat(x01_real, xr_2); + op[idx + 1] = ixheaacd_add32_sat(x_01_imag, xi_2); idx = re_arr_tab_sml_240_ptr[n++] << 1; - op[idx] = ixheaacd_add32(temp, p2); - op[idx + 1] = ixheaacd_sub32(temp2, p4); + op[idx] = ixheaacd_add32_sat(temp, p2); + op[idx + 1] = ixheaacd_sub32_sat(temp2, p4); idx = re_arr_tab_sml_240_ptr[n++] << 1; - op[idx] = ixheaacd_sub32(temp, p2); - op[idx + 1] = ixheaacd_sub32(temp1, p4); + op[idx] = ixheaacd_sub32_sat(temp, p2); + op[idx + 1] = ixheaacd_sub32_sat(temp1, p4); fft3outptr += 2; } } \ No newline at end of file diff --git a/decoder/ixheaacd_aac_rom.h b/decoder/ixheaacd_aac_rom.h index 0d99e9e..a6a8142 100644 --- a/decoder/ixheaacd_aac_rom.h +++ b/decoder/ixheaacd_aac_rom.h @@ -21,6 +21,7 @@ #define IXHEAACD_AAC_ROM_H #define AAC_NF_NO_RANDOM_VAL 512 +#define MAX_CB_SIZE 13 typedef struct { WORD32 ixheaacd_pow_table_Q13[129]; @@ -153,8 +154,8 @@ typedef struct { WORD16 sfb_long_table[52]; WORD16 sfb_short_table[16]; - UWORD16 *code_book[13]; - UWORD32 *index_table[13]; + UWORD16 *code_book[MAX_CB_SIZE]; + UWORD32 *index_table[MAX_CB_SIZE]; WORD8 *scale_fac_bands_512[16]; WORD8 *scale_fac_bands_480[16]; diff --git a/decoder/ixheaacd_aac_tns.c b/decoder/ixheaacd_aac_tns.c index 99f8c05..3fbaf9a 100644 --- a/decoder/ixheaacd_aac_tns.c +++ b/decoder/ixheaacd_aac_tns.c @@ -52,13 +52,14 @@ #include "ixheaacd_aacdec.h" -static PLATFORM_INLINE WORD32 ixheaacd_mac32_tns(WORD32 a, WORD32 b, WORD32 c) { +static PLATFORM_INLINE WORD32 ixheaacd_mac32_tns_sat(WORD32 a, WORD32 b, + WORD32 c) { WORD32 result; WORD64 temp_result; temp_result = (WORD64)a * (WORD64)b; result = (WORD32)(temp_result >> 32); - result = ixheaacd_add32(c, result); + result = ixheaacd_add32_sat(c, result); return (result); } @@ -225,29 +226,29 @@ VOID ixheaacd_tns_ar_filter_fixed_dec(WORD32 *spectrum, WORD32 size, WORD32 inc, { WORD32 temp_lo = 0; for (i = 0; i < order; i++) { - y = (*spectrum) << scale_spec; + y = ixheaacd_shl32_sat((*spectrum), scale_spec); acc = 0; for (j = i; j > 0; j--) { - acc = ixheaacd_mac32_tns(state[j - 1], lpc[j], acc); + acc = ixheaacd_mac32_tns_sat(state[j - 1], lpc[j], acc); state[j] = state[j - 1]; } - y = ixheaacd_sub32(y, (acc << 1)); - state[0] = ixheaacd_shl32(y, shift_value); + y = ixheaacd_sub32_sat(y, ixheaacd_shl32_sat(acc, 1)); + state[0] = ixheaacd_shl32_sat(y, shift_value); *spectrum = y >> scale_spec; spectrum += inc; } temp_lo = 0; for (i = order; i < size; i++) { - y = (*spectrum) << scale_spec; + y = ixheaacd_shl32_sat((*spectrum), scale_spec); acc = 0; for (j = order; j > 0; j--) { - acc = ixheaacd_mac32_tns(state[j - 1], lpc[j], acc); + acc = ixheaacd_mac32_tns_sat(state[j - 1], lpc[j], acc); state[j] = state[j - 1]; } - y = ixheaacd_sub32(y, (acc << 1)); - state[0] = ixheaacd_shl32(y, shift_value); + y = ixheaacd_sub32_sat(y, ixheaacd_shl32_sat(acc, 1)); + state[0] = ixheaacd_shl32_sat(y, shift_value); *spectrum = y >> scale_spec; spectrum += inc; @@ -274,15 +275,15 @@ VOID ixheaacd_tns_ar_filter_fixed_non_neon_armv7(WORD32 *spectrum, WORD32 size, { WORD32 temp_lo = 0; for (i = 0; i < order; i++) { - y = (*spectrum) << scale_spec; + y = ixheaacd_shl32_sat((*spectrum), scale_spec); acc = 0; for (j = i; j > 0; j--) { - acc = ixheaacd_mac32_tns(state[j - 1], lpc[j], acc); + acc = ixheaacd_mac32_tns_sat(state[j - 1], lpc[j], acc); state[j] = state[j - 1]; } - y = ixheaacd_sub32(y, (acc << 1)); - state[0] = ixheaacd_shl32(y, shift_value); + y = ixheaacd_sub32_sat(y, ixheaacd_shl32_sat(acc, 1)); + state[0] = ixheaacd_shl32_sat(y, shift_value); *spectrum = y >> scale_spec; spectrum += inc; @@ -291,15 +292,15 @@ VOID ixheaacd_tns_ar_filter_fixed_non_neon_armv7(WORD32 *spectrum, WORD32 size, for (i = order; i < size; i++) { WORD64 acc = 0; WORD32 acc1; - y = (*spectrum) << scale_spec; + y = ixheaacd_shl32_sat((*spectrum), scale_spec); for (j = order; j > 0; j--) { acc = mac32x32in64_dual(state[j - 1], lpc[j], acc); state[j] = state[j - 1]; } acc1 = (WORD32)(acc >> 32); - y = ixheaacd_sub32(y, (acc1 << 1)); - state[0] = ixheaacd_shl32(y, shift_value); + y = ixheaacd_sub32_sat(y, ixheaacd_shl32_sat(acc1, 1)); + state[0] = ixheaacd_shl32_sat(y, shift_value); *spectrum = y >> scale_spec; spectrum += inc; @@ -324,15 +325,15 @@ VOID ixheaacd_tns_ar_filter_fixed_armv8(WORD32 *spectrum, WORD32 size, { WORD32 temp_lo = 0; for (i = 0; i < order; i++) { - y = (*spectrum) << scale_spec; + y = ixheaacd_shl32_sat((*spectrum), scale_spec); acc = 0; for (j = i; j > 0; j--) { - acc = ixheaacd_mac32_tns(state[j - 1], lpc[j], acc); + acc = ixheaacd_mac32_tns_sat(state[j - 1], lpc[j], acc); state[j] = state[j - 1]; } - y = ixheaacd_sub32(y, (acc << 1)); - state[0] = ixheaacd_shl32(y, shift_value); + y = ixheaacd_sub32_sat(y, ixheaacd_shl32_sat(acc, 1)); + state[0] = ixheaacd_shl32_sat(y, shift_value); *spectrum = y >> scale_spec; spectrum += inc; @@ -341,15 +342,15 @@ VOID ixheaacd_tns_ar_filter_fixed_armv8(WORD32 *spectrum, WORD32 size, for (i = order; i < size; i++) { WORD64 acc = 0; WORD32 acc1; - y = (*spectrum) << scale_spec; + y = ixheaacd_shl32_sat((*spectrum), scale_spec); for (j = order; j > 0; j--) { acc = ixheaacd_mac32x32in64_dual(state[j - 1], lpc[j], acc); state[j] = state[j - 1]; } acc1 = (WORD32)(acc >> 32); - y = ixheaacd_sub32(y, (acc1 << 1)); - state[0] = ixheaacd_shl32(y, shift_value); + y = ixheaacd_sub32(y, ixheaacd_shl32_sat(acc1, 1)); + state[0] = ixheaacd_shl32_sat(y, shift_value); *spectrum = y >> scale_spec; spectrum += inc; @@ -394,32 +395,32 @@ VOID ixheaacd_tns_ar_filter_dec(WORD32 *spectrum, WORD32 size, WORD32 inc, } for (i = 0; i < order; i++) { - y = (*spectrum) << scale_spec; + y = ixheaacd_shl32_sat((*spectrum), scale_spec); acc = 0; for (j = i; j > 0; j--) { - acc = ixheaacd_add32( + acc = ixheaacd_add32_sat( acc, ixheaacd_mult32x16in32(ptr_filter_state[j - 1], lpc[j])); ptr_filter_state[j] = ptr_filter_state[j - 1]; } - y = ixheaacd_sub32(y, (acc << 1)); - ptr_filter_state[0] = ixheaacd_shl32(y, shift_value); + y = ixheaacd_sub32_sat(y, ixheaacd_shl32_sat(acc, 1)); + ptr_filter_state[0] = ixheaacd_shl32_sat(y, shift_value); *spectrum = y >> scale_spec; spectrum += inc; } for (i = order; i < size; i++) { - y = (*spectrum) << scale_spec; + y = ixheaacd_shl32_sat((*spectrum), scale_spec); acc = 0; for (j = order; j > 0; j--) { - acc = ixheaacd_add32( + acc = ixheaacd_add32_sat( acc, ixheaacd_mult32x16in32(ptr_filter_state[j - 1], lpc[j])); ptr_filter_state[j] = ptr_filter_state[j - 1]; } - y = ixheaacd_sub32(y, (acc << 1)); - ptr_filter_state[0] = ixheaacd_shl32(y, shift_value); + y = ixheaacd_sub32_sat(y, ixheaacd_shl32_sat(acc, 1)); + ptr_filter_state[0] = ixheaacd_shl32_sat(y, shift_value); *spectrum = y >> scale_spec; spectrum += inc; } diff --git a/decoder/ixheaacd_aacdec.h b/decoder/ixheaacd_aacdec.h index ec1af57..8f161eb 100644 --- a/decoder/ixheaacd_aacdec.h +++ b/decoder/ixheaacd_aacdec.h @@ -23,7 +23,6 @@ #define AAC_DEC_OK IA_ENHAACPLUS_DEC_API_NONFATAL_NO_ERROR #define IA_ENHAACPDEC_NUM_MEMTABS (4) -#define IA_MPS_DEC_NUM_MEMTABS (4) #define FRAME_SIZE 1024 diff --git a/decoder/ixheaacd_aacdecoder.c b/decoder/ixheaacd_aacdecoder.c index d47c244..19770ad 100644 --- a/decoder/ixheaacd_aacdecoder.c +++ b/decoder/ixheaacd_aacdecoder.c @@ -510,7 +510,12 @@ WORD32 ixheaacd_aacdec_decodeframe( goto _ia_handle_error; } aac_dec_handle->frame_status = 0; - error_code = IA_ENHAACPLUS_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; + if (error_code > 0) { + error_code = IA_ENHAACPLUS_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; + return error_code; + } else { + return error_code; + } } } @@ -743,25 +748,15 @@ WORD32 ixheaacd_aacdec_decodeframe( if (ele_type == ID_END && p_state_enhaacplus_dec->bs_format == LOAS_BSFORMAT) { - WORD16 tmp; - tmp = ((WORD16)latm_element->layer_info[0][0].frame_len_bits) - + WORD32 tmp; + tmp = ((WORD32)latm_element->layer_info[0][0].frame_len_bits) - (it_bit_buff->initial_cnt_bits - it_bit_buff->cnt_bits); if (tmp > 0) ixheaacd_read_bidirection(it_bit_buff, tmp); if (latm_element->other_data_present) { - tmp = latm_element->other_data_length; - ixheaacd_read_bidirection(it_bit_buff, tmp); - } - } - - if (p_obj_exhaacplus_dec->aac_config.ui_drc_enable) { - for (ch = 0; ch < num_ch; ch++) { - pstr_drc_dec->is_longblock[*ch_idx + ch] = - (aac_dec_handle->pstr_aac_dec_ch_info[ch] - ->str_ics_info.window_sequence == EIGHT_SHORT_SEQUENCE) - ? 0 - : 1; + WORD32 count_bits = (WORD32)latm_element->other_data_length; + ixheaacd_read_bidirection(it_bit_buff, count_bits); } } @@ -887,4 +882,4 @@ WORD32 ixheaacd_extension_payload(ia_bit_buf_struct *it_bit_buff, WORD32 cnt) { } return err; -} \ No newline at end of file +} diff --git a/decoder/ixheaacd_aacpluscheck.c b/decoder/ixheaacd_aacpluscheck.c index dafbdfa..15d74c3 100644 --- a/decoder/ixheaacd_aacpluscheck.c +++ b/decoder/ixheaacd_aacpluscheck.c @@ -47,6 +47,7 @@ #include "ixheaacd_sbrdecoder.h" #include "ixheaacd_sbr_payload.h" #include "ixheaacd_audioobjtypes.h" +#include "ixheaacd_error_codes.h" #define SBR_EXTENSION_MPEG SBR_EXTENSION @@ -151,12 +152,13 @@ FLAG ixheaacd_check_for_sbr_payload( } else { ixheaacd_read_bits_buf(it_bit_buff, 4); + if (it_bit_buff->cnt_bits < ((count - 1) << 3)) { + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } it_bit_buff->ptr_read_next += count - 1; it_bit_buff->cnt_bits -= ((count - 1) << 3); - if (it_bit_buff->ptr_read_next > it_bit_buff->ptr_bit_buf_end) { - it_bit_buff->ptr_read_next = it_bit_buff->ptr_bit_buf_base; - } } } if (it_bit_buff->cnt_bits < 0) ret = -1; diff --git a/decoder/ixheaacd_api.c b/decoder/ixheaacd_api.c index 68afd8f..1947a24 100644 --- a/decoder/ixheaacd_api.c +++ b/decoder/ixheaacd_api.c @@ -137,6 +137,8 @@ IA_ERRORCODE ixheaacd_dec_mem_api( return (IA_ENHAACPLUS_DEC_API_FATAL_MEM_ALIGN); } p_obj_exhaacplus_dec->pp_mem_aac[i_idx] = pv_value; + memset(p_obj_exhaacplus_dec->pp_mem_aac[i_idx], 0, + p_obj_exhaacplus_dec->p_mem_info_aac[i_idx].ui_size); if (i_idx == IA_ENHAACPLUS_DEC_PERSIST_IDX) { pUWORD8 p_temp = pv_value; @@ -148,9 +150,6 @@ IA_ERRORCODE ixheaacd_dec_mem_api( sizeof(ia_audio_specific_config_struct) + (8300)); p_obj_exhaacplus_dec->p_state_aac = pv_value; - memset(p_obj_exhaacplus_dec->p_state_aac, 0, - sizeof(ia_aac_dec_state_struct)); - p_obj_exhaacplus_dec->p_state_aac->pstr_dec_data = p_temp; p_obj_exhaacplus_dec->p_state_aac->ia_audio_specific_config = p_temp + sizeof(ia_dec_data_struct); @@ -380,6 +379,7 @@ IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_enhaacplus_dec_obj, WORD32 i_cmd, case IA_API_CMD_INIT: { switch (i_idx) { case IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS: { + memset(p_obj_exhaacplus_dec, 0, sizeof(*p_obj_exhaacplus_dec)); p_obj_exhaacplus_dec->aac_config.ui_pcm_wdsz = 16; p_obj_exhaacplus_dec->aac_config.flag_downmix = 0; p_obj_exhaacplus_dec->aac_config.flag_08khz_out = 0; @@ -411,6 +411,8 @@ IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_enhaacplus_dec_obj, WORD32 i_cmd, p_obj_exhaacplus_dec->aac_config.ui_coupling_channel = 0; p_obj_exhaacplus_dec->aac_config.downmix = 0; + p_obj_exhaacplus_dec->aac_config.ui_n_channels = 2; + p_obj_exhaacplus_dec->aac_config.i_channel_mask = 3; { ia_aac_dec_tables_struct *pstr_aac_tables = @@ -776,10 +778,14 @@ IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_enhaacplus_dec_obj, WORD32 i_cmd, case IA_API_CMD_GET_MEMTABS_SIZE: { *pui_value = (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) * - (IA_ENHAACPDEC_NUM_MEMTABS + IA_MPS_DEC_NUM_MEMTABS); + (IA_ENHAACPDEC_NUM_MEMTABS); break; } case IA_API_CMD_SET_MEMTABS_PTR: { + if (pv_value == NULL) return IA_ENHAACPLUS_DEC_API_FATAL_MEM_ALLOC; + memset(pv_value, 0, (sizeof(ia_mem_info_struct) + sizeof(pVOID *)) * + (IA_ENHAACPDEC_NUM_MEMTABS)); + p_obj_exhaacplus_dec->p_mem_info_aac = pv_value; p_obj_exhaacplus_dec->pp_mem_aac = (pVOID *)((WORD8 *)pv_value + @@ -800,8 +806,12 @@ IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_enhaacplus_dec_obj, WORD32 i_cmd, switch (i_idx) { case IA_CMD_TYPE_DO_EXECUTE: { WORD32 err_code = 0; - err_code = ixheaacd_dec_execute(p_obj_exhaacplus_dec); - if (err_code != 0) { + if (!p_obj_exhaacplus_dec->p_state_aac->ui_init_done) { + err_code = IA_FATAL_ERROR; + } else { + err_code = ixheaacd_dec_execute(p_obj_exhaacplus_dec); + } + if (err_code != IA_NO_ERROR) { p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; } @@ -1255,10 +1265,21 @@ IA_ERRORCODE ixheaacd_dec_init( IA_ERRORCODE err_code = IA_NO_ERROR; struct ia_aac_persistent_struct *aac_persistent_mem; struct ia_sbr_pers_struct *sbr_persistent_mem; + WORD32 ret_val; p_obj_exhaacplus_dec->p_state_aac = p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_PERSIST_IDX]; + if (p_obj_exhaacplus_dec->p_state_aac != NULL) { + ret_val = setjmp(p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf); + if (ret_val != 0) { + p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = + p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; + p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0; + return IA_NO_ERROR; + } + } + time_data = (WORD16 *)(p_obj_exhaacplus_dec ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]); @@ -1397,17 +1418,22 @@ IA_ERRORCODE ixheaacd_dec_init( return IA_NO_ERROR; } + memset(&(p_state_enhaacplus_dec->eld_specific_config), 0, + sizeof(ia_eld_specific_config_struct)); return_val = ixheaacd_aac_headerdecode( p_obj_exhaacplus_dec, (UWORD8 *)in_buffer, &header_bytes_consumed, aac_persistent_mem->str_aac_decoder.pstr_aac_tables ->pstr_huffmann_tables); - - memcpy(sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[0], - &p_obj_exhaacplus_dec->p_state_aac->str_sbr_config, - sizeof(ia_sbr_header_data_struct)); - memcpy(sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[1], - &p_obj_exhaacplus_dec->p_state_aac->str_sbr_config, - sizeof(ia_sbr_header_data_struct)); + if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD || + p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD) { + *sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[0] = + p_obj_exhaacplus_dec->p_state_aac->str_sbr_config; + *sbr_persistent_mem->str_sbr_dec_inst.pstr_sbr_header[1] = + p_obj_exhaacplus_dec->p_state_aac->str_sbr_config; + } else { + memset(&(p_state_enhaacplus_dec->eld_specific_config), 0, + sizeof(ia_eld_specific_config_struct)); + } if (return_val < 0) { if (return_val == @@ -1444,7 +1470,7 @@ IA_ERRORCODE ixheaacd_dec_init( p_obj_exhaacplus_dec, inbuffer, outbuffer, &out_bytes, frames_done, pcm_size, &p_obj_exhaacplus_dec->p_state_aac->num_of_output_ch); - if (error_code == -1) return error_code; + if (error_code) return error_code; p_obj_exhaacplus_dec->p_state_aac->frame_counter++; } else { out_bytes = 0; @@ -1455,8 +1481,6 @@ IA_ERRORCODE ixheaacd_dec_init( } if (return_val == 0) p_obj_exhaacplus_dec->p_state_aac->ui_init_done = 1; - - p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 1; return return_val; } @@ -1493,6 +1517,8 @@ IA_ERRORCODE ixheaacd_dec_init( &p_state_enhaacplus_dec->str_bit_buf, (UWORD8 *)in_buffer, p_obj_exhaacplus_dec->p_mem_info_aac[IA_ENHAACPLUS_DEC_INPUT_IDX] .ui_size); + p_state_enhaacplus_dec->pstr_bit_buf->xaac_jmp_buf = + &(p_state_enhaacplus_dec->xaac_jmp_buf); p_state_enhaacplus_dec->ptr_bit_stream = p_state_enhaacplus_dec->pstr_bit_buf; @@ -1577,7 +1603,7 @@ IA_ERRORCODE ixheaacd_dec_init( } } } else { - struct ia_bit_buf_struct temp_bit_buff; + struct ia_bit_buf_struct temp_bit_buff = {0}; ia_adts_header_struct adts; struct ia_bit_buf_struct *it_bit_buff; @@ -1612,6 +1638,8 @@ IA_ERRORCODE ixheaacd_dec_init( ixheaacd_create_init_bit_buf(it_bit_buff, in_buffer, p_state_enhaacplus_dec->ui_in_bytes); + p_state_enhaacplus_dec->pstr_bit_buf->xaac_jmp_buf = + &(p_state_enhaacplus_dec->xaac_jmp_buf); it_bit_buff->adts_header_present = p_state_enhaacplus_dec->s_adts_hdr_present; @@ -1786,6 +1814,9 @@ IA_ERRORCODE ixheaacd_dec_init( p_state_enhaacplus_dec->b_n_raw_data_blk--; } + sample_rate_2 = sample_rate_1; + frame_size_2 = frame_size_1; + if (!p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] && p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) { if ((p_obj_exhaacplus_dec->aac_config.flag_16khz_out == 1) && @@ -1793,9 +1824,6 @@ IA_ERRORCODE ixheaacd_dec_init( p_obj_exhaacplus_dec->aac_config.flag_16khz_out = 0; } - sample_rate_2 = sample_rate_1; - frame_size_2 = frame_size_1; - p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] = ixheaacd_init_sbr( sample_rate_1, frame_size_1, (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag, @@ -1804,10 +1832,15 @@ IA_ERRORCODE ixheaacd_dec_init( 1, frame_size_1 * 2, NULL, NULL, p_state_enhaacplus_dec->str_sbr_config, p_state_enhaacplus_dec->audio_object_type); + if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { + p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf = + &(p_state_enhaacplus_dec->xaac_jmp_buf); + } } else { } - if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { + if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] && + p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) { ia_sbr_scr_struct sbr_scratch_struct; WORD16 num_channels_1_t = num_channels_1; ixheaacd_allocate_sbr_scr( @@ -1862,6 +1895,10 @@ IA_ERRORCODE ixheaacd_dec_init( p_state_enhaacplus_dec->str_sbr_config, p_state_enhaacplus_dec->audio_object_type); } + if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { + p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf = + &(p_state_enhaacplus_dec->xaac_jmp_buf); + } } if (sample_rate < sample_rate_1) sample_rate = sample_rate_1; @@ -1895,6 +1932,7 @@ IA_ERRORCODE ixheaacd_dec_init( WORD max_ch_num = p_obj_exhaacplus_dec->aac_config.ui_max_channels; i = 0; + p_obj_exhaacplus_dec->aac_config.ui_n_channels = ch_idx; while (p_obj_exhaacplus_dec->aac_config.element_type[ch_idx_err] <= 3 && p_obj_exhaacplus_dec->aac_config.element_type[ch_idx_err] >= 0) { ch_idx_err++; @@ -1984,16 +2022,17 @@ IA_ERRORCODE ixheaacd_dec_init( return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL; } - p_state_enhaacplus_dec->str_sbr_dec_info[i] = 0; - if (sbr_present_flag) { - p_state_enhaacplus_dec->str_sbr_dec_info[i] = ixheaacd_init_sbr( - sample_rate_2, frame_size_2, - (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag, - p_state_enhaacplus_dec->sbr_persistent_mem_v, - p_state_enhaacplus_dec->ptr_overlap_buf, channel, ps_enable, 1, - frame_size_2 * 2, NULL, NULL, - p_state_enhaacplus_dec->str_sbr_config, - p_state_enhaacplus_dec->audio_object_type); + p_state_enhaacplus_dec->str_sbr_dec_info[i] = ixheaacd_init_sbr( + sample_rate_2, frame_size_2, + (FLAG *)&p_obj_exhaacplus_dec->aac_config.down_sample_flag, + p_state_enhaacplus_dec->sbr_persistent_mem_v, + p_state_enhaacplus_dec->ptr_overlap_buf, channel, ps_enable, 1, + frame_size_2 * 2, NULL, NULL, + p_state_enhaacplus_dec->str_sbr_config, + p_state_enhaacplus_dec->audio_object_type); + if (p_state_enhaacplus_dec->str_sbr_dec_info[i]) { + p_state_enhaacplus_dec->str_sbr_dec_info[i]->xaac_jmp_buf = + &(p_state_enhaacplus_dec->xaac_jmp_buf); } i++; @@ -2046,6 +2085,10 @@ IA_ERRORCODE ixheaacd_dec_init( memcpy(it_bit_buff, &temp_bit_buff, sizeof(struct ia_bit_buf_struct)); p_state_enhaacplus_dec->b_n_raw_data_blk = 0; + + if (p_obj_exhaacplus_dec->p_state_aac->header_dec_done == 1) { + p_obj_exhaacplus_dec->p_state_aac->header_dec_done = 0; + } } return err_code; } @@ -2099,7 +2142,7 @@ VOID ixheaacd_fill_prog_config_slots( IA_ERRORCODE ixheaacd_dec_execute( ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec) { - ia_adts_header_struct adts; + ia_adts_header_struct adts = {0}; ia_aac_dec_state_struct *p_state_enhaacplus_dec; UWORD8 *in_buffer; @@ -2108,7 +2151,7 @@ IA_ERRORCODE ixheaacd_dec_execute( WORD16 frame_size = 0; WORD32 sample_rate_dec = 0; WORD32 sample_rate = 0; - WORD16 num_ch; + WORD16 num_ch = 0; struct ia_bit_buf_struct *it_bit_buff; WORD32 error_code = IA_NO_ERROR; WORD ch_idx1; @@ -2123,9 +2166,20 @@ IA_ERRORCODE ixheaacd_dec_execute( SIZE_T bytes_for_sync; WORD32 audio_mux_length_bytes_last = 0; + WORD32 ret_val; p_obj_exhaacplus_dec->aac_config.ui_sbr_mode = 0; + if (p_obj_exhaacplus_dec->p_state_aac != NULL) { + ret_val = setjmp(p_obj_exhaacplus_dec->p_state_aac->xaac_jmp_buf); + if (ret_val != 0) { + p_obj_exhaacplus_dec->p_state_aac->i_bytes_consumed = + p_obj_exhaacplus_dec->p_state_aac->ui_in_bytes; + p_obj_exhaacplus_dec->p_state_aac->ui_out_bytes = 0; + return IA_NO_ERROR; + } + } + time_data = (WORD16 *)(p_obj_exhaacplus_dec ->pp_mem_aac[IA_ENHAACPLUS_DEC_OUTPUT_IDX]); in_buffer = p_obj_exhaacplus_dec->pp_mem_aac[IA_ENHAACPLUS_DEC_INPUT_IDX]; @@ -2232,6 +2286,7 @@ IA_ERRORCODE ixheaacd_dec_execute( { ixheaacd_create_init_bit_buf(it_bit_buff, in_buffer, p_state_enhaacplus_dec->ui_in_bytes); + it_bit_buff->xaac_jmp_buf = &(p_state_enhaacplus_dec->xaac_jmp_buf); it_bit_buff->adts_header_present = p_state_enhaacplus_dec->s_adts_hdr_present; @@ -2420,6 +2475,10 @@ IA_ERRORCODE ixheaacd_dec_execute( p_state_enhaacplus_dec->frame_length ); + if (!p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]) { + p_state_enhaacplus_dec->i_bytes_consumed = 1; + return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL; + } p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->p_ind_channel_info = (WORD8 *)p_state_enhaacplus_dec->aac_scratch_mem_v + (8 * 1024) + pers_used; @@ -2444,6 +2503,9 @@ IA_ERRORCODE ixheaacd_dec_execute( time_data, channel, p_obj_exhaacplus_dec->aac_config.ui_max_channels, p_state_enhaacplus_dec->audio_object_type); + if(p_state_enhaacplus_dec->ch_config == 2 && channel == 1) + return IA_ENHAACPLUS_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; + error_code = ixheaacd_aacdec_decodeframe( p_obj_exhaacplus_dec, &aac_scratch_struct, actual_out_buffer, p_obj_exhaacplus_dec->aac_config.frame_status, &type, &ch_idx, 0, @@ -2472,6 +2534,7 @@ IA_ERRORCODE ixheaacd_dec_execute( } } + num_ch = p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->channels; if (skip_full_decode == 0) { if (p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_ELD || p_state_enhaacplus_dec->audio_object_type == AOT_ER_AAC_LD) @@ -2481,7 +2544,6 @@ IA_ERRORCODE ixheaacd_dec_execute( sample_rate_dec = p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->sampling_rate; - num_ch = p_state_enhaacplus_dec->pstr_aac_dec_info[ch_idx]->channels; } } @@ -2524,10 +2586,15 @@ IA_ERRORCODE ixheaacd_dec_execute( ps_enable, 1, frame_size * 2, NULL, NULL, p_state_enhaacplus_dec->str_sbr_config, p_state_enhaacplus_dec->audio_object_type); + if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { + p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]->xaac_jmp_buf = + &(p_state_enhaacplus_dec->xaac_jmp_buf); + } } { - if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx]) { + if (p_state_enhaacplus_dec->str_sbr_dec_info[ch_idx] && + p_state_enhaacplus_dec->pstr_stream_sbr[0][0].no_elements) { ia_sbr_scr_struct sbr_scratch_struct; ixheaacd_allocate_sbr_scr(&sbr_scratch_struct, p_state_enhaacplus_dec->aac_scratch_mem_v, diff --git a/decoder/ixheaacd_arith_dec.c b/decoder/ixheaacd_arith_dec.c index 77b516d..14bb414 100644 --- a/decoder/ixheaacd_arith_dec.c +++ b/decoder/ixheaacd_arith_dec.c @@ -1662,17 +1662,7 @@ static void ixheaacd_arith_map_context(WORD32 pres_n, WORD32 prev_n, VOID ixheaacd_copy_to_bitbuff(ia_bit_buf_struct *it_bit_buff_src, ia_bit_buf_struct *it_bit_buff_dst) { - it_bit_buff_dst->ptr_bit_buf_base = it_bit_buff_src->ptr_bit_buf_base; - it_bit_buff_dst->ptr_bit_buf_end = it_bit_buff_src->ptr_bit_buf_end; - - it_bit_buff_dst->ptr_read_next = it_bit_buff_src->ptr_read_next; - - it_bit_buff_dst->bit_pos = it_bit_buff_src->bit_pos; - it_bit_buff_dst->cnt_bits = it_bit_buff_src->cnt_bits; - - it_bit_buff_dst->size = it_bit_buff_src->size; - - it_bit_buff_dst->max_size = it_bit_buff_src->max_size; + *it_bit_buff_dst = *it_bit_buff_src; } static WORD32 ixheaacd_arith_get_context(WORD8 *c_prev, WORD8 *c_pres, @@ -1699,7 +1689,13 @@ static WORD32 ixheaacd_arith_first_symbol(ia_bit_buf_struct *it_bit_buff, WORD32 bit_count = 16; val = 0; - val = ixheaacd_read_bits_buf(it_bit_buff, 16); + if (it_bit_buff->cnt_bits < 16) { + WORD32 shift_value = 16 - it_bit_buff->cnt_bits; + val = ixheaacd_read_bits_buf(it_bit_buff, it_bit_buff->cnt_bits); + val <<= shift_value; + } else { + val = ixheaacd_read_bits_buf(it_bit_buff, 16); + } s->low = 0; s->high = 65535; @@ -1738,6 +1734,17 @@ static WORD32 ixheaacd_arith_decode(ia_bit_buf_struct *it_bit_buff, register UWORD16 const *p; register UWORD16 const *q; + WORD32 short_value, i = 16; + int shift_value; + if (it_bit_buff->cnt_bits < 16) { + shift_value = 16 - it_bit_buff->cnt_bits; + short_value = ixheaacd_read_bits_buf(it_bit_buff, it_bit_buff->cnt_bits); + short_value <<= shift_value; + } else { + shift_value = 0; + short_value = ixheaacd_read_bits_buf(it_bit_buff, 16); + } + low = s->low; high = s->high; value = s->value; @@ -1779,10 +1786,12 @@ static WORD32 ixheaacd_arith_decode(ia_bit_buf_struct *it_bit_buff, low += low; high += high + 1; - value = (value << 1) | ixheaacd_read_bits_buf(it_bit_buff, 1); + i--; + value = (value << 1) | ((short_value >> i) & 1); bit_count++; } + ixheaacd_read_bidirection(it_bit_buff, -(i - shift_value)); s->low = low; s->high = high; s->value = value; @@ -1800,7 +1809,7 @@ WORD32 ixheaacd_arth_decoding_level2(ia_bit_buf_struct *it_bit_buff, WORD32 i, j, lev, pki, esc_nb; WORD32 m; WORD32 c = 0; - struct ia_bit_buf_struct it_bit_buff_temp; + struct ia_bit_buf_struct it_bit_buff_temp = {0}; WORD32 bit_count = 0; WORD32 s1; WORD32 temp; diff --git a/decoder/ixheaacd_avq_dec.c b/decoder/ixheaacd_avq_dec.c index 478edd8..15c228c 100644 --- a/decoder/ixheaacd_avq_dec.c +++ b/decoder/ixheaacd_avq_dec.c @@ -24,12 +24,15 @@ #include #include #include +#include "ixheaacd_constants.h" +#include +#include #include "ixheaacd_acelp_com.h" extern const WORD32 ixheaacd_factorial_7[8]; extern const WORD32 ixheaacd_iso_code_index_table[LEN_ABS_LEADER]; -extern const UWORD8 ixheaacd_iso_code_data_table[LEN_ABS_LEADER]; -extern const UWORD32 ixheaacd_signed_leader_is[LEN_ABS_LEADER]; +extern const UWORD8 ixheaacd_iso_code_data_table[LEN_SIGN_LEADER]; +extern const UWORD32 ixheaacd_signed_leader_is[LEN_SIGN_LEADER]; extern const WORD32 ixheaacd_iso_code_num_table[], ixheaacd_pos_abs_leaders_a3[], ixheaacd_pos_abs_leaders_a4[]; extern const UWORD8 ixheaacd_absolute_leader_tab_da[][8]; @@ -55,9 +58,10 @@ static VOID ixheaacd_nearest_neighbor_2d(WORD32 x[], WORD32 y[], WORD32 count, if (x[i] % 2 != 0) { if (x[i] < 0) { - rem_temp[i] = -(rem_temp[i] - (1 << count)); + rem_temp[i] = ixheaacd_negate32_sat( + ixheaacd_sub32_sat(rem_temp[i], (1 << count))); } else { - rem_temp[i] = rem_temp[i] - (1 << count); + rem_temp[i] = ixheaacd_sub32_sat(rem_temp[i], (1 << count)); } } } @@ -83,10 +87,10 @@ static VOID ixheaacd_nearest_neighbor_2d(WORD32 x[], WORD32 y[], WORD32 count, if (e[j] < 0) { y[j] -= 2; - rem_temp[j] = rem_temp[j] + (2 << count); + rem_temp[j] = ixheaacd_add32_sat(rem_temp[j], (2 << count)); } else { y[j] += 2; - rem_temp[j] = rem_temp[j] - (2 << count); + rem_temp[j] = ixheaacd_sub32_sat(rem_temp[j], (2 << count)); } } @@ -98,7 +102,7 @@ VOID ixheaacd_voronoi_search(WORD32 x[], WORD32 y[], WORD32 count, WORD32 *rem1, WORD32 *rem2) { WORD32 i, y0[8], y1[8]; WORD32 x1[8], tmp; - WORD64 e0, e1; + WORD32 e0, e1; ixheaacd_nearest_neighbor_2d(x, y0, count, rem1); for (i = 0; i < 8; i++) { @@ -107,7 +111,7 @@ VOID ixheaacd_voronoi_search(WORD32 x[], WORD32 y[], WORD32 count, WORD32 *rem1, x1[i] = x[i] - 1; } else { x1[i] = 0; - rem2[i] = rem2[i] - (1 << count); + rem2[i] = ixheaacd_sub32_sat(rem2[i], (1 << count)); } } else { x1[i] = x[i] - 1; @@ -123,9 +127,9 @@ VOID ixheaacd_voronoi_search(WORD32 x[], WORD32 y[], WORD32 count, WORD32 *rem1, e0 = e1 = 0; for (i = 0; i < 8; i++) { tmp = rem1[i]; - e0 += (WORD64)tmp * tmp; + e0 = ixheaacd_add32_sat(ixheaacd_sat64_32((WORD64)tmp * (WORD64)tmp), e0); tmp = rem2[i]; - e1 += (WORD64)tmp * tmp; + e1 = ixheaacd_add32_sat(ixheaacd_sat64_32((WORD64)tmp * (WORD64)tmp), e1); } if (e0 < e1) { @@ -151,13 +155,15 @@ VOID ixheaacd_voronoi_idx_dec(WORD32 *kv, WORD32 m, WORD32 *y, WORD32 count) { rem1[7] = y[7] & (m - 1); sum = 0; for (i = 6; i >= 1; i--) { - tmp = 2 * kv[i]; - sum += tmp; - y[i] += tmp; + tmp = ixheaacd_shl32_sat(kv[i], 1); + sum = ixheaacd_add32_sat(sum, tmp); + y[i] = ixheaacd_add32_sat(y[i], tmp); z[i] = y[i] >> count; rem1[i] = y[i] & (m - 1); } - y[0] += (4 * kv[0] + sum); + y[0] = ixheaacd_add32_sat( + y[0], + ixheaacd_add32_sat(ixheaacd_sat64_32((WORD64)4 * (WORD64)kv[0]), sum)); z[0] = (y[0] - 2) >> count; if (m != 0) rem1[0] = (y[0] - 2) % m; @@ -171,7 +177,7 @@ VOID ixheaacd_voronoi_idx_dec(WORD32 *kv, WORD32 m, WORD32 *y, WORD32 count) { ptr1 = y; ptr2 = v; for (i = 0; i < 8; i++) { - *ptr1++ -= m * *ptr2++; + *ptr1++ -= ixheaacd_sat64_32((WORD64)m * (WORD64)*ptr2++); } } @@ -275,24 +281,29 @@ static VOID ixheaacd_gosset_decode_base_index(WORD32 n, UWORD32 code_book_ind, VOID ixheaacd_rotated_gosset_mtx_dec(WORD32 qn, WORD32 code_book_idx, WORD32 *kv, WORD32 *b) { - WORD32 i, m, c[8]; - WORD32 count = 0; - if (qn <= 4) { ixheaacd_gosset_decode_base_index(qn, code_book_idx, b); } else { - m = 1; + WORD32 i, m, c[8]; + WORD32 count = 0; while (qn > 4) { - m *= 2; count++; qn -= 2; } + if (count >= 31) + m = MAX_32; + else + m = 1 << count; + ixheaacd_gosset_decode_base_index(qn, code_book_idx, b); ixheaacd_voronoi_idx_dec(kv, m, c, count); - for (i = 0; i < 8; i++) b[i] = m * b[i] + c[i]; + for (i = 0; i < 8; i++) { + b[i] = + ixheaacd_add32_sat(ixheaacd_sat64_32((WORD64)m * (WORD64)b[i]), c[i]); + } } return; } diff --git a/decoder/ixheaacd_basic_ops32.h b/decoder/ixheaacd_basic_ops32.h index b25972f..f9a5299 100644 --- a/decoder/ixheaacd_basic_ops32.h +++ b/decoder/ixheaacd_basic_ops32.h @@ -65,19 +65,13 @@ static PLATFORM_INLINE WORD32 ixheaacd_shr32(WORD32 a, WORD b) { } static PLATFORM_INLINE WORD32 ixheaacd_shl32_sat(WORD32 a, WORD b) { - WORD32 out_val = a; - for (; b > 0; b--) { - if (a > (WORD32)0X3fffffffL) { - out_val = MAX_32; - break; - } else if (a < (WORD32)0xc0000000L) { - out_val = MIN_32; - break; - } - - a = ixheaacd_shl32(a, 1); - out_val = a; - } + WORD32 out_val; + if (a > (MAX_32 >> b)) + out_val = MAX_32; + else if (a < (MIN_32 >> b)) + out_val = MIN_32; + else + out_val = a << b; return (out_val); } @@ -380,13 +374,13 @@ static PLATFORM_INLINE WORD32 div32(WORD32 a, WORD32 b, WORD *q_format) { return quotient; } -static PLATFORM_INLINE WORD32 ixheaacd_mac16x16in32(WORD32 a, WORD16 b, - WORD16 c) { +static PLATFORM_INLINE WORD32 ixheaacd_mac16x16in32_sat(WORD32 a, WORD16 b, + WORD16 c) { WORD32 acc; acc = ixheaacd_mult16x16in32(b, c); - acc = ixheaacd_add32(a, acc); + acc = ixheaacd_add32_sat(a, acc); return acc; } @@ -475,4 +469,4 @@ static PLATFORM_INLINE WORD32 sub32_shr(WORD32 a, WORD32 b) { return diff; } -#endif +#endif \ No newline at end of file diff --git a/decoder/ixheaacd_basic_ops40.h b/decoder/ixheaacd_basic_ops40.h index f653505..8f11089 100644 --- a/decoder/ixheaacd_basic_ops40.h +++ b/decoder/ixheaacd_basic_ops40.h @@ -345,6 +345,18 @@ static PLATFORM_INLINE WORD64 ixheaacd_add64_sat(WORD64 a, WORD64 b) { return (result); } +static PLATFORM_INLINE WORD32 ixheaacd_sat64_32(WORD64 a) { + WORD32 result; + if (a >= MAX_32) { + result = MAX_32; + } else if (a <= MIN_32) { + result = MIN_32; + } else + result = (WORD32)a; + + return (result); +} + static PLATFORM_INLINE WORD64 ixheaacd_add64(WORD64 a, WORD64 b) { WORD64 result; result = a + b; diff --git a/decoder/ixheaacd_bit_extract.h b/decoder/ixheaacd_bit_extract.h index 9ed8f7b..4ee2add 100644 --- a/decoder/ixheaacd_bit_extract.h +++ b/decoder/ixheaacd_bit_extract.h @@ -50,7 +50,7 @@ VOID ixheaacd_read_tns_u(ia_sfb_info_struct *pstr_sfb_info, ia_bit_buf_struct *it_bit_buff); WORD32 ixheaacd_core_coder_data(WORD32 id, ia_usac_data_struct *usac_data, - WORD32 elem_idx, WORD32 *chan_offset, + WORD32 elem_idx, WORD32 chan_offset, ia_bit_buf_struct *it_bit_buff, WORD32 nr_core_coder_channels); diff --git a/decoder/ixheaacd_bitbuffer.c b/decoder/ixheaacd_bitbuffer.c index 847815f..0882689 100644 --- a/decoder/ixheaacd_bitbuffer.c +++ b/decoder/ixheaacd_bitbuffer.c @@ -17,9 +17,10 @@ ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ +#include #include "ixheaacd_sbr_common.h" #include - +#include #include "ixheaacd_constants.h" #include #include @@ -31,6 +32,7 @@ #include "ixheaacd_bitbuffer.h" #include "ixheaacd_adts_crc_check.h" +#include "ixheaacd_error_codes.h" VOID ixheaacd_byte_align(ia_bit_buf_struct *it_bit_buff, WORD32 *align_bits_cnt) { @@ -44,11 +46,38 @@ VOID ixheaacd_byte_align(ia_bit_buf_struct *it_bit_buff, *align_bits_cnt = it_bit_buff->cnt_bits; } +WORD32 ixheaacd_skip_bits_buf(ia_bit_buf_struct *it_bit_buff, WORD no_of_bits) { + UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; + WORD bit_pos = it_bit_buff->bit_pos; + + if (it_bit_buff->cnt_bits < no_of_bits) + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + it_bit_buff->cnt_bits -= no_of_bits; + + ptr_read_next += no_of_bits / 8; + bit_pos -= (no_of_bits % 8); + if (bit_pos < 0) { + bit_pos += 8; + ptr_read_next++; + } + assert(bit_pos >= 0 && bit_pos <= 7); + + it_bit_buff->ptr_read_next = ptr_read_next; + it_bit_buff->bit_pos = (WORD16)bit_pos; + return no_of_bits; +} + WORD32 ixheaacd_show_bits_buf(ia_bit_buf_struct *it_bit_buff, WORD no_of_bits) { UWORD32 ret_val; UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; WORD bit_pos = it_bit_buff->bit_pos; + if (it_bit_buff->cnt_bits < no_of_bits) { + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } + ret_val = (UWORD32)*ptr_read_next; bit_pos -= no_of_bits; @@ -56,10 +85,6 @@ WORD32 ixheaacd_show_bits_buf(ia_bit_buf_struct *it_bit_buff, WORD no_of_bits) { bit_pos += 8; ptr_read_next++; - if (ptr_read_next > it_bit_buff->ptr_bit_buf_end) { - ptr_read_next = it_bit_buff->ptr_bit_buf_base; - } - ret_val <<= 8; ret_val |= (UWORD32)*ptr_read_next; @@ -79,21 +104,34 @@ WORD32 ixheaacd_read_bits_buf(ia_bit_buf_struct *it_bit_buff, WORD no_of_bits) { return 0; } + if (it_bit_buff->cnt_bits < no_of_bits) { + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } + it_bit_buff->cnt_bits -= no_of_bits; ret_val = (UWORD32)*ptr_read_next; bit_pos -= no_of_bits; - while (bit_pos < 0) { - bit_pos += 8; - ptr_read_next++; - - if (ptr_read_next > it_bit_buff->ptr_bit_buf_end) { - ptr_read_next = it_bit_buff->ptr_bit_buf_base; + if (0 == it_bit_buff->cnt_bits) { + while (bit_pos < -1) { + bit_pos += 8; + ptr_read_next++; + ret_val <<= 8; + ret_val |= (UWORD32)*ptr_read_next; } - + bit_pos += 8; ret_val <<= 8; + ptr_read_next++; + } else { + while (bit_pos < 0) { + bit_pos += 8; + ptr_read_next++; - ret_val |= (UWORD32)*ptr_read_next; + ret_val <<= 8; + + ret_val |= (UWORD32)*ptr_read_next; + } } ret_val = ret_val << ((31 - no_of_bits) - bit_pos) >> (32 - no_of_bits); @@ -118,45 +156,23 @@ UWORD32 ixheaacd_aac_read_byte(UWORD8 **ptr_read_next, WORD32 *bit_pos, return 1; } -UWORD32 ixheaacd_aac_read_2bytes(UWORD8 **ptr_read_next, WORD32 *bit_pos, - WORD32 *readword) { - UWORD8 *v = *ptr_read_next; - WORD32 bits_consumed = *bit_pos; - - if ((bits_consumed - 16) >= 0) { - *readword = (*readword << 8) | *v; - v++; - *readword = (*readword << 8) | *v; - v++; - bits_consumed -= 16; - - } else if ((bits_consumed - 8) >= 0) { - *readword = (*readword << 8) | *v; - v++; - bits_consumed -= 8; - } - - *bit_pos = bits_consumed; - *ptr_read_next = v; - return 1; -} - UWORD32 ixheaacd_aac_read_byte_corr1(UWORD8 **ptr_read_next, - WORD16 *ptr_bit_pos, WORD32 *readword) { + WORD32 *ptr_bit_pos, WORD32 *readword, + UWORD8 *p_bit_buf_end) { UWORD8 *v = *ptr_read_next; - WORD16 bits_consumed = *ptr_bit_pos; + WORD32 bits_consumed = *ptr_bit_pos; + WORD32 temp_bit_count = 0; while (bits_consumed >= 8) { - if ((bits_consumed -= 8) >= 0) { - { - *readword = (*readword << 8) | *v; - v++; - } - } else { - bits_consumed += 8; + bits_consumed -= 8; + if ((p_bit_buf_end < v) && (p_bit_buf_end != 0)) + temp_bit_count += 8; + else { + *readword = (*readword << 8) | *v; + v++; } } - *ptr_bit_pos = bits_consumed; + *ptr_bit_pos = bits_consumed + temp_bit_count; *ptr_read_next = v; return 1; } @@ -193,6 +209,11 @@ WORD32 ixheaacd_aac_read_bit(ia_bit_buf_struct *it_bit_buff) { ptr_read_next--; } + if (ptr_read_next < it_bit_buff->ptr_bit_buf_base) { + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } + it_bit_buff->cnt_bits += no_of_bits; ret_val = *ptr_read_next; bit_pos -= no_of_bits; @@ -211,6 +232,11 @@ WORD32 ixheaacd_aac_read_bit_rev(ia_bit_buf_struct *it_bit_buff) { UWORD32 temp; WORD no_of_bits = 1; + if (it_bit_buff->cnt_bits < no_of_bits) { + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } + if (bit_pos >= 8) { bit_pos -= 8; ptr_read_next++; @@ -264,7 +290,8 @@ WORD32 ixheaacd_read_bit(ia_bit_buf_struct *it_bit_buff, WORD32 no_of_bits) { return 0; } - ret_val = ixheaacd_aac_showbits_32(ptr_read_next); + ret_val = + ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->bit_count, NULL); it_bit_buff->byte_ptr += (no_of_bits >> 3); if (it_bit_buff->valid_bits != 8) { diff --git a/decoder/ixheaacd_bitbuffer.h b/decoder/ixheaacd_bitbuffer.h index d9099d1..d029971 100644 --- a/decoder/ixheaacd_bitbuffer.h +++ b/decoder/ixheaacd_bitbuffer.h @@ -20,6 +20,8 @@ #ifndef IXHEAACD_BITBUFFER_H #define IXHEAACD_BITBUFFER_H +#include + #define CRC_ADTS_HEADER_LEN 56 #define CRC_ADTS_RAW_DATA_BLK_LEN 192 #define CRC_ADTS_RAW_IIND_ICS 128 @@ -83,6 +85,7 @@ typedef struct ia_bit_buf_struct { UWORD8 *ptr_start; WORD32 write_bit_count; WORD32 max_size; + jmp_buf *xaac_jmp_buf; } ia_bit_buf_struct; @@ -103,24 +106,25 @@ ia_bit_buf_struct *ixheaacd_create_init_bit_buf(ia_bit_buf_struct *it_bit_buff, WORD32 ixheaacd_read_bits_buf(ia_bit_buf_struct *it_bit_buff, WORD no_of_bits); +WORD32 ixheaacd_skip_bits_buf(ia_bit_buf_struct *it_bit_buff, WORD no_of_bits); + WORD32 ixheaacd_show_bits_buf(ia_bit_buf_struct *it_bit_buff, WORD no_of_bits); VOID ixheaacd_read_bidirection(ia_bit_buf_struct *it_bit_buff, WORD32 ixheaacd_drc_offset); -UWORD32 ixheaacd_aac_showbits_32(UWORD8 *ptr_read_next); +UWORD32 ixheaacd_aac_showbits_32(UWORD8 *ptr_read_next, WORD32 cnt_bits, + WORD32 *increment); UWORD32 ixheaacd_aac_read_byte(UWORD8 **ptr_read_next, WORD32 *bit_pos, WORD32 *readword); -UWORD32 ixheaacd_aac_read_2bytes(UWORD8 **ptr_read_next, WORD32 *bit_pos, - WORD32 *readword); - UWORD32 ixheaacd_aac_read_byte_corr(UWORD8 **ptr_read_next, WORD32 *ptr_bit_pos, WORD32 *readword, UWORD8 *p_bit_buf_end); UWORD32 ixheaacd_aac_read_byte_corr1(UWORD8 **ptr_read_next, - WORD16 *ptr_bit_pos, WORD32 *readword); + WORD32 *ptr_bit_pos, WORD32 *readword, + UWORD8 *p_bit_buf_end); #define get_no_bits_available(it_bit_buff) ((it_bit_buff)->cnt_bits) #define ixheaacd_no_bits_read(it_bit_buff) \ diff --git a/decoder/ixheaacd_block.c b/decoder/ixheaacd_block.c index aa6f22a..d67e817 100644 --- a/decoder/ixheaacd_block.c +++ b/decoder/ixheaacd_block.c @@ -103,7 +103,7 @@ static PLATFORM_INLINE WORD32 ixheaacd_mac32x16in32_drc(WORD32 a, WORD32 b, WORD32 ixheaacd_cnt_leading_ones(WORD32 a); VOID ixheaacd_huff_sfb_table(WORD32 it_bit_buff, WORD16 *huff_index, - WORD16 *len, const UWORD16 *code_book_tbl, + WORD32 *len, const UWORD16 *code_book_tbl, const UWORD32 *idx_table) { UWORD32 temp = 0; UWORD32 temp1 = 0; @@ -169,9 +169,14 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word1( WORD len_idx = 0; UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; WORD32 bit_pos = it_bit_buff->bit_pos; - WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next); - WORD16 index, length; - ptr_read_next += 4; + WORD16 index; + WORD32 length; + WORD32 read_word; + WORD32 increment; + + read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits, + &increment); + ptr_read_next += increment; do { len_idx = offsets[1] - offsets[0]; @@ -319,8 +324,12 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word1( no_bands--; } while (no_bands >= 0); + ptr_read_next = ptr_read_next - increment; + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + it_bit_buff->ptr_bit_buf_end); + it_bit_buff->bit_pos = bit_pos; - it_bit_buff->ptr_read_next = ptr_read_next - 4; + it_bit_buff->ptr_read_next = ptr_read_next; return err_code; } @@ -335,11 +344,16 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word2_11( WORD idx; WORD32 out1, out2; WORD32 err_code = 0; - WORD16 index, length; + WORD16 index; + WORD32 length; UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; WORD32 bit_pos = it_bit_buff->bit_pos; - WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next); - ptr_read_next += 4; + WORD32 read_word; + WORD32 increment; + + read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits, + &increment); + ptr_read_next += increment; for (idx = width; idx != 0; idx -= 2) { { @@ -471,8 +485,11 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word2_11( } } } + ptr_read_next = ptr_read_next - increment; + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + it_bit_buff->ptr_bit_buf_end); - it_bit_buff->ptr_read_next = ptr_read_next - 4; + it_bit_buff->ptr_read_next = ptr_read_next; it_bit_buff->bit_pos = bit_pos; return err_code; @@ -488,8 +505,12 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_quad( WORD16 index, length; UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; WORD32 bit_pos = it_bit_buff->bit_pos; - WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next); - ptr_read_next += 4; + WORD32 read_word; + WORD32 increment; + + read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits, + &increment); + ptr_read_next += increment; spec_orig = spec_coef; do { idx_len = offsets[1] - offsets[0]; @@ -608,7 +629,10 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_quad( no_bands--; } while (no_bands >= 0); - it_bit_buff->ptr_read_next = ptr_read_next - 4; + ptr_read_next = ptr_read_next - increment; + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + it_bit_buff->ptr_bit_buf_end); + it_bit_buff->ptr_read_next = ptr_read_next; it_bit_buff->bit_pos = bit_pos; return 0; @@ -622,8 +646,12 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word2_quad( WORD16 index, length; UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; WORD32 bit_pos = it_bit_buff->bit_pos; - WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next); - ptr_read_next += 4; + WORD32 read_word; + WORD32 increment; + + read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits, + &increment); + ptr_read_next += increment; for (idx = width; idx != 0; idx -= 4) { WORD32 ampres, ampres1; @@ -763,7 +791,10 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word2_quad( it_bit_buff->ptr_bit_buf_end); } - it_bit_buff->ptr_read_next = ptr_read_next - 4; + ptr_read_next = ptr_read_next - increment; + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + it_bit_buff->ptr_bit_buf_end); + it_bit_buff->ptr_read_next = ptr_read_next; it_bit_buff->bit_pos = bit_pos; return 0; @@ -784,8 +815,12 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_pair( UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; WORD32 bit_pos = it_bit_buff->bit_pos; - WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next); - ptr_read_next += 4; + WORD32 read_word; + WORD32 increment; + + read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits, + &increment); + ptr_read_next += increment; do { len_idx = offsets[1] - offsets[0]; @@ -858,7 +893,10 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_pair( no_bands--; } while (no_bands >= 0); - it_bit_buff->ptr_read_next = ptr_read_next - 4; + ptr_read_next = ptr_read_next - increment; + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + it_bit_buff->ptr_bit_buf_end); + it_bit_buff->ptr_read_next = ptr_read_next; it_bit_buff->bit_pos = bit_pos; return 0; @@ -875,8 +913,12 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word2_pair( WORD16 index, length; UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; WORD32 bit_pos = it_bit_buff->bit_pos; - WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next); - ptr_read_next += 4; + WORD32 read_word; + WORD32 increment; + + read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits, + &increment); + ptr_read_next += increment; for (idx = width; idx != 0; idx -= 2) { { @@ -955,7 +997,10 @@ static PLATFORM_INLINE WORD ixheaacd_huffman_dec_word2_pair( it_bit_buff->ptr_bit_buf_end); } - it_bit_buff->ptr_read_next = ptr_read_next - 4; + ptr_read_next = ptr_read_next - increment; + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + it_bit_buff->ptr_bit_buf_end); + it_bit_buff->ptr_read_next = ptr_read_next; it_bit_buff->bit_pos = bit_pos; return 0; @@ -1028,6 +1073,7 @@ WORD ixheaacd_huffman_dec_word2(ia_bit_buf_struct *it_bit_buff, WORD32 cb_no, WORD ret_val = 0; WORD32 huff_mode; WORD start_bit_pos = it_bit_buff->bit_pos; + WORD32 cnt_bits = it_bit_buff->cnt_bits; WORD32 *pow_table = (WORD32 *)ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13; UWORD8 *start_read_pos = it_bit_buff->ptr_read_next; @@ -1070,14 +1116,14 @@ WORD ixheaacd_huffman_dec_word2(ia_bit_buf_struct *it_bit_buff, WORD32 cb_no, if (it_bit_buff->bit_pos <= 7) { bits_cons = ((it_bit_buff->ptr_read_next - start_read_pos) << 3) + (it_bit_buff->bit_pos - start_bit_pos); - it_bit_buff->cnt_bits -= bits_cons; + it_bit_buff->cnt_bits = cnt_bits - bits_cons; } else { it_bit_buff->ptr_read_next += (it_bit_buff->bit_pos) >> 3; it_bit_buff->bit_pos = it_bit_buff->bit_pos & 0x7; bits_cons = ((it_bit_buff->ptr_read_next - start_read_pos) << 3) + ((it_bit_buff->bit_pos - start_bit_pos)); - it_bit_buff->cnt_bits -= bits_cons; + it_bit_buff->cnt_bits = cnt_bits - bits_cons; } } return ret_val; diff --git a/decoder/ixheaacd_channel.c b/decoder/ixheaacd_channel.c index 83803de..6ebe402 100644 --- a/decoder/ixheaacd_channel.c +++ b/decoder/ixheaacd_channel.c @@ -82,15 +82,25 @@ #define SPEC(ptr, w, gl) ((ptr) + ((w) * (gl))) -#define _SWAP(a, b) \ - (b = (((WORD32)a[0] << 24) | ((WORD32)a[1] << 16) | ((WORD32)a[2] << 8) | \ - ((WORD32)a[3]))) - -UWORD32 ixheaacd_aac_showbits_32(UWORD8 *ptr_read_next) { +UWORD32 ixheaacd_aac_showbits_32(UWORD8 *ptr_read_next, WORD32 cnt_bits, + WORD32 *increment) { UWORD8 *v = ptr_read_next; UWORD32 b = 0; + WORD32 i; + WORD32 bumped = 0; - _SWAP(v, b); + for (i = 0; i < 4; i++) { + b = b << 8; + if (cnt_bits > 0) { + b = b | *v; + v++; + bumped++; + } + cnt_bits -= 8; + } + if (increment != NULL) { + *increment = bumped; + } return b; } @@ -263,6 +273,7 @@ static WORD16 ixheaacd_read_block_data( if (ptr_aac_dec_channel_info->str_tns_info.tns_data_present) error_code = ixheaacd_read_tns_data(it_bit_buff, ptr_aac_dec_channel_info); + if (error_code) return error_code; } if (aac_spect_data_resil_flag && @@ -271,8 +282,9 @@ static WORD16 ixheaacd_read_block_data( if (aac_sf_data_resil_flag && ((object_type == AOT_ER_AAC_ELD) || (object_type == AOT_ER_AAC_LD))) { - ixheaacd_rvlc_dec(ptr_aac_dec_channel_info, ptr_aac_dec_static_channel_info, - it_bit_buff); + error_code = ixheaacd_rvlc_dec( + ptr_aac_dec_channel_info, ptr_aac_dec_static_channel_info, it_bit_buff); + if (error_code) return error_code; it_bit_buff->bit_pos = 7 - it_bit_buff->bit_pos; } @@ -281,11 +293,12 @@ static WORD16 ixheaacd_read_block_data( if (ptr_aac_dec_channel_info->str_tns_info.tns_data_present) error_code = ixheaacd_read_tns_data(it_bit_buff, ptr_aac_dec_channel_info); + if (error_code) return error_code; } { it_bit_buff->bit_pos = 7 - it_bit_buff->bit_pos; } - error_code |= ixheaacd_read_spectral_data( + error_code = ixheaacd_read_spectral_data( it_bit_buff, ptr_aac_dec_channel_info, ptr_aac_tables, total_channels, frame_size, object_type, aac_spect_data_resil_flag, aac_sf_data_resil_flag); @@ -575,7 +588,8 @@ VOID ixheaacd_channel_pair_process( void *self_ptr) { WORD32 channel; ia_aac_decoder_struct *self = self_ptr; - if (aac_spect_data_resil_flag) { + if (aac_spect_data_resil_flag && + ((object_type == AOT_ER_AAC_LD) || (object_type == AOT_ER_AAC_ELD))) { for (channel = 0; channel < num_ch; channel++) { ixheaacd_cblock_inv_quant_spect_data(ptr_aac_dec_channel_info[channel], ptr_aac_tables); @@ -784,10 +798,6 @@ WORD16 ixheaacd_read_spectral_data( ptr_aac_tables->pstr_block_tables->ixheaacd_pow_table_Q13, ptr_scratch); } - - else { - memset(ptr_spec_coef_out, 0, sizeof(WORD32) * sfb_width); - } } ptr_scratch += sfb_width; ptr_spec_coef_out += sfb_width; @@ -798,7 +808,7 @@ WORD16 ixheaacd_read_spectral_data( else index = frame_size - swb_offset[max_sfb]; - memset(ptr_spec_coef_out, 0, sizeof(WORD32) * index); + if (index < 0) return -1; } else { memset(ptr_spec_coef, 0, sizeof(WORD32) * 1024); @@ -878,6 +888,12 @@ WORD16 ixheaacd_read_spectral_data( ixheaacd_huff_mute_erroneous_lines(pstr_hcr_info); } + if (it_bit_buff->cnt_bits < + ptr_aac_dec_channel_info->reorder_spect_data_len) { + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } + it_bit_buff->cnt_bits += -ptr_aac_dec_channel_info->reorder_spect_data_len; it_bit_buff->ptr_read_next = @@ -1146,6 +1162,26 @@ WORD32 ixheaacd_ltp_data(WORD32 object_type, ia_ics_info_struct *ics, ltp->long_used[sfb] = ixheaacd_read_bits_buf(bs, 1); } } - + if (ics->frame_length == 480) { + if ((ics->sampling_rate_index > 5) && + (ltp->last_band > MAX_LTP_SFB_SR_FIVE_PLUS_480)) + ltp->last_band = MAX_LTP_SFB_SR_FIVE_PLUS_480; + else if ((ics->sampling_rate_index == 5) && + (ltp->last_band > MAX_LTP_SFB_SR_FIVE_480)) + ltp->last_band = MAX_LTP_SFB_SR_FIVE_480; + else if ((ics->sampling_rate_index < 5) && + (ltp->last_band > MAX_LTP_SFB_SR_FIVE_LESS_480)) + ltp->last_band = MAX_LTP_SFB_SR_FIVE_LESS_480; + } else if (ics->frame_length == 512) { + if ((ics->sampling_rate_index > 5) && + (ltp->last_band > MAX_LTP_SFB_SR_FIVE_PLUS_512)) + ltp->last_band = MAX_LTP_SFB_SR_FIVE_PLUS_512; + else if ((ics->sampling_rate_index == 5) && + (ltp->last_band > MAX_LTP_SFB_SR_FIVE_512)) + ltp->last_band = MAX_LTP_SFB_SR_FIVE_512; + else if ((ics->sampling_rate_index < 5) && + (ltp->last_band > MAX_LTP_SFB_SR_FIVE_LESS_512)) + ltp->last_band = MAX_LTP_SFB_SR_FIVE_LESS_512; + } return 0; } diff --git a/decoder/ixheaacd_common_lpfuncs.c b/decoder/ixheaacd_common_lpfuncs.c index ff43237..a9df44e 100644 --- a/decoder/ixheaacd_common_lpfuncs.c +++ b/decoder/ixheaacd_common_lpfuncs.c @@ -85,9 +85,13 @@ ixheaacd_aac_showbits_7(ia_bit_buf_struct *it_bit_buff) { UWORD8 *v = it_bit_buff->ptr_read_next; UWORD32 b = 0; UWORD32 x; - b = (((WORD32)v[0] << 8) | (WORD32)(v[1])); + b = ((WORD32)v[0] << 8); + if (it_bit_buff->bit_pos < 6) { + b |= (WORD32)(v[1]); + } x = (UWORD32)b << (15 + 8 - it_bit_buff->bit_pos); x = (UWORD32)x >> (25); + return x; } @@ -162,7 +166,7 @@ WORD ixheaacd_get_channel_mask( VOID ixheaacd_read_data_stream_element(ia_bit_buf_struct *it_bit_buff, WORD32 *byte_align_bits, ia_drc_dec_struct *drc_handle) { - ia_bit_buf_struct temp_bs; + ia_bit_buf_struct temp_bs = {0}; WORD32 count = ixheaacd_read_bits_buf(it_bit_buff, 13); WORD32 cnt = (count & 0xff); WORD32 start_pos = 0; @@ -207,12 +211,13 @@ VOID ixheaacd_read_data_stream_element(ia_bit_buf_struct *it_bit_buff, } } + if (it_bit_buff->cnt_bits < (cnt << 3)) { + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } it_bit_buff->ptr_read_next += cnt; it_bit_buff->cnt_bits -= ((cnt) << 3); - if (it_bit_buff->ptr_read_next > it_bit_buff->ptr_bit_buf_end) { - it_bit_buff->ptr_read_next = it_bit_buff->ptr_bit_buf_base; - } } VOID ixheaacd_read_fill_element(ia_bit_buf_struct *it_bit_buff, @@ -239,12 +244,13 @@ VOID ixheaacd_read_fill_element(ia_bit_buf_struct *it_bit_buff, } else { ixheaacd_read_bits_buf(it_bit_buff, 4); + if (it_bit_buff->cnt_bits < ((count - 1) << 3)) { + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } it_bit_buff->ptr_read_next += count - 1; it_bit_buff->cnt_bits -= ((count - 1) << 3); - if (it_bit_buff->ptr_read_next > it_bit_buff->ptr_bit_buf_end) { - it_bit_buff->ptr_read_next = it_bit_buff->ptr_bit_buf_base; - } } } } @@ -312,10 +318,7 @@ WORD32 ixheaacd_get_element_index_tag( it_bit_buff, &p_obj_enhaacplus_dec->aac_config.ui_pce_found_in_hdr, &p_obj_enhaacplus_dec->aac_config.str_prog_config); if (error_code != 0) { - if (it_bit_buff->cnt_bits < 0) { - return (WORD16)( - (WORD32)IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); - } + if (error_code < 0) return error_code; return IA_ENHAACPLUS_DEC_EXE_NONFATAL_DECODE_FRAME_ERROR; } } diff --git a/decoder/ixheaacd_config.h b/decoder/ixheaacd_config.h index 7029fd2..c6a540e 100644 --- a/decoder/ixheaacd_config.h +++ b/decoder/ixheaacd_config.h @@ -40,6 +40,8 @@ #define USAC_OUT_FRAMELENGTH_2048 2048 #define USAC_OUT_FRAMELENGTH_4096 4096 +#define MAX_CORE_SBR_FRAME_LEN_IDX (4) + #define ID_EXT_ELE_FILL 0 #define ID_EXT_ELE_MPEGS 1 #define ID_EXT_ELE_SAOC 2 diff --git a/decoder/ixheaacd_create.c b/decoder/ixheaacd_create.c index 9f72de1..962b98c 100644 --- a/decoder/ixheaacd_create.c +++ b/decoder/ixheaacd_create.c @@ -39,7 +39,20 @@ #include "ixheaacd_drc_data_struct.h" #include "ixheaacd_drc_dec.h" +#include "ixheaacd_sbr_scale.h" +#include "ixheaacd_env_extr_part.h" +#include "ixheaacd_sbr_rom.h" +#include "ixheaacd_hybrid.h" +#include "ixheaacd_ps_dec.h" +#include "ixheaacd_common_rom.h" +#include "ixheaacd_qmf_dec.h" +#include "ixheaacd_sbr_const.h" +#include "ixheaacd_lpp_tran.h" #include "ixheaacd_sbrdecoder.h" +#include "ixheaacd_env_extr.h" +#include "ixheaacd_env_calc.h" +#include "ixheaacd_pvc_dec.h" +#include "ixheaacd_sbr_dec.h" #include "ixheaacd_mps_polyphase.h" #include "ixheaacd_sbr_const.h" @@ -50,7 +63,6 @@ #include #include "ixheaacd_memory_standards.h" #include "ixheaacd_sbrdecsettings.h" -#include "ixheaacd_env_extr_part.h" #include "ixheaacd_defines.h" #include #include "ixheaacd_common_rom.h" @@ -302,21 +314,26 @@ WORD32 ixheaacd_decode_init( case ID_USAC_SCE: case ID_USAC_LFE: + if ((chan + 1) > MAX_NUM_CHANNELS_USAC_LVL2) return -1; usac_data->seed_value[chan] = 0x3039; + chan++; break; case ID_USAC_CPE: { - WORD32 frame_len_tbl[] = {-1, -1, 32, 32, 64}; + static const WORD32 frame_len_tbl[MAX_CORE_SBR_FRAME_LEN_IDX + 1] = { + -1, -1, 32, 32, 64}; + if ((chan + 2) > MAX_NUM_CHANNELS_USAC_LVL2) return -1; usac_data->seed_value[chan] = 0x3039; chan++; usac_data->seed_value[chan] = 0x10932; + chan++; if (stereo_config_index > 0) { WORD32 bs_frame_length = - frame_len_tbl[ptr_usac_config->core_sbr_framelength_index] - 1; + frame_len_tbl[ptr_usac_config->core_sbr_framelength_index]; WORD32 bs_residual_coding = (stereo_config_index > 1) ? 1 : 0; ia_usac_dec_mps_config_struct *ptr_usac_mps212_config = @@ -523,7 +540,6 @@ WORD32 ixheaacd_decode_create(ia_exhaacplus_dec_api_struct *handle, WORD32 tracks_for_decoder) { WORD32 stream; - WORD32 num_delay_samp = 0; WORD32 err = 0; ia_frame_data_struct *pstr_frame_data; WORD32 stream_count; @@ -541,6 +557,8 @@ WORD32 ixheaacd_decode_create(ia_exhaacplus_dec_api_struct *handle, err = ixheaacd_dec_data_init(handle, pstr_frame_data, &(pstr_dec_data->str_usac_data)); + if (err != 0) return err; + switch (pstr_dec_data->str_usac_data.sbr_ratio_idx) { case 0: handle->aac_config.ui_sbr_mode = 0; @@ -559,7 +577,6 @@ WORD32 ixheaacd_decode_create(ia_exhaacplus_dec_api_struct *handle, handle->aac_config.ui_sbr_mode = 0; } - if (err != 0) return err; break; @@ -677,9 +694,12 @@ WORD32 ixheaacd_decode_create(ia_exhaacplus_dec_api_struct *handle, if (pstr_dec_data->str_usac_data.pstr_esbr_dec == NULL) { return -1; + } else { + pstr_dec_data->str_usac_data.pstr_esbr_dec->xaac_jmp_buf = + &(aac_dec_handle->xaac_jmp_buf); } } } - - return (num_delay_samp); + aac_dec_handle->decode_create_done = 1; + return 0; } diff --git a/decoder/ixheaacd_decode_main.c b/decoder/ixheaacd_decode_main.c index 21e6bca..8bb71da 100644 --- a/decoder/ixheaacd_decode_main.c +++ b/decoder/ixheaacd_decode_main.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include "ixheaacd_error_standards.h" #include "ixheaacd_memory_standards.h" #include "ixheaacd_sbrdecsettings.h" #include "ixheaacd_env_extr_part.h" @@ -263,12 +263,14 @@ WORD32 ixheaacd_dec_main(VOID *temp_handle, WORD8 *inbuffer, WORD8 *outbuffer, if (frames_done == 0) { WORD32 delay; - delay = ixheaacd_decode_create( - handle, pstr_dec_data, - pstr_dec_data->str_frame_data.scal_out_select + 1); + if (aac_dec_handle->decode_create_done == 0) { + delay = ixheaacd_decode_create( + handle, pstr_dec_data, + pstr_dec_data->str_frame_data.scal_out_select + 1); + if (delay == -1) return -1; + } pstr_dec_data->dec_bit_buf.max_size = handle->p_mem_info_aac[IA_MEMTYPE_INPUT].ui_size; - if (delay == -1) return -1; *num_channel_out = pstr_dec_data->str_frame_data.scal_out_num_channels; return 0; } @@ -280,6 +282,7 @@ WORD32 ixheaacd_dec_main(VOID *temp_handle, WORD8 *inbuffer, WORD8 *outbuffer, pstr_dec_data->dec_bit_buf.ptr_read_next = (UWORD8 *)inbuffer; pstr_dec_data->dec_bit_buf.bit_pos = 7; pstr_dec_data->dec_bit_buf.cnt_bits = pstr_dec_data->dec_bit_buf.size; + pstr_dec_data->dec_bit_buf.xaac_jmp_buf = &(aac_dec_handle->xaac_jmp_buf); pstr_dec_data->str_usac_data.usac_flag = aac_dec_handle->usac_flag; if (pstr_dec_data->dec_bit_buf.size > pstr_dec_data->dec_bit_buf.max_size) @@ -298,15 +301,15 @@ WORD32 ixheaacd_dec_main(VOID *temp_handle, WORD8 *inbuffer, WORD8 *outbuffer, if (config_len != 0) { /* updating the config parameters*/ - ia_bit_buf_struct *config_bit_buf = - (ia_bit_buf_struct *)malloc(sizeof(ia_bit_buf_struct)); + ia_bit_buf_struct config_bit_buf = {0}; - config_bit_buf->ptr_bit_buf_base = config; - config_bit_buf->size = config_len << 3; - config_bit_buf->ptr_read_next = config_bit_buf->ptr_bit_buf_base; - config_bit_buf->ptr_bit_buf_end = (UWORD8 *)config + config_len; - config_bit_buf->bit_pos = 7; - config_bit_buf->cnt_bits = config_bit_buf->size; + config_bit_buf.ptr_bit_buf_base = config; + config_bit_buf.size = config_len << 3; + config_bit_buf.ptr_read_next = config_bit_buf.ptr_bit_buf_base; + config_bit_buf.ptr_bit_buf_end = (UWORD8 *)config + config_len; + config_bit_buf.bit_pos = 7; + config_bit_buf.cnt_bits = config_bit_buf.size; + config_bit_buf.xaac_jmp_buf = &(aac_dec_handle->xaac_jmp_buf); suitable_tracks = ixheaacd_frm_data_init(pstr_audio_specific_config, pstr_dec_data); @@ -314,14 +317,18 @@ WORD32 ixheaacd_dec_main(VOID *temp_handle, WORD8 *inbuffer, WORD8 *outbuffer, if (suitable_tracks <= 0) return -1; /* call codec re-configure*/ + aac_dec_handle->decode_create_done = 0; err = ixheaacd_config( - config_bit_buf, &(pstr_dec_data->str_frame_data - .str_audio_specific_config.str_usac_config), + &config_bit_buf, &(pstr_dec_data->str_frame_data + .str_audio_specific_config.str_usac_config), &(pstr_audio_specific_config ->channel_configuration) /*&pstr_audio_specific_config->str_usac_config*/); - free(config_bit_buf); if (err != 0) return -1; + pstr_dec_data->str_frame_data.str_audio_specific_config + .sampling_frequency = + pstr_dec_data->str_frame_data.str_audio_specific_config + .str_usac_config.usac_sampling_frequency; delay = ixheaacd_decode_create( handle, pstr_dec_data, pstr_dec_data->str_frame_data.scal_out_select + 1); @@ -336,6 +343,7 @@ WORD32 ixheaacd_dec_main(VOID *temp_handle, WORD8 *inbuffer, WORD8 *outbuffer, pstr_dec_data->dec_bit_buf.ptr_read_next = (UWORD8 *)inbuffer; pstr_dec_data->dec_bit_buf.bit_pos = 7; pstr_dec_data->dec_bit_buf.cnt_bits = pstr_dec_data->dec_bit_buf.size; + pstr_dec_data->dec_bit_buf.xaac_jmp_buf = &(aac_dec_handle->xaac_jmp_buf); pstr_dec_data->str_usac_data.usac_flag = aac_dec_handle->usac_flag; @@ -351,6 +359,7 @@ WORD32 ixheaacd_dec_main(VOID *temp_handle, WORD8 *inbuffer, WORD8 *outbuffer, } // temp_read=ixheaacd_show_bits_buf(pstr_dec_data->dec_bit_buf,preroll_frame_offset[access_unit]); + if (!aac_dec_handle->decode_create_done) return IA_FATAL_ERROR; err = ixheaacd_usac_process(pstr_dec_data, num_channel_out, aac_dec_handle); diff --git a/decoder/ixheaacd_defines.h b/decoder/ixheaacd_defines.h index 3ff42dd..ed85be2 100644 --- a/decoder/ixheaacd_defines.h +++ b/decoder/ixheaacd_defines.h @@ -28,6 +28,7 @@ #define MAX_BINS_LONG 1024 #define MAX_BINS_SHORT 128 #define MAX_SCALE_FACTOR_BANDS_SHORT 16 +#define MAX_SCALE_FACTOR_BANDS_LONG (52) #define ZERO_HCB 0 @@ -59,4 +60,6 @@ typedef struct { WORD32 sampling_frequency; } ia_sampling_rate_info_struct; +#define USAC_MAX_SAMPLE_RATE (96000) + #endif diff --git a/decoder/ixheaacd_drc_data_struct.h b/decoder/ixheaacd_drc_data_struct.h index 9e1980b..faf9775 100644 --- a/decoder/ixheaacd_drc_data_struct.h +++ b/decoder/ixheaacd_drc_data_struct.h @@ -76,7 +76,6 @@ typedef struct { UWORD8 max_audio_channels; UWORD8 length_history; UWORD8 num_drc_elements; - WORD32 is_longblock[MAX_BS_ELEMENT]; WORD32 state; WORD32 target_ref_level; WORD32 prog_ref_level; diff --git a/decoder/ixheaacd_drc_freq_dec.c b/decoder/ixheaacd_drc_freq_dec.c index 9adef97..48a83e3 100644 --- a/decoder/ixheaacd_drc_freq_dec.c +++ b/decoder/ixheaacd_drc_freq_dec.c @@ -672,11 +672,15 @@ static int ixheaacd_drc_read_compression(ia_handle_bit_buf_struct bs, int bit_count = 0; int dmx_lvl_present, ext_present, compression_present; int coarse_gain_present, fine_grain_present; - ia_bit_buf_struct local_bs; + ia_bit_buf_struct local_bs = {0}; WORD32 bytes = 0, bits = 0; memcpy(&local_bs, bs, sizeof(ia_bit_buf_struct)); + if (local_bs.size < bs_pos) { + longjmp(*(local_bs.xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } bytes = (local_bs.size - bs_pos) >> 3; bits = (local_bs.size - bs_pos) % 8; diff --git a/decoder/ixheaacd_env_calc.c b/decoder/ixheaacd_env_calc.c index 2cedba7..8d31290 100644 --- a/decoder/ixheaacd_env_calc.c +++ b/decoder/ixheaacd_env_calc.c @@ -1277,7 +1277,7 @@ VOID ixheaacd_enery_calc_persfb(WORD32 **anal_buf_real, WORD32 **anal_buf_imag, WORD16 temp; temp = ixheaacd_extract16l(ixheaacd_shr32_dir(*ptr, pre_shift1)); ptr += 64; - accu_line = ixheaacd_mac16x16in32(accu_line, temp, temp); + accu_line = ixheaacd_mac16x16in32_sat(accu_line, temp, temp); } } accumulate = @@ -1518,7 +1518,7 @@ VOID ixheaacd_harm_idx_zerotwolp_dec(WORD32 *ptr_real_buf, WORD16 *ptr_gain_buf, sine_level = (ptr_sine_level_buf[2 * k] << 16); if (sine_level == 0) { - *ptr_real_buf++ = ixheaacd_mac16x16in32_shl( + *ptr_real_buf++ = ixheaacd_mac16x16in32_shl_sat( signal_real, ixheaacd_extract16h(ptr_rand_ph[k]), noise_level_mant[2 * k]); } else if (harm_index == 0) @@ -1579,7 +1579,7 @@ VOID ixheaacd_harm_idx_onethreelp( tone_count++; } else { if (!noise_absc_flag) { - signal_real = ixheaacd_mac16x16in32_shl( + signal_real = ixheaacd_mac16x16in32_shl_sat( signal_real, ixheaacd_extract16h(ptr_rand_ph[k]), *noise_level_mant); } } @@ -1625,7 +1625,7 @@ VOID ixheaacd_harm_idx_onethreelp( sine_level_next = (ptr_sine_level_buf[2 * (k + 1)]); if ((!noise_absc_flag) && (sine_level == 0)) { - signal_real = ixheaacd_mac16x16in32_shl( + signal_real = ixheaacd_mac16x16in32_shl_sat( signal_real, ixheaacd_extract16h(ptr_rand_ph[k]), *noise_level_mant); } noise_level_mant += 2; @@ -1660,7 +1660,7 @@ VOID ixheaacd_harm_idx_onethreelp( tone_count++; } else { if (!noise_absc_flag) { - signal_real = ixheaacd_mac16x16in32_shl( + signal_real = ixheaacd_mac16x16in32_shl_sat( signal_real, ixheaacd_extract16h(ptr_rand_ph[k]), *noise_level_mant); } @@ -1738,9 +1738,9 @@ VOID ixheaacd_harm_idx_zerotwo(FLAG noise_absc_flag, WORD16 num_sub_bands, WORD32 random = *ptr_rand_ph; WORD16 noise = smoothed_noise[0]; - *ptr_real_buf = ixheaacd_mac16x16in32_shl( + *ptr_real_buf = ixheaacd_mac16x16in32_shl_sat( signal_real, ixheaacd_extract16h(random), noise); - *ptr_imag = ixheaacd_mac16x16in32_shl( + *ptr_imag = ixheaacd_mac16x16in32_shl_sat( sig_imag, ixheaacd_extract16l(random), noise); } else { *ptr_real_buf = signal_real; @@ -1811,9 +1811,9 @@ VOID ixheaacd_harm_idx_onethree(FLAG noise_absc_flag, WORD16 num_sub_bands, WORD32 random = *ptr_rand_ph; WORD16 noise = smoothed_noise[0]; - *ptr_real_buf = ixheaacd_mac16x16in32_shl( + *ptr_real_buf = ixheaacd_mac16x16in32_shl_sat( signal_real, ixheaacd_extract16h(random), noise); - *ptr_imag = ixheaacd_mac16x16in32_shl( + *ptr_imag = ixheaacd_mac16x16in32_shl_sat( sig_imag, ixheaacd_extract16l(random), noise); } else { *ptr_real_buf = signal_real; @@ -1828,4 +1828,4 @@ VOID ixheaacd_harm_idx_onethree(FLAG noise_absc_flag, WORD16 num_sub_bands, ptr_real_buf++; ptr_imag++; } -} +} \ No newline at end of file diff --git a/decoder/ixheaacd_env_dec.c b/decoder/ixheaacd_env_dec.c index 7f10188..e363def 100644 --- a/decoder/ixheaacd_env_dec.c +++ b/decoder/ixheaacd_env_dec.c @@ -20,6 +20,7 @@ #include #include "ixheaacd_sbr_common.h" #include +#include "ixheaacd_error_standards.h" #include "ixheaacd_constants.h" #include @@ -377,9 +378,10 @@ VOID ixheaacd_add_arr(WORD16 *ptr1, WORD16 *ptr2, WORD32 num) { } } -VOID ixheaacd_calc_noise_floor(ia_sbr_header_data_struct *ptr_header_data, - ia_sbr_frame_info_data_struct *ptr_sbr_data, - ia_sbr_prev_frame_data_struct *ptr_prev_data) { +IA_ERRORCODE ixheaacd_calc_noise_floor( + ia_sbr_header_data_struct *ptr_header_data, + ia_sbr_frame_info_data_struct *ptr_sbr_data, + ia_sbr_prev_frame_data_struct *ptr_prev_data) { WORD32 i; WORD32 num_nf_bands; WORD32 num_noise_env; @@ -424,6 +426,8 @@ VOID ixheaacd_calc_noise_floor(ia_sbr_header_data_struct *ptr_header_data, ixheaacd_limit_noise_floor_fac(ptr_header_data, ptr_sbr_data); ixheaacd_drc_offset = num_nf_bands * (num_noise_env - 1); + if (ixheaacd_drc_offset < 0 || ixheaacd_drc_offset >= MAX_NUM_NOISE_VALUES) + return IA_FATAL_ERROR; ptr1 = &ptr_sbr_data->int_noise_floor[ixheaacd_drc_offset]; ptr2 = ptr_prev_noise_floor; @@ -443,13 +447,16 @@ VOID ixheaacd_calc_noise_floor(ia_sbr_header_data_struct *ptr_header_data, *ptr_noise_floor++ = (WORD16)(0x4000 + (noise_floor_exp & MASK_FOR_EXP)); } } + return IA_NO_ERROR; } -VOID ixheaacd_dec_sbrdata_for_pvc( +IA_ERRORCODE ixheaacd_dec_sbrdata_for_pvc( ia_sbr_header_data_struct *ptr_header_data, ia_sbr_frame_info_data_struct *ptr_sbr_data, ia_sbr_prev_frame_data_struct *ptr_prev_data) { - ixheaacd_calc_noise_floor(ptr_header_data, ptr_sbr_data, ptr_prev_data); + WORD32 err = 0; + err = ixheaacd_calc_noise_floor(ptr_header_data, ptr_sbr_data, ptr_prev_data); + if (err) return err; if (!ptr_sbr_data->coupling_mode) { ptr_sbr_data->num_noise_sfac = @@ -458,6 +465,7 @@ VOID ixheaacd_dec_sbrdata_for_pvc( ixheaacd_dequant_pvc_env_data(ptr_sbr_data->num_noise_sfac, ptr_sbr_data->flt_noise_floor); } + return IA_NO_ERROR; } VOID ixheaacd_sbr_env_dequant_coup_fix( @@ -589,8 +597,10 @@ WORD32 ixheaacd_dec_sbrdata(ia_sbr_header_data_struct *ptr_header_data_ch_0, if (err) return err; - ixheaacd_calc_noise_floor(ptr_header_data_ch_0, ptr_sbr_data_ch_0, - ptr_prev_data_ch_0); + err = ixheaacd_calc_noise_floor(ptr_header_data_ch_0, ptr_sbr_data_ch_0, + ptr_prev_data_ch_0); + + if (err == (WORD32)IA_FATAL_ERROR) return (WORD32)IA_FATAL_ERROR; if (!ptr_sbr_data_ch_0->coupling_mode && usac_flag) { ptr_sbr_data_ch_0->num_noise_sfac = @@ -611,8 +621,10 @@ WORD32 ixheaacd_dec_sbrdata(ia_sbr_header_data_struct *ptr_header_data_ch_0, if (err) return err; - ixheaacd_calc_noise_floor(ptr_header_data_ch_1, ptr_sbr_data_ch_1, - ptr_prev_data_ch_1); + err = ixheaacd_calc_noise_floor(ptr_header_data_ch_1, ptr_sbr_data_ch_1, + ptr_prev_data_ch_1); + + if (err) return err; if (!ptr_sbr_data_ch_1->coupling_mode && usac_flag) { ptr_sbr_data_ch_1->num_noise_sfac = @@ -656,6 +668,7 @@ WORD32 ixheaacd_dec_envelope(ia_sbr_header_data_struct *ptr_header_data, WORD32 usac_flag = ptr_header_data->usac_flag; WORD32 temp_1 = ptr_prev_data_ch_0->end_position - ptr_header_data->num_time_slots; + if (temp_1 < 0) return -1; temp_1 = ptr_sbr_data->str_frame_info_details.border_vec[0] - temp_1; if ((!ptr_header_data->err_flag_prev) && (!ptr_header_data->err_flag) && diff --git a/decoder/ixheaacd_env_dec.h b/decoder/ixheaacd_env_dec.h index 3c36486..b0eaa7e 100644 --- a/decoder/ixheaacd_env_dec.h +++ b/decoder/ixheaacd_env_dec.h @@ -28,9 +28,10 @@ WORD32 ixheaacd_dec_sbrdata(ia_sbr_header_data_struct *ptr_header_data_ch_0, ia_sbr_prev_frame_data_struct *ptr_prev_data_ch_1, ixheaacd_misc_tables *ptr_common_tables); -VOID ixheaacd_dec_sbrdata_for_pvc(ia_sbr_header_data_struct *ptr_header_data, - ia_sbr_frame_info_data_struct *ptr_sbr_data, - ia_sbr_prev_frame_data_struct *ptr_prev_data); +IA_ERRORCODE ixheaacd_dec_sbrdata_for_pvc( + ia_sbr_header_data_struct *ptr_header_data, + ia_sbr_frame_info_data_struct *ptr_sbr_data, + ia_sbr_prev_frame_data_struct *ptr_prev_data); VOID ixheaacd_harm_idx_onethreelp(WORD32 *ptr_real_buf, WORD16 *ptr_gain_buf, WORD scale_change, WORD16 *ptr_sine_level_buf, diff --git a/decoder/ixheaacd_env_extr.c b/decoder/ixheaacd_env_extr.c index 4224d9f..728d8a1 100644 --- a/decoder/ixheaacd_env_extr.c +++ b/decoder/ixheaacd_env_extr.c @@ -1138,9 +1138,15 @@ VOID ixheaacd_read_env_data(ia_sbr_frame_info_data_struct *ptr_frame_data, } for (i = (1 - dtdf_dir_flag); i < no_band[j]; i++) { - readword = ixheaacd_show_bits_buf(it_bit_buff, 20); - ixheaacd_huffman_decode(readword << 12, &index, &length, - (const UWORD16 *)h, (const UWORD32 *)idx_tab); + if (it_bit_buff->cnt_bits < 20) { + readword = ixheaacd_show_bits_buf(it_bit_buff, it_bit_buff->cnt_bits); + readword = readword << (32 - it_bit_buff->cnt_bits); + } else { + readword = ixheaacd_show_bits_buf(it_bit_buff, 20); + readword = readword << 12; + } + ixheaacd_huffman_decode(readword, &index, &length, (const UWORD16 *)h, + (const UWORD32 *)idx_tab); delta = index - lav; ixheaacd_read_bits_buf(it_bit_buff, length); p_sbr_sf[ixheaacd_drc_offset + i] = @@ -1328,7 +1334,7 @@ int ixheaacd_extract_frame_info_ld( WORD16 time_border[MAX_ENVELOPES + 1]; WORD16 time_border_noise[2 + 1]; WORD16 f[MAX_ENVELOPES + 1]; - int rel_bord_lead[7] ={0}; + int rel_bord_lead[7] = {0}; ia_frame_info_struct *v_frame_info = &h_frame_data->str_frame_info_details; @@ -1354,6 +1360,9 @@ int ixheaacd_extract_frame_info_ld( bs_transient_position = ixheaacd_read_bits_buf(it_bit_buff, SBR_TRAN_BITS); v_frame_info->frame_class = 0; + if ((numTimeSlots != 16) && (bs_transient_position >= LD_ENV_TBL_480)) { + return -1; + } bs_num_env = (numTimeSlots == 16) ? ixheaacd_ld_env_table_512[bs_transient_position] [SBR_ENVT_NUMENV] diff --git a/decoder/ixheaacd_error_standards.h b/decoder/ixheaacd_error_standards.h index 736a659..7f029ca 100644 --- a/decoder/ixheaacd_error_standards.h +++ b/decoder/ixheaacd_error_standards.h @@ -20,8 +20,6 @@ #ifndef IXHEAACD_ERROR_STANDARDS_H #define IXHEAACD_ERROR_STANDARDS_H -typedef WORD32 IA_ERRORCODE; - #define IA_NO_ERROR 0x00000000 #define IA_FATAL_ERROR 0x80000000 diff --git a/decoder/ixheaacd_esbr_envcal.c b/decoder/ixheaacd_esbr_envcal.c index e1bb1c7..a3382c3 100644 --- a/decoder/ixheaacd_esbr_envcal.c +++ b/decoder/ixheaacd_esbr_envcal.c @@ -22,7 +22,7 @@ #include #include - +#include "ixheaacd_error_standards.h" #include "ixheaacd_sbr_const.h" #include "ixheaacd_sbrdecsettings.h" #include "ixheaacd_bitbuffer.h" @@ -569,6 +569,8 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, } for (i = 0; i < bs_num_env; i++) { + if (kk > MAX_NOISE_ENVELOPES) return IA_FATAL_ERROR; + if (p_frame_info->border_vec[i] == p_frame_info->noise_border_vec[kk]) kk++, next++; diff --git a/decoder/ixheaacd_esbr_rom.h b/decoder/ixheaacd_esbr_rom.h index 57edc24..253f8c3 100644 --- a/decoder/ixheaacd_esbr_rom.h +++ b/decoder/ixheaacd_esbr_rom.h @@ -57,5 +57,5 @@ extern const FLOAT32 ixheaacd_analy_cos_sin_table_kl_16[16 * 16 * 2]; extern const FLOAT32 ixheaacd_analy_cos_sin_table_kl_24[24 * 24 * 2]; extern const FLOAT32 ixheaacd_analy_cos_sin_table_kl_32[32 * 32 * 2]; extern const FLOAT32 ixheaacd_analy_cos_sin_table_kl_40[40 * 80 * 2]; -extern const FLOAT32 ixheaacd_sel_case[4][8]; +extern const FLOAT32 ixheaacd_sel_case[5][8]; #endif diff --git a/decoder/ixheaacd_ext_ch_ele.c b/decoder/ixheaacd_ext_ch_ele.c index 8bc17e7..01506e7 100644 --- a/decoder/ixheaacd_ext_ch_ele.c +++ b/decoder/ixheaacd_ext_ch_ele.c @@ -353,38 +353,42 @@ static VOID ixheaacd_filter_and_add(const WORD32 *in, const WORD32 length, sum = ixheaacd_mac32x32in64(sum, in[1], filter[1]); sum = ixheaacd_mac32x32in64(sum, in[0], filter[2]); sum = ixheaacd_mac32x32in64_n(sum, &in[0], &filter[3], 4); - *out += (WORD32)((sum * factor_even) >> 15); + *out = ixheaacd_add32_sat( + *out, ixheaacd_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); out++; sum = ixheaacd_mult32x32in64(in[1], filter[0]); sum = ixheaacd_mac32x32in64(sum, in[0], filter[1]); sum = ixheaacd_mac32x32in64_n(sum, &in[0], &filter[2], 5); - *out += (WORD32)((sum * factor_odd) >> 15); + *out = ixheaacd_add32_sat( + *out, ixheaacd_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); out++; sum = ixheaacd_mult32x32in64(in[0], filter[0]); sum = ixheaacd_mac32x32in64_n(sum, &in[0], &filter[1], 6); - - *out = ixheaacd_add32_sat(*out, (WORD32)((sum * factor_even) >> 15)); - + *out = ixheaacd_add32_sat( + *out, ixheaacd_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); out++; for (i = 3; i < length - 4; i += 2) { sum = 0; sum = ixheaacd_mac32x32in64_7(sum, &in[i - 3], filter); - *out = ixheaacd_add32_sat(*out, (WORD32)((sum * factor_odd) >> 15)); + *out = ixheaacd_add32_sat( + *out, ixheaacd_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); out++; sum = 0; sum = ixheaacd_mac32x32in64_7(sum, &in[i - 2], filter); - *out = ixheaacd_add32_sat(*out, (WORD32)((sum * factor_even) >> 15)); + *out = ixheaacd_add32_sat( + *out, ixheaacd_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); out++; } i = length - 3; sum = 0; sum = ixheaacd_mac32x32in64_n(sum, &in[i - 3], filter, 6); sum = ixheaacd_mac32x32in64(sum, in[i + 2], filter[6]); - *out += (WORD32)((sum * factor_odd) >> 15); + *out = ixheaacd_add32_sat( + *out, ixheaacd_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); out++; i = length - 2; @@ -393,7 +397,8 @@ static VOID ixheaacd_filter_and_add(const WORD32 *in, const WORD32 length, sum = ixheaacd_mac32x32in64(sum, in[i + 1], filter[5]); sum = ixheaacd_mac32x32in64(sum, in[i], filter[6]); - *out += (WORD32)((sum * factor_even) >> 15); + *out = ixheaacd_add32_sat( + *out, ixheaacd_sat64_32((((WORD64)sum * (WORD64)factor_even) >> 15))); out++; i = length - 1; @@ -403,7 +408,8 @@ static VOID ixheaacd_filter_and_add(const WORD32 *in, const WORD32 length, sum = ixheaacd_mac32x32in64(sum, in[i - 1], filter[5]); sum = ixheaacd_mac32x32in64(sum, in[i - 2], filter[6]); - *out += (WORD32)((sum * factor_odd) >> 15); + *out = ixheaacd_add32_sat( + *out, ixheaacd_sat64_32((((WORD64)sum * (WORD64)factor_odd) >> 15))); } static WORD32 ixheaacd_estimate_dmx_im(const WORD32 *dmx_re, @@ -520,15 +526,17 @@ static WORD32 ixheaacd_cplx_pred_upmixing( alpha_q_im_temp = alpha_q_im[grp][sfb] * 1677722; if (cplx_pred_used[grp][sfb]) { for (k = 0; k < pstr_sfb_info->sfb_width[sfb]; k++, i++) { - WORD32 mid_side = r_spec[i] - - (WORD32)((WORD64)ixheaacd_mult32x32in64( - alpha_q_re_temp, l_spec[i]) >> - 24) - - (WORD32)((WORD64)ixheaacd_mult32x32in64( - alpha_q_im_temp, dmx_im[i]) >> - 24); - r_spec[i] = (factor)*ixheaacd_sub32_sat(l_spec[i], mid_side); - l_spec[i] = l_spec[i] + mid_side; + WORD32 mid_side = ixheaacd_sub32_sat( + ixheaacd_sub32_sat(r_spec[i], + (WORD32)((WORD64)ixheaacd_mult32x32in64( + alpha_q_re_temp, l_spec[i]) >> + 24)), + (WORD32)((WORD64)ixheaacd_mult32x32in64(alpha_q_im_temp, + dmx_im[i]) >> + 24)); + r_spec[i] = ixheaacd_sat64_32((WORD64)factor) * + (WORD64)(ixheaacd_sub32_sat(l_spec[i], mid_side)); + l_spec[i] = ixheaacd_add32_sat(l_spec[i], mid_side); } } else { @@ -549,7 +557,8 @@ static WORD32 ixheaacd_cplx_pred_upmixing( alpha_q_re_temp, l_spec[i]) >> 24)); - r_spec[i] = (factor) * (ixheaacd_sub32_sat(l_spec[i], mid_side)); + r_spec[i] = ixheaacd_sat64_32((WORD64)factor) * + (WORD64)(ixheaacd_sub32_sat(l_spec[i], mid_side)); l_spec[i] = ixheaacd_add32_sat(l_spec[i], mid_side); } @@ -633,13 +642,13 @@ WORD32 ixheaacd_ics_info(ia_usac_data_struct *usac_data, WORD32 chn, } WORD32 ixheaacd_core_coder_data(WORD32 id, ia_usac_data_struct *usac_data, - WORD32 elem_idx, WORD32 *chan_offset, + WORD32 elem_idx, WORD32 chan_offset, ia_bit_buf_struct *it_bit_buff, WORD32 nr_core_coder_channels) { WORD32 err_code = 0; WORD32 k = 0, ch = 0, chn, left = 0, right = 0; - ia_usac_tmp_core_coder_struct str_tmp_core_coder; + ia_usac_tmp_core_coder_struct str_tmp_core_coder = {0}; ia_usac_tmp_core_coder_struct *pstr_core_coder = &str_tmp_core_coder; ia_td_frame_data_struct td_frame; @@ -660,8 +669,8 @@ WORD32 ixheaacd_core_coder_data(WORD32 id, ia_usac_data_struct *usac_data, pstr_core_coder->common_window = ixheaacd_read_bits_buf(it_bit_buff, 1); if (pstr_core_coder->common_window) { - left = *chan_offset; - right = *chan_offset + 1; + left = chan_offset; + right = chan_offset + 1; err_code = ixheaacd_ics_info(usac_data, left, &pstr_core_coder->max_sfb[left], @@ -698,8 +707,8 @@ WORD32 ixheaacd_core_coder_data(WORD32 id, ia_usac_data_struct *usac_data, pstr_core_coder->ms_mask_present[0] = ixheaacd_read_ms_mask(usac_data, pstr_core_coder, it_bit_buff, left); } else { - left = *chan_offset; - right = *chan_offset + 1; + left = chan_offset; + right = chan_offset + 1; pstr_core_coder->ms_mask_present[0] = 0; pstr_core_coder->ms_mask_present[1] = 0; @@ -768,12 +777,12 @@ WORD32 ixheaacd_core_coder_data(WORD32 id, ia_usac_data_struct *usac_data, } else { pstr_core_coder->common_window = 0; pstr_core_coder->common_tw = 0; - left = *chan_offset; - right = *chan_offset; - if (nr_core_coder_channels == 2) right = *chan_offset + 1; + left = chan_offset; + right = chan_offset; + if (nr_core_coder_channels == 2) right = chan_offset + 1; } - for (ch = 0, chn = *chan_offset; ch < nr_core_coder_channels; ch++, chn++) { + for (ch = 0, chn = chan_offset; ch < nr_core_coder_channels; ch++, chn++) { if (pstr_core_coder->core_mode[ch] == 1) { err_code = ixheaacd_tw_buff_update(usac_data, chn, usac_data->str_tddec[chn]); @@ -847,9 +856,10 @@ WORD32 ixheaacd_core_coder_data(WORD32 id, ia_usac_data_struct *usac_data, if (pstr_core_coder->tns_on_lr == 0 && (id != ID_USAC_LFE)) { for (ch = 0, chn = left; chn <= right; ch++, chn++) { if (pstr_core_coder->core_mode[ch] == CORE_MODE_FD) { - ixheaacd_tns_apply( + err_code = ixheaacd_tns_apply( usac_data, usac_data->coef_fix[chn], pstr_core_coder->max_sfb[ch], usac_data->pstr_sfb_info[chn], usac_data->pstr_tns[chn]); + if (err_code) return err_code; } } } @@ -873,9 +883,10 @@ WORD32 ixheaacd_core_coder_data(WORD32 id, ia_usac_data_struct *usac_data, if (pstr_core_coder->tns_on_lr) { for (ch = 0, chn = left; chn <= right; ch++, chn++) { if (pstr_core_coder->core_mode[ch] == CORE_MODE_FD) { - ixheaacd_tns_apply( + err_code = ixheaacd_tns_apply( usac_data, usac_data->coef_fix[chn], pstr_core_coder->max_sfb[ch], usac_data->pstr_sfb_info[chn], usac_data->pstr_tns[chn]); + if (err_code) return err_code; } } } diff --git a/decoder/ixheaacd_fft.c b/decoder/ixheaacd_fft.c index c5ac7b9..fdc2e13 100644 --- a/decoder/ixheaacd_fft.c +++ b/decoder/ixheaacd_fft.c @@ -24,6 +24,7 @@ #include "ixheaacd_interface.h" #include "ixheaacd_constants.h" #include +#include "ixheaacd_basic_ops40.h" #include "ixheaacd_function_selector.h" extern const WORD32 ixheaacd_twiddle_table_fft_32x32[514]; @@ -42,33 +43,24 @@ extern const WORD8 ixheaacd_mps_dig_rev[16]; (j) = _ >> (m); \ } while (0) -static PLATFORM_INLINE WORD32 ixheaacd_mult32(WORD32 a, WORD32 b) { +static PLATFORM_INLINE WORD32 ixheaacd_mult32_sat(WORD32 a, WORD32 b) { WORD32 result; WORD64 temp_result; temp_result = (WORD64)a * (WORD64)b; - result = (WORD32)(temp_result >> 31); + result = ixheaacd_sat64_32(temp_result >> 31); return (result); } -static PLATFORM_INLINE WORD32 ixheaacd_mac32(WORD32 a, WORD32 b, WORD32 c) { +static PLATFORM_INLINE WORD32 ixheaacd_mac32_sat(WORD32 a, WORD32 b, WORD32 c) { WORD32 result; - result = a + ixheaacd_mult32(b, c); + result = ixheaacd_add32_sat(a, ixheaacd_mult32_sat(b, c)); return (result); } -static PLATFORM_INLINE WORD32 ixheaacd_mult32_shl(WORD32 a, WORD32 b) { - WORD32 result; - WORD64 temp_result; - - temp_result = (WORD64)a * (WORD64)b; - result = (WORD32)(temp_result >> 32); - - return (result << 1); -} VOID ixheaacd_mps_complex_fft_64_dec(WORD32 *ptr_x, WORD32 *fin_re, WORD32 *fin_im, WORD32 nlength) { @@ -105,23 +97,23 @@ VOID ixheaacd_mps_complex_fft_64_dec(WORD32 *ptr_x, WORD32 *fin_re, x3r = *inp; x3i = *(inp + 1); - x0r = x0r + x2r; - x0i = x0i + x2i; - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + x1r; - x0i = x0i + x1i; - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + x3i; - x2i = x2i - x3r; - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *ptr_y++ = x0r; *ptr_y++ = x0i; @@ -159,23 +151,23 @@ VOID ixheaacd_mps_complex_fft_64_dec(WORD32 *ptr_x, WORD32 *fin_re, x3i = (*(data + 1)); data -= 3 * (del << 1); - x0r = x0r + x2r; - x0i = x0i + x2i; - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + x1r; - x0i = x0i + x1i; - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + x3i; - x2i = x2i - x3r; - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -228,38 +220,41 @@ VOID ixheaacd_mps_complex_fft_64_dec(WORD32 *ptr_x, WORD32 *fin_re, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) - ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2l) - ixheaacd_mult32(x2i, w2h)); - x2i = ixheaacd_mac32(ixheaacd_mult32(x2r, w2h), x2i, w2l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2r, w2l), + ixheaacd_mult32_sat(x2i, w2h)); + x2i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x2r, w2h), x2i, w2l); x2r = tmp; - tmp = (ixheaacd_mult32(x3r, w3l) - ixheaacd_mult32(x3i, w3h)); - x3i = ixheaacd_mac32(ixheaacd_mult32(x3r, w3h), x3i, w3l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3r, w3l), + ixheaacd_mult32_sat(x3i, w3h)); + x3i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x3r, w3h), x3i, w3l); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + (x3i); - x2i = x2i - (x3r); - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -306,38 +301,42 @@ VOID ixheaacd_mps_complex_fft_64_dec(WORD32 *ptr_x, WORD32 *fin_re, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) - ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2l) - ixheaacd_mult32(x2i, w2h)); - x2i = ixheaacd_mac32(ixheaacd_mult32(x2r, w2h), x2i, w2l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2r, w2l), + ixheaacd_mult32_sat(x2i, w2h)); + x2i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x2r, w2h), x2i, w2l); x2r = tmp; - tmp = (ixheaacd_mult32(x3r, w3h) + ixheaacd_mult32(x3i, w3l)); - x3i = -ixheaacd_mult32(x3r, w3l) + ixheaacd_mult32(x3i, w3h); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x3r, w3h), + ixheaacd_mult32_sat(x3i, w3l)); + x3i = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3i, w3h), + ixheaacd_mult32_sat(x3r, w3l)); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + (x3i); - x2i = x2i - (x3r); - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -384,38 +383,43 @@ VOID ixheaacd_mps_complex_fft_64_dec(WORD32 *ptr_x, WORD32 *fin_re, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) - ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2h) + ixheaacd_mult32(x2i, w2l)); - x2i = -ixheaacd_mult32(x2r, w2l) + ixheaacd_mult32(x2i, w2h); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x2r, w2h), + ixheaacd_mult32_sat(x2i, w2l)); + x2i = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2i, w2h), + ixheaacd_mult32_sat(x2r, w2l)); x2r = tmp; - tmp = (ixheaacd_mult32(x3r, w3h) + ixheaacd_mult32(x3i, w3l)); - x3i = -ixheaacd_mult32(x3r, w3l) + ixheaacd_mult32(x3i, w3h); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x3r, w3h), + ixheaacd_mult32_sat(x3i, w3l)); + x3i = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3i, w3h), + ixheaacd_mult32_sat(x3r, w3l)); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + (x3i); - x2i = x2i - (x3r); - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -462,38 +466,42 @@ VOID ixheaacd_mps_complex_fft_64_dec(WORD32 *ptr_x, WORD32 *fin_re, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) - ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2h) + ixheaacd_mult32(x2i, w2l)); - x2i = -ixheaacd_mult32(x2r, w2l) + ixheaacd_mult32(x2i, w2h); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x2r, w2h), + ixheaacd_mult32_sat(x2i, w2l)); + x2i = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2i, w2h), + ixheaacd_mult32_sat(x2r, w2l)); x2r = tmp; - tmp = (-ixheaacd_mult32(x3r, w3l) + ixheaacd_mult32(x3i, w3h)); - x3i = ixheaacd_mac32(ixheaacd_mult32(x3r, w3h), x3i, w3l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3i, w3h), + ixheaacd_mult32_sat(x3r, w3l)); + x3i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x3r, w3h), x3i, w3l); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i - x3i; - x3r = x1r - (x3r << 1); - x3i = x1i + (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_sub32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_add32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + (x3i); - x2i = x2i - (x3r); - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -591,23 +599,23 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3r = *inp; x3i = *(inp + 1); - x0r = x0r + x2r; - x0i = x0i + x2i; - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + x1r; - x0i = x0i + x1i; - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + x3i; - x2i = x2i - x3r; - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *ptr_y++ = x0r; *ptr_y++ = x0i; @@ -645,23 +653,23 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = (*(data + 1)); data -= 3 * (del << 1); - x0r = x0r + x2r; - x0i = x0i + x2i; - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + x1r; - x0i = x0i + x1i; - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + x3i; - x2i = x2i - x3r; - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -714,38 +722,41 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) - ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2l) - ixheaacd_mult32(x2i, w2h)); - x2i = ixheaacd_mac32(ixheaacd_mult32(x2r, w2h), x2i, w2l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2r, w2l), + ixheaacd_mult32_sat(x2i, w2h)); + x2i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x2r, w2h), x2i, w2l); x2r = tmp; - tmp = (ixheaacd_mult32(x3r, w3l) - ixheaacd_mult32(x3i, w3h)); - x3i = ixheaacd_mac32(ixheaacd_mult32(x3r, w3h), x3i, w3l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3r, w3l), + ixheaacd_mult32_sat(x3i, w3h)); + x3i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x3r, w3h), x3i, w3l); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + (x3i); - x2i = x2i - (x3r); - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -791,38 +802,42 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) - ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2l) - ixheaacd_mult32(x2i, w2h)); - x2i = ixheaacd_mac32(ixheaacd_mult32(x2r, w2h), x2i, w2l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2r, w2l), + ixheaacd_mult32_sat(x2i, w2h)); + x2i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x2r, w2h), x2i, w2l); x2r = tmp; - tmp = (ixheaacd_mult32(x3r, w3h) + ixheaacd_mult32(x3i, w3l)); - x3i = -ixheaacd_mult32(x3r, w3l) + ixheaacd_mult32(x3i, w3h); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x3r, w3h), + ixheaacd_mult32_sat(x3i, w3l)); + x3i = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3i, w3h), + ixheaacd_mult32_sat(x3r, w3l)); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + (x3i); - x2i = x2i - (x3r); - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -869,38 +884,43 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) - ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2h) + ixheaacd_mult32(x2i, w2l)); - x2i = -ixheaacd_mult32(x2r, w2l) + ixheaacd_mult32(x2i, w2h); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x2r, w2h), + ixheaacd_mult32_sat(x2i, w2l)); + x2i = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2i, w2h), + ixheaacd_mult32_sat(x2r, w2l)); x2r = tmp; - tmp = (ixheaacd_mult32(x3r, w3h) + ixheaacd_mult32(x3i, w3l)); - x3i = -ixheaacd_mult32(x3r, w3l) + ixheaacd_mult32(x3i, w3h); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x3r, w3h), + ixheaacd_mult32_sat(x3i, w3l)); + x3i = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3i, w3h), + ixheaacd_mult32_sat(x3r, w3l)); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + (x3i); - x2i = x2i - (x3r); - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -947,38 +967,42 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) - ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2h) + ixheaacd_mult32(x2i, w2l)); - x2i = -ixheaacd_mult32(x2r, w2l) + ixheaacd_mult32(x2i, w2h); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x2r, w2h), + ixheaacd_mult32_sat(x2i, w2l)); + x2i = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2i, w2h), + ixheaacd_mult32_sat(x2r, w2l)); x2r = tmp; - tmp = (-ixheaacd_mult32(x3r, w3l) + ixheaacd_mult32(x3i, w3h)); - x3i = ixheaacd_mac32(ixheaacd_mult32(x3r, w3h), x3i, w3l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3i, w3h), + ixheaacd_mult32_sat(x3r, w3l)); + x3i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x3r, w3h), x3i, w3l); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i - x3i; - x3r = x1r - (x3r << 1); - x3i = x1i + (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_sub32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_add32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r + (x3i); - x2i = x2i - (x3r); - x3i = x2r - (x3i << 1); - x3r = x2i + (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_add32_sat(x2r, x3i); + x2i = ixheaacd_sub32_sat(x2i, x3r); + x3i = ixheaacd_sub32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_add32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -1021,8 +1045,9 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x1r = *ptr_y; x1i = *(ptr_y + 1); - tmp = (ixheaacd_mult32(x1r, w1l) - ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; *ptr_y = (x0r) / 2 - (x1r) / 2; @@ -1047,8 +1072,10 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x1r = *ptr_y; x1i = *(ptr_y + 1); - tmp = (ixheaacd_mult32(x1r, w1h) + ixheaacd_mult32(x1i, w1l)); - x1i = -ixheaacd_mult32(x1r, w1l) + ixheaacd_mult32(x1i, w1h); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x1r, w1h), + ixheaacd_mult32_sat(x1i, w1l)); + x1i = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1i, w1h), + ixheaacd_mult32_sat(x1r, w1l)); x1r = tmp; *ptr_y = (x0r) / 2 - (x1r) / 2; @@ -1091,23 +1118,23 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3r = *inp; x3i = *(inp + 1); - x0r = x0r + x2r; - x0i = x0i + x2i; - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + x1r; - x0i = x0i + x1i; - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r - x3i; - x2i = x2i + x3r; - x3i = x2r + (x3i << 1); - x3r = x2i - (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_sub32_sat(x2r, x3i); + x2i = ixheaacd_add32_sat(x2i, x3r); + x3i = ixheaacd_add32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_sub32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *ptr_y++ = x0r; *ptr_y++ = x0i; @@ -1145,23 +1172,23 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = (*(data + 1)); data -= 3 * (del << 1); - x0r = x0r + x2r; - x0i = x0i + x2i; - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); x0r = ixheaacd_add32_sat(x0r, x1r); x0i = ixheaacd_add32_sat(x0i, x1i); - x1r = ixheaacd_sub32_sat(x0r, (x1r << 1)); - x1i = ixheaacd_sub32_sat(x0i, (x1i << 1)); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); x2r = ixheaacd_sub32_sat(x2r, x3i); x2i = ixheaacd_add32_sat(x2i, x3r); - x3i = ixheaacd_add32_sat(x2r, (x3i << 1)); - x3r = ixheaacd_sub32_sat(x2i, (x3r << 1)); + x3i = ixheaacd_add32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_sub32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -1214,38 +1241,41 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) + ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(-ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(-ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2l) + ixheaacd_mult32(x2i, w2h)); - x2i = ixheaacd_mac32(-ixheaacd_mult32(x2r, w2h), x2i, w2l); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x2r, w2l), + ixheaacd_mult32_sat(x2i, w2h)); + x2i = ixheaacd_mac32_sat(-ixheaacd_mult32_sat(x2r, w2h), x2i, w2l); x2r = tmp; - tmp = (ixheaacd_mult32(x3r, w3l) + ixheaacd_mult32(x3i, w3h)); - x3i = ixheaacd_mac32(-ixheaacd_mult32(x3r, w3h), x3i, w3l); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x3r, w3l), + ixheaacd_mult32_sat(x3i, w3h)); + x3i = ixheaacd_mac32_sat(-ixheaacd_mult32_sat(x3r, w3h), x3i, w3l); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r - (x3i); - x2i = x2i + (x3r); - x3i = x2r + (x3i << 1); - x3r = x2i - (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_sub32_sat(x2r, x3i); + x2i = ixheaacd_add32_sat(x2i, x3r); + x3i = ixheaacd_add32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_sub32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -1292,38 +1322,42 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) + ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(-ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(-ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2l) + ixheaacd_mult32(x2i, w2h)); - x2i = ixheaacd_mac32(-ixheaacd_mult32(x2r, w2h), x2i, w2l); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x2r, w2l), + ixheaacd_mult32_sat(x2i, w2h)); + x2i = ixheaacd_mac32_sat(-ixheaacd_mult32_sat(x2r, w2h), x2i, w2l); x2r = tmp; - tmp = (ixheaacd_mult32(x3r, w3h) - ixheaacd_mult32(x3i, w3l)); - x3i = ixheaacd_mult32(x3r, w3l) + ixheaacd_mult32(x3i, w3h); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3r, w3h), + ixheaacd_mult32_sat(x3i, w3l)); + x3i = ixheaacd_add32_sat(ixheaacd_mult32_sat(x3r, w3l), + ixheaacd_mult32_sat(x3i, w3h)); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r - (x3i); - x2i = x2i + (x3r); - x3i = x2r + (x3i << 1); - x3r = x2i - (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_sub32_sat(x2r, x3i); + x2i = ixheaacd_add32_sat(x2i, x3r); + x3i = ixheaacd_add32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_sub32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -1370,38 +1404,43 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) + ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(-ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(-ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2h) - ixheaacd_mult32(x2i, w2l)); - x2i = ixheaacd_mult32(x2r, w2l) + ixheaacd_mult32(x2i, w2h); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2r, w2h), + ixheaacd_mult32_sat(x2i, w2l)); + x2i = ixheaacd_add32_sat(ixheaacd_mult32_sat(x2r, w2l), + ixheaacd_mult32_sat(x2i, w2h)); x2r = tmp; - tmp = (ixheaacd_mult32(x3r, w3h) - ixheaacd_mult32(x3i, w3l)); - x3i = ixheaacd_mult32(x3r, w3l) + ixheaacd_mult32(x3i, w3h); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x3r, w3h), + ixheaacd_mult32_sat(x3i, w3l)); + x3i = ixheaacd_add32_sat(ixheaacd_mult32_sat(x3r, w3l), + ixheaacd_mult32_sat(x3i, w3h)); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i + x3i; - x3r = x1r - (x3r << 1); - x3i = x1i - (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_add32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_sub32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r - (x3i); - x2i = x2i + (x3r); - x3i = x2r + (x3i << 1); - x3r = x2i - (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_sub32_sat(x2r, x3i); + x2i = ixheaacd_add32_sat(x2i, x3r); + x3i = ixheaacd_add32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_sub32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -1448,38 +1487,42 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x3i = *(data + 1); data -= 3 * (del << 1); - tmp = (ixheaacd_mult32(x1r, w1l) + ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(-ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(-ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; - tmp = (ixheaacd_mult32(x2r, w2h) - ixheaacd_mult32(x2i, w2l)); - x2i = ixheaacd_mult32(x2r, w2l) + ixheaacd_mult32(x2i, w2h); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x2r, w2h), + ixheaacd_mult32_sat(x2i, w2l)); + x2i = ixheaacd_add32_sat(ixheaacd_mult32_sat(x2r, w2l), + ixheaacd_mult32_sat(x2i, w2h)); x2r = tmp; - tmp = (-ixheaacd_mult32(x3r, w3l) - ixheaacd_mult32(x3i, w3h)); - x3i = ixheaacd_mac32(-ixheaacd_mult32(x3r, w3h), x3i, w3l); + tmp = -ixheaacd_add32_sat(ixheaacd_mult32_sat(x3r, w3l), + ixheaacd_mult32_sat(x3i, w3h)); + x3i = ixheaacd_mac32_sat(-ixheaacd_mult32_sat(x3r, w3h), x3i, w3l); x3r = tmp; x0r = (*data); x0i = (*(data + 1)); - x0r = x0r + (x2r); - x0i = x0i + (x2i); - x2r = x0r - (x2r << 1); - x2i = x0i - (x2i << 1); - x1r = x1r + x3r; - x1i = x1i - x3i; - x3r = x1r - (x3r << 1); - x3i = x1i + (x3i << 1); + x0r = ixheaacd_add32_sat(x0r, x2r); + x0i = ixheaacd_add32_sat(x0i, x2i); + x2r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x2r, 1)); + x2i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x2i, 1)); + x1r = ixheaacd_add32_sat(x1r, x3r); + x1i = ixheaacd_sub32_sat(x1i, x3i); + x3r = ixheaacd_sub32_sat(x1r, ixheaacd_shl32_sat(x3r, 1)); + x3i = ixheaacd_add32_sat(x1i, ixheaacd_shl32_sat(x3i, 1)); - x0r = x0r + (x1r); - x0i = x0i + (x1i); - x1r = x0r - (x1r << 1); - x1i = x0i - (x1i << 1); - x2r = x2r - (x3i); - x2i = x2i + (x3r); - x3i = x2r + (x3i << 1); - x3r = x2i - (x3r << 1); + x0r = ixheaacd_add32_sat(x0r, x1r); + x0i = ixheaacd_add32_sat(x0i, x1i); + x1r = ixheaacd_sub32_sat(x0r, ixheaacd_shl32_sat(x1r, 1)); + x1i = ixheaacd_sub32_sat(x0i, ixheaacd_shl32_sat(x1i, 1)); + x2r = ixheaacd_sub32_sat(x2r, x3i); + x2i = ixheaacd_add32_sat(x2i, x3r); + x3i = ixheaacd_add32_sat(x2r, ixheaacd_shl32_sat(x3i, 1)); + x3r = ixheaacd_sub32_sat(x2i, ixheaacd_shl32_sat(x3r, 1)); *data = x0r; *(data + 1) = x0i; @@ -1522,8 +1565,9 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x1r = *ptr_y; x1i = *(ptr_y + 1); - tmp = (ixheaacd_mult32(x1r, w1l) + ixheaacd_mult32(x1i, w1h)); - x1i = ixheaacd_mac32(-ixheaacd_mult32(x1r, w1h), x1i, w1l); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); + x1i = ixheaacd_mac32_sat(-ixheaacd_mult32_sat(x1r, w1h), x1i, w1l); x1r = tmp; *ptr_y = (x0r) / 2 - (x1r) / 2; @@ -1548,8 +1592,10 @@ VOID ixheaacd_complex_fft_p2_dec(WORD32 *xr, WORD32 *xi, WORD32 nlength, x1r = *ptr_y; x1i = *(ptr_y + 1); - tmp = (ixheaacd_mult32(x1r, w1h) - ixheaacd_mult32(x1i, w1l)); - x1i = ixheaacd_mult32(x1r, w1l) + ixheaacd_mult32(x1i, w1h); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(x1r, w1h), + ixheaacd_mult32_sat(x1i, w1l)); + x1i = ixheaacd_add32_sat(ixheaacd_mult32_sat(x1r, w1l), + ixheaacd_mult32_sat(x1i, w1h)); x1r = tmp; *ptr_y = (x0r) / 2 - (x1r) / 2; @@ -1669,31 +1715,31 @@ VOID ixheaacd_complex_fft_p3(WORD32 *xr, WORD32 *xi, WORD32 nlength, if (fft_mode < 0) { for (i = 0; i < nlength; i += 3) { - tmp = ixheaacd_sub32_sat(ixheaacd_mult32(ptr_x[2 * i], (*w1r)), - ixheaacd_mult32(ptr_x[2 * i + 1], (*w1i))); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(ptr_x[2 * i], (*w1r)), + ixheaacd_mult32_sat(ptr_x[2 * i + 1], (*w1i))); ptr_x[2 * i + 1] = - ixheaacd_add32_sat(ixheaacd_mult32(ptr_x[2 * i], (*w1i)), - ixheaacd_mult32(ptr_x[2 * i + 1], (*w1r))); + ixheaacd_add32_sat(ixheaacd_mult32_sat(ptr_x[2 * i], (*w1i)), + ixheaacd_mult32_sat(ptr_x[2 * i + 1], (*w1r))); ptr_x[2 * i] = tmp; w1r++; w1i++; - tmp = ixheaacd_sub32_sat(ixheaacd_mult32(ptr_x[2 * i + 2], (*w1r)), - ixheaacd_mult32(ptr_x[2 * i + 3], (*w1i))); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(ptr_x[2 * i + 2], (*w1r)), + ixheaacd_mult32_sat(ptr_x[2 * i + 3], (*w1i))); ptr_x[2 * i + 3] = - ixheaacd_add32_sat(ixheaacd_mult32(ptr_x[2 * i + 2], (*w1i)), - ixheaacd_mult32(ptr_x[2 * i + 3], (*w1r))); + ixheaacd_add32_sat(ixheaacd_mult32_sat(ptr_x[2 * i + 2], (*w1i)), + ixheaacd_mult32_sat(ptr_x[2 * i + 3], (*w1r))); ptr_x[2 * i + 2] = tmp; w1r++; w1i++; - tmp = ixheaacd_sub32_sat(ixheaacd_mult32(ptr_x[2 * i + 4], (*w1r)), - ixheaacd_mult32(ptr_x[2 * i + 5], (*w1i))); + tmp = ixheaacd_sub32_sat(ixheaacd_mult32_sat(ptr_x[2 * i + 4], (*w1r)), + ixheaacd_mult32_sat(ptr_x[2 * i + 5], (*w1i))); ptr_x[2 * i + 5] = - ixheaacd_add32_sat(ixheaacd_mult32(ptr_x[2 * i + 4], (*w1i)), - ixheaacd_mult32(ptr_x[2 * i + 5], (*w1r))); + ixheaacd_add32_sat(ixheaacd_mult32_sat(ptr_x[2 * i + 4], (*w1i)), + ixheaacd_mult32_sat(ptr_x[2 * i + 5], (*w1r))); ptr_x[2 * i + 4] = tmp; w1r += 3 * (128 / mpass - 1) + 1; @@ -1703,31 +1749,31 @@ VOID ixheaacd_complex_fft_p3(WORD32 *xr, WORD32 *xi, WORD32 nlength, else { for (i = 0; i < nlength; i += 3) { - tmp = ixheaacd_add32_sat(ixheaacd_mult32(ptr_x[2 * i], (*w1r)), - ixheaacd_mult32(ptr_x[2 * i + 1], (*w1i))); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(ptr_x[2 * i], (*w1r)), + ixheaacd_mult32_sat(ptr_x[2 * i + 1], (*w1i))); ptr_x[2 * i + 1] = - ixheaacd_sub32_sat(ixheaacd_mult32(ptr_x[2 * i + 1], (*w1r)), - ixheaacd_mult32(ptr_x[2 * i], (*w1i))); + ixheaacd_sub32_sat(ixheaacd_mult32_sat(ptr_x[2 * i + 1], (*w1r)), + ixheaacd_mult32_sat(ptr_x[2 * i], (*w1i))); ptr_x[2 * i] = tmp; w1r++; w1i++; - tmp = ixheaacd_add32_sat(ixheaacd_mult32(ptr_x[2 * i + 2], (*w1r)), - ixheaacd_mult32(ptr_x[2 * i + 3], (*w1i))); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(ptr_x[2 * i + 2], (*w1r)), + ixheaacd_mult32_sat(ptr_x[2 * i + 3], (*w1i))); ptr_x[2 * i + 3] = - ixheaacd_sub32_sat(ixheaacd_mult32(ptr_x[2 * i + 3], (*w1r)), - ixheaacd_mult32(ptr_x[2 * i + 2], (*w1i))); + ixheaacd_sub32_sat(ixheaacd_mult32_sat(ptr_x[2 * i + 3], (*w1r)), + ixheaacd_mult32_sat(ptr_x[2 * i + 2], (*w1i))); ptr_x[2 * i + 2] = tmp; w1r++; w1i++; - tmp = ixheaacd_add32_sat(ixheaacd_mult32(ptr_x[2 * i + 4], (*w1r)), - ixheaacd_mult32(ptr_x[2 * i + 5], (*w1i))); + tmp = ixheaacd_add32_sat(ixheaacd_mult32_sat(ptr_x[2 * i + 4], (*w1r)), + ixheaacd_mult32_sat(ptr_x[2 * i + 5], (*w1i))); ptr_x[2 * i + 5] = - ixheaacd_sub32_sat(ixheaacd_mult32(ptr_x[2 * i + 5], (*w1r)), - ixheaacd_mult32(ptr_x[2 * i + 4], (*w1i))); + ixheaacd_sub32_sat(ixheaacd_mult32_sat(ptr_x[2 * i + 5], (*w1r)), + ixheaacd_mult32_sat(ptr_x[2 * i + 4], (*w1i))); ptr_x[2 * i + 4] = tmp; w1r += 3 * (128 / mpass - 1) + 1; diff --git a/decoder/ixheaacd_hbe_trans.c b/decoder/ixheaacd_hbe_trans.c index 0c6f191..19c8cbb 100644 --- a/decoder/ixheaacd_hbe_trans.c +++ b/decoder/ixheaacd_hbe_trans.c @@ -56,7 +56,7 @@ #include "ixheaacd_pvc_dec.h" #include "ixheaacd_sbr_dec.h" - +#include "ixheaacd_error_standards.h" #include "ixheaacd_sbrqmftrans.h" #include "ixheaacd_qmf_poly.h" @@ -259,8 +259,9 @@ WORD32 ixheaacd_qmf_hbe_apply(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer, TWICE_QMF_SYNTH_CHANNELS_NUM * sizeof(FLOAT32)); } - ixheaacd_hbe_post_anal_process(ptr_hbe_txposer, pitch_in_bins, - ptr_hbe_txposer->upsamp_4_flag); + err_code = ixheaacd_hbe_post_anal_process(ptr_hbe_txposer, pitch_in_bins, + ptr_hbe_txposer->upsamp_4_flag); + if (err_code) return err_code; for (i = 0; i < ptr_hbe_txposer->no_bins; i++) { for (qmf_band_idx = ptr_hbe_txposer->start_band; @@ -1532,9 +1533,9 @@ VOID ixheaacd_hbe_post_anal_xprod4(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer, } } -VOID ixheaacd_hbe_post_anal_process(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer, - WORD32 pitch_in_bins, - WORD32 sbr_upsamp_4_flg) { +IA_ERRORCODE ixheaacd_hbe_post_anal_process( + ia_esbr_hbe_txposer_struct *ptr_hbe_txposer, WORD32 pitch_in_bins, + WORD32 sbr_upsamp_4_flg) { FLOAT32 p; WORD32 trans_fac; WORD32 qmf_voc_columns = ptr_hbe_txposer->no_bins / 2; @@ -1555,9 +1556,11 @@ VOID ixheaacd_hbe_post_anal_process(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer, ptr_hbe_txposer->x_over_qmf[1]); trans_fac = 4; - if (trans_fac <= ptr_hbe_txposer->max_stretch) + if (trans_fac <= ptr_hbe_txposer->max_stretch) { + if (ptr_hbe_txposer->x_over_qmf[2] <= 1) return IA_FATAL_ERROR; ixheaacd_hbe_post_anal_prod4(ptr_hbe_txposer, qmf_voc_columns, ptr_hbe_txposer->x_over_qmf[2]); + } } else { trans_fac = 2; @@ -1579,9 +1582,12 @@ VOID ixheaacd_hbe_post_anal_process(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer, (pitch_in_bins + sbr_upsamp_4_flg * 128)); trans_fac = 4; - if (trans_fac <= ptr_hbe_txposer->max_stretch) + if (trans_fac <= ptr_hbe_txposer->max_stretch) { + if (ptr_hbe_txposer->x_over_qmf[2] <= 1) return IA_FATAL_ERROR; ixheaacd_hbe_post_anal_xprod4(ptr_hbe_txposer, qmf_voc_columns, ptr_hbe_txposer->x_over_qmf[2], p, (pitch_in_bins + sbr_upsamp_4_flg * 128)); + } } -} \ No newline at end of file + return IA_NO_ERROR; +} diff --git a/decoder/ixheaacd_headerdecode.c b/decoder/ixheaacd_headerdecode.c index 140ad78..f888798 100644 --- a/decoder/ixheaacd_headerdecode.c +++ b/decoder/ixheaacd_headerdecode.c @@ -19,6 +19,7 @@ */ #include #include +#include "ixheaacd_error_standards.h" #include "ixheaacd_constants.h" #include #include @@ -153,21 +154,18 @@ WORD32 ixheaacd_read_prog_config_element( struct ia_bit_buf_struct *it_bit_buff) { WORD32 i, tmp; WORD count = 0, num_ch = 0; - WORD32 object_type; tmp = ixheaacd_read_bits_buf(it_bit_buff, 6); ptr_config_element->element_instance_tag = (tmp >> 2); ptr_config_element->object_type = tmp & 0x3; - object_type = 0; - if ((ptr_config_element->object_type + 1) != 2 && (ptr_config_element->object_type + 1) != 4 ) { - object_type = IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL; + return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL; } ptr_config_element->samp_freq_index = ixheaacd_read_bits_buf(it_bit_buff, 4); @@ -236,7 +234,7 @@ WORD32 ixheaacd_read_prog_config_element( ixheaacd_skip_bits(it_bit_buff, 8, tmp); - return object_type; + return 0; } WORD ixheaacd_decode_pce(struct ia_bit_buf_struct *it_bit_buff, @@ -245,9 +243,10 @@ WORD ixheaacd_decode_pce(struct ia_bit_buf_struct *it_bit_buff, WORD32 error_code = 0; if (*ui_pce_found_in_hdr == 1 || *ui_pce_found_in_hdr == 3) { - ia_program_config_struct ptr_config_element; + ia_program_config_struct ptr_config_element = {0}; ptr_config_element.alignment_bits = ptr_prog_config->alignment_bits; - ixheaacd_read_prog_config_element(&ptr_config_element, it_bit_buff); + error_code = + ixheaacd_read_prog_config_element(&ptr_config_element, it_bit_buff); *ui_pce_found_in_hdr = 3; } else { error_code = @@ -494,6 +493,9 @@ WORD32 ixheaacd_ga_hdr_dec(ia_aac_dec_state_struct *aac_state_struct, memset(aac_state_struct->ia_audio_specific_config, 0, sizeof(ia_audio_specific_config_struct)); + memset(&(aac_state_struct->eld_specific_config), 0, + sizeof(ia_eld_specific_config_struct)); + pstr_audio_specific_config = aac_state_struct->ia_audio_specific_config; aac_state_struct->p_config->str_prog_config.alignment_bits = @@ -539,11 +541,12 @@ WORD32 ixheaacd_ga_hdr_dec(ia_aac_dec_state_struct *aac_state_struct, ixheaacd_read_bits_buf(it_bit_buff, 5); } - if ((aac_state_struct->audio_object_type >= AOT_AAC_MAIN || - aac_state_struct->audio_object_type <= AOT_AAC_LTP || + if (((aac_state_struct->audio_object_type >= AOT_AAC_MAIN && + aac_state_struct->audio_object_type <= AOT_AAC_LTP) || aac_state_struct->audio_object_type == AOT_AAC_SCAL || aac_state_struct->audio_object_type == AOT_TWIN_VQ || aac_state_struct->audio_object_type == AOT_ER_AAC_LD || + aac_state_struct->audio_object_type == AOT_ER_AAC_ELD || aac_state_struct->audio_object_type == AOT_ER_AAC_LC) && aac_state_struct->audio_object_type != AOT_USAC) @@ -610,6 +613,9 @@ WORD32 ixheaacd_ga_hdr_dec(ia_aac_dec_state_struct *aac_state_struct, &(pstr_audio_specific_config->channel_configuration)); if (err != 0) return err; + pstr_audio_specific_config->sampling_frequency = + pstr_audio_specific_config->str_usac_config.usac_sampling_frequency; + if (pstr_audio_specific_config->audio_object_type == AOT_USAC) { pstr_audio_specific_config->sbr_present_flag = 1; pstr_audio_specific_config->ext_audio_object_type = AOT_SBR; @@ -635,54 +641,7 @@ WORD32 ixheaacd_ga_hdr_dec(ia_aac_dec_state_struct *aac_state_struct, } { - WORD32 write_flag = 0; - WORD32 system_flag = 1; - WORD32 len; - - if (system_flag) { - if (write_flag == 0) { - if ((SIZE_T)it_bit_buff->ptr_read_next == - (SIZE_T)it_bit_buff->ptr_bit_buf_base) { - len = ((((SIZE_T)it_bit_buff->ptr_bit_buf_end - - (SIZE_T)it_bit_buff->ptr_bit_buf_base) + - 1) - << 3) - - (SIZE_T)it_bit_buff->size; - } else { - len = ((((SIZE_T)it_bit_buff->ptr_bit_buf_end - - (SIZE_T)it_bit_buff->ptr_bit_buf_base) + - 1) - << 3) - - (((((SIZE_T)it_bit_buff->ptr_read_next - - (SIZE_T)it_bit_buff->ptr_bit_buf_base)) - << 3) + - 7 - it_bit_buff->bit_pos); - } - if (len > 0) { - if ((SIZE_T)it_bit_buff->ptr_read_next == - (SIZE_T)it_bit_buff->ptr_bit_buf_base) { - len = ((((SIZE_T)it_bit_buff->ptr_bit_buf_end - - (SIZE_T)it_bit_buff->ptr_bit_buf_base) + - 1) - << 3) - - (SIZE_T)it_bit_buff->size - 0; - } else { - len = ((((SIZE_T)it_bit_buff->ptr_bit_buf_end - - (SIZE_T)it_bit_buff->ptr_bit_buf_base) + - 1) - << 3) - - ((((((SIZE_T)it_bit_buff->ptr_read_next - - (SIZE_T)it_bit_buff->ptr_bit_buf_base)) - << 3) + - 7 - it_bit_buff->bit_pos) - - 0); - } - if (len > 0) { - dummy = ixheaacd_read_bits_buf(it_bit_buff, len); - } - } - } - } + dummy = ixheaacd_skip_bits_buf(it_bit_buff, it_bit_buff->cnt_bits); if ((SIZE_T)it_bit_buff->ptr_read_next == (SIZE_T)it_bit_buff->ptr_bit_buf_base) { @@ -924,7 +883,7 @@ IA_ERRORCODE ixheaacd_latm_header_decode( result = ixheaacd_latm_audio_mux_element( it_bit_buff, &latm_struct_element, aac_state_struct, pstr_samp_rate_info); - if (result < 0) { + if (result != 0) { sync_status = 0; aac_state_struct->sync_status = sync_status; @@ -941,9 +900,9 @@ WORD32 ixheaacd_aac_headerdecode( ia_exhaacplus_dec_api_struct *p_obj_exhaacplus_dec, UWORD8 *buffer, WORD32 *bytes_consumed, const ia_aac_dec_huffman_tables_struct *pstr_huffmann_tables) { - struct ia_bit_buf_struct it_bit_buff, *handle_bit_buff; - ia_adif_header_struct adif; - ia_adts_header_struct adts; + struct ia_bit_buf_struct it_bit_buff = {0}, *handle_bit_buff; + ia_adif_header_struct adif = {0}; + ia_adts_header_struct adts = {0}; WORD32 result; WORD32 header_len; WORD32 sync = 0; @@ -970,6 +929,7 @@ WORD32 ixheaacd_aac_headerdecode( handle_bit_buff = ixheaacd_create_bit_buf(&it_bit_buff, (UWORD8 *)buffer, (WORD16)header_len); handle_bit_buff->cnt_bits += (header_len << 3); + handle_bit_buff->xaac_jmp_buf = &aac_state_struct->xaac_jmp_buf; if (is_ga_header == 1) { return ixheaacd_ga_hdr_dec(aac_state_struct, header_len, bytes_consumed, @@ -1033,7 +993,7 @@ WORD32 ixheaacd_aac_headerdecode( if ((adts.aac_frame_length + ADTS_HEADER_LENGTH) < (header_len - bytes_taken)) { - ia_adts_header_struct adts_loc; + ia_adts_header_struct adts_loc = {0}; handle_bit_buff = ixheaacd_create_init_bit_buf( &it_bit_buff, (UWORD8 *)(buffer + adts.aac_frame_length), @@ -1084,7 +1044,11 @@ WORD32 ixheaacd_aac_headerdecode( bytes_taken += *bytes_consumed; *bytes_consumed = bytes_taken; return result; - } else + } else if (result == -1) + return -1; + else if (result == (WORD32)IA_FATAL_ERROR) + return IA_FATAL_ERROR; + else bytes_taken += *bytes_consumed - 1; continue; } @@ -1107,6 +1071,22 @@ WORD32 ixheaacd_aac_headerdecode( return err_code; } + switch (aac_state_struct->audio_object_type) { + case AOT_AAC_MAIN: + case AOT_AAC_LC: + case AOT_AAC_SSR: + case AOT_AAC_LTP: + case AOT_AAC_SCAL: + case AOT_TWIN_VQ: + case AOT_ER_AAC_LD: + case AOT_ER_AAC_ELD: + case AOT_ER_AAC_LC: + case AOT_USAC: + break; + default: + return IA_ENHAACPLUS_DEC_INIT_FATAL_AUDIOOBJECTTYPE_NOT_SUPPORTED; + } + if (aac_state_struct->audio_object_type != AOT_USAC) aac_state_struct->usac_flag = 0; *bytes_consumed = bytes_taken; diff --git a/decoder/ixheaacd_huff_code_reorder.c b/decoder/ixheaacd_huff_code_reorder.c index 9d8c2a5..c7ef853 100644 --- a/decoder/ixheaacd_huff_code_reorder.c +++ b/decoder/ixheaacd_huff_code_reorder.c @@ -574,7 +574,7 @@ static VOID ixheaacd_huff_ext_sect_info(ia_hcr_info_struct *ptr_hcr_info) { ptr_num_ext_sort_cw_sect[x_srt_sc_cnt] = 0; } -static VOID ixheaacd_hcr_prepare_segmentation_grid( +static UWORD32 ixheaacd_hcr_prepare_segmentation_grid( ia_hcr_info_struct *ptr_hcr_info) { UWORD16 i, j; UWORD16 num_segment = 0; @@ -630,7 +630,12 @@ static VOID ixheaacd_hcr_prepare_segmentation_grid( break; } } + + if (num_segment == 0) ptr_hcr_info->str_dec_io.err_log |= (ERROR_POS << 9); + ptr_hcr_info->str_segment_info.num_segment = num_segment; + + return (ptr_hcr_info->str_dec_io.err_log); } static PLATFORM_INLINE UWORD16 *ixheaacd_huff_dec_pair_hcr_pcw( @@ -734,7 +739,10 @@ static PLATFORM_INLINE WORD16 ixheaacd_huff_dec_pair_hcr_non_pcw( WORD16 index, length; WORD32 y, z; WORD32 read_word1; - WORD32 read_word = ixheaacd_aac_showbits_32(itt_bit_buff->byte_ptr); + WORD32 read_word; + + read_word = ixheaacd_aac_showbits_32(itt_bit_buff->byte_ptr, + itt_bit_buff->bit_count, NULL); ixheaacd_huffman_decode(read_word, &index, &length, code_book_tbl, idx_table); read_word1 = read_word << length; @@ -907,7 +915,8 @@ static UWORD16 *ixheaacd_huff_dec_word_hcr_pcw( WORD32 flush_cw; WORD32 i, value, norm_val, off; WORD32 out1, out2; - WORD16 index, length; + WORD16 index; + WORD32 length; UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; WORD32 spec_index = ptr_hcr_info->str_dec_io.quant_spec_coeff_idx; WORD32 *spec_coef = @@ -923,8 +932,8 @@ static UWORD16 *ixheaacd_huff_dec_word_hcr_pcw( if (read_bit_offset) { *read_bits -= read_bit_offset; *bit_pos += read_bit_offset; - ixheaacd_aac_read_byte_corr1(&ptr_read_next, (WORD16 *)bit_pos, - read_word); + ixheaacd_aac_read_byte_corr1(&ptr_read_next, bit_pos, read_word, + it_bit_buff->ptr_bit_buf_end); } read_word1 = *read_word << *bit_pos; @@ -1072,6 +1081,7 @@ static VOID ixheaacd_decode_pcw(ia_bit_buf_struct *itt_bit_buff, UWORD16 cur_ext_sort_cw_sec; UWORD8 codebook; UWORD8 dimension; + WORD32 increment; WORD32 num_ext_sorted_cw_in_sect_idx = ptr_hcr_info->sect_info.num_ext_sorted_cw_in_sect_idx; @@ -1094,20 +1104,19 @@ static VOID ixheaacd_decode_pcw(ia_bit_buf_struct *itt_bit_buff, WORD32 num_decoded_bits; const UWORD8 *ptr_cb_dimension_tbl = ptr_hcr_info->table_info.ptr_cb_dimension_tbl; - const UWORD16 *cb_table; - const UWORD32 *idx_table; - WORD32 read_word = ixheaacd_aac_showbits_32(itt_bit_buff->ptr_read_next); + WORD32 read_word = ixheaacd_aac_showbits_32( + itt_bit_buff->ptr_read_next, itt_bit_buff->cnt_bits, &increment); WORD32 read_bits = itt_bit_buff->cnt_bits; - itt_bit_buff->ptr_read_next += 4; + itt_bit_buff->ptr_read_next += increment; for (ext_sort_sec = ptr_num_ext_sorted_sect_in_sets[num_ext_sorted_sect_in_sets_idx]; ext_sort_sec != 0; ext_sort_sec--) { codebook = ptr_ext_sorted_cw[ext_sorted_cw_idx]; - cb_table = (UWORD16 *)(ptr_aac_tables->code_book[codebook]); - idx_table = (UWORD32 *)(ptr_aac_tables->index_table[codebook]); + if (codebook <= 0) return; + ext_sorted_cw_idx++; if (ext_sorted_cw_idx >= (MAX_SFB_HCR + MAX_HCR_SETS)) { return; @@ -1122,6 +1131,8 @@ static VOID ixheaacd_decode_pcw(ia_bit_buf_struct *itt_bit_buff, if (codebook <= 4) { WORD32 tbl_sign = 0; + const UWORD16 *cb_table = (UWORD16 *)(ptr_aac_tables->code_book[codebook]); + const UWORD32 *idx_table = (UWORD32 *)(ptr_aac_tables->index_table[codebook]); if (codebook > 2) { tbl_sign = 1; @@ -1157,6 +1168,8 @@ static VOID ixheaacd_decode_pcw(ia_bit_buf_struct *itt_bit_buff, { WORD32 tbl_sign = 0; WORD32 huff_mode = 9; + const UWORD16 *cb_table = (UWORD16 *)(ptr_aac_tables->code_book[codebook]); + const UWORD32 *idx_table = (UWORD32 *)(ptr_aac_tables->index_table[codebook]); num_decoded_bits = 0; if (codebook > 6) { @@ -1271,7 +1284,10 @@ static PLATFORM_INLINE UWORD16 ixheaacd_huff_dec_quad_hcr_non_pcw( const UWORD16 *code_book_tbl, WORD32 tbl_sign, const UWORD32 *idx_table) { WORD16 index, length; WORD16 cw_len; - WORD32 read_word = ixheaacd_aac_showbits_32(itt_bit_buff->byte_ptr); + WORD32 read_word; + + read_word = ixheaacd_aac_showbits_32(itt_bit_buff->byte_ptr, + itt_bit_buff->bit_count, NULL); ixheaacd_huffman_decode(read_word, &index, &length, code_book_tbl, idx_table); cw_len = length; if (tbl_sign) { @@ -1339,16 +1355,22 @@ static PLATFORM_INLINE UWORD16 ixheaacd_huff_dec_word_hcr_non_pcw( WORD32 out1, out2; UWORD16 cw_len; - WORD16 index, length; + WORD16 index; + WORD32 length; + + WORD32 read_word; + WORD32 increment; + + read_word = ixheaacd_aac_showbits_32(itt_bit_buff->byte_ptr, + itt_bit_buff->bit_count, &increment); - WORD32 read_word = ixheaacd_aac_showbits_32(itt_bit_buff->byte_ptr); UWORD8 *ptr_read_next = itt_bit_buff->byte_ptr; - ptr_read_next += 4; + ptr_read_next += increment; ixheaacd_huff_sfb_table(read_word, &index, &length, code_book_tbl, idx_table); cw_len = length; - ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word); + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); out1 = index / 17; out2 = index - out1 * 17; @@ -1374,7 +1396,7 @@ static PLATFORM_INLINE UWORD16 ixheaacd_huff_dec_word_hcr_non_pcw( cw_len++; } - ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word); + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); if (sp1 == 16) { i = 4; @@ -1386,13 +1408,13 @@ static PLATFORM_INLINE UWORD16 ixheaacd_huff_dec_word_hcr_non_pcw( length += (norm_val - 21); cw_len += (norm_val - 21); - ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word); + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); off = ixheaacd_extu(read_word, length, 32 - i); length += i; cw_len += i; - ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word); + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); i = off + ((WORD32)1 << i); @@ -1414,13 +1436,13 @@ static PLATFORM_INLINE UWORD16 ixheaacd_huff_dec_word_hcr_non_pcw( length += (norm_val - 21); cw_len += (norm_val - 21); - ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word); + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); off = ixheaacd_extu(read_word, length, 32 - i); length += i; cw_len += i; - ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word); + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &length, &read_word, NULL); i = off + ((WORD32)1 << i); if (out2 < 0) @@ -1438,8 +1460,6 @@ static VOID ixheaacd_decode_hcr_non_pcw( ia_bit_buf_struct *itt_bit_buff, ia_hcr_info_struct *ptr_hcr_info, ia_aac_dec_tables_struct *ptr_aac_tables, WORD32 *cw_offset, WORD32 trial, WORD32 start) { - UWORD16 *cb_table; - UWORD32 *idx_table; WORD16 codeword_len = 0; WORD8 seg_bits_left; UWORD8 tot_bits_to_save, code_bits_to_save, extra_code_bits; @@ -1452,14 +1472,6 @@ static VOID ixheaacd_decode_hcr_non_pcw( segment_offset++, *cw_offset += 1) { if (p_remaining_bits_in_seg[segment_offset] && !ptr_hcr_info->str_segment_info.is_decoded[*cw_offset]) { - cb_table = - (UWORD16 *)(ptr_aac_tables - ->code_book[ptr_hcr_info->str_non_pcw_side_info - .ptr_cb[*cw_offset % num_segment]]); - idx_table = - (UWORD32 *)(ptr_aac_tables - ->index_table[ptr_hcr_info->str_non_pcw_side_info - .ptr_cb[*cw_offset % num_segment]]); { UWORD32 i_qsc; WORD8 current_seg_bits = p_remaining_bits_in_seg[segment_offset]; @@ -1546,6 +1558,15 @@ static VOID ixheaacd_decode_hcr_non_pcw( if (ptr_hcr_info->str_non_pcw_side_info .ptr_cb[*cw_offset % num_segment] <= 4) { WORD32 tbl_sign = 0; + const UWORD16 *cb_table = + (UWORD16 + *)(ptr_aac_tables + ->code_book[ptr_hcr_info->str_non_pcw_side_info + .ptr_cb[*cw_offset % num_segment]]); + const UWORD32 *idx_table = + (UWORD32 *)(ptr_aac_tables->index_table + [ptr_hcr_info->str_non_pcw_side_info + .ptr_cb[*cw_offset % num_segment]]); if (ptr_hcr_info->str_non_pcw_side_info .ptr_cb[*cw_offset % num_segment] > 2) { @@ -1567,6 +1588,17 @@ static VOID ixheaacd_decode_hcr_non_pcw( .ptr_cb[*cw_offset % num_segment] < 11) { WORD32 tbl_sign = 0; WORD32 huff_mode = 9; + + const UWORD16 *cb_table = + (UWORD16 + *)(ptr_aac_tables + ->code_book[ptr_hcr_info->str_non_pcw_side_info + .ptr_cb[*cw_offset % num_segment]]); + const UWORD32 *idx_table = + (UWORD32 *)(ptr_aac_tables->index_table + [ptr_hcr_info->str_non_pcw_side_info + .ptr_cb[*cw_offset % num_segment]]); + if (ptr_hcr_info->str_non_pcw_side_info .ptr_cb[*cw_offset % num_segment] > 6) { if (ptr_hcr_info->str_non_pcw_side_info @@ -1727,14 +1759,11 @@ static VOID ixheaacd_hcr_reorder_quantized_spec_coeff( WORD32 *arr_temp_values = ptr_hcr_info->str_segment_info.arr_temp_values; WORD32 *ptr_bak = ptr_hcr_info->str_segment_info.arr_temp_values; - WORD32 cnt = 0; - for (i = num_sect; i != 0; i--) { num_spec_val_sect = *ptr_num_sorted_cw_in_sect++ << ptr_cb_dim_shift_tbl[*ptr_sorted_cb]; ptr_teva = &arr_temp_values[*ptr_reorder_offset++]; for (j = num_spec_val_sect; j != 0; j--) { - cnt++; qsc = *ptr_quant_spec_coeff++; abs_qsc = ixheaacd_abs32(qsc); if (abs_qsc <= ptr_lav_tbl[*ptr_sorted_cb]) { @@ -1811,7 +1840,8 @@ UWORD32 ixheaacd_hcr_decoder( ixheaacd_huff_sort_sect_cb_cwd(ptr_hcr_info); - ixheaacd_hcr_prepare_segmentation_grid(ptr_hcr_info); + if (ixheaacd_hcr_prepare_segmentation_grid(ptr_hcr_info) != 0) + return (ptr_hcr_info->str_dec_io.err_log); ixheaacd_huff_ext_sect_info(ptr_hcr_info); diff --git a/decoder/ixheaacd_imdct.c b/decoder/ixheaacd_imdct.c index a93b04b..02929b0 100644 --- a/decoder/ixheaacd_imdct.c +++ b/decoder/ixheaacd_imdct.c @@ -254,7 +254,8 @@ WORD8 ixheaacd_cal_fac_data(ia_usac_data_struct *usac_data, WORD32 i_ch, i_aq = NULL; for (k = 0; k < lfac; k++) { - if (ABS(fac_data[k + 1]) > itemp) itemp = ABS(fac_data[k + 1]); + if (ixheaacd_abs32_sat(fac_data[k + 1]) > itemp) + itemp = ixheaacd_abs32_sat(fac_data[k + 1]); } qshift1 = ixheaacd_norm32(itemp); diff --git a/decoder/ixheaacd_init_config.c b/decoder/ixheaacd_init_config.c index d7650fc..9efd983 100644 --- a/decoder/ixheaacd_init_config.c +++ b/decoder/ixheaacd_init_config.c @@ -62,6 +62,7 @@ #include "ixheaacd_info.h" #include "ixheaacd_struct.h" #include "ixheaacd_constants.h" +#include "ixheaacd_error_standards.h" #include "ixheaacd_error_codes.h" @@ -499,14 +500,30 @@ WORD32 ixheaacd_config(ia_bit_buf_struct *it_bit_buff, pstr_usac_conf->usac_sampling_frequency_index = ixheaacd_read_bits_buf(it_bit_buff, 5); - if (pstr_usac_conf->usac_sampling_frequency_index == 0x1f) + if (pstr_usac_conf->usac_sampling_frequency_index == 0x1f) { pstr_usac_conf->usac_sampling_frequency = ixheaacd_read_bits_buf(it_bit_buff, 24); + if (pstr_usac_conf->usac_sampling_frequency > USAC_MAX_SAMPLE_RATE) { + return IA_FATAL_ERROR; + } + + } else { + static const WORD32 sampling_rate_tbl[] = { + 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, + 16000, 12000, 11025, 8000, 7350, 0, 0, 57600, + 51200, 40000, 38400, 34150, 28800, 25600, 20000, 19200, + 17075, 14400, 12800, 9600, 0, 0, 0}; + + pstr_usac_conf->usac_sampling_frequency = + sampling_rate_tbl[pstr_usac_conf->usac_sampling_frequency_index]; + } + pstr_usac_conf->core_sbr_framelength_index = ixheaacd_read_bits_buf(it_bit_buff, 3); - if (pstr_usac_conf->core_sbr_framelength_index > 4) return -1; + if (pstr_usac_conf->core_sbr_framelength_index > MAX_CORE_SBR_FRAME_LEN_IDX) + return -1; pstr_usac_conf->channel_configuration_index = ixheaacd_read_bits_buf(it_bit_buff, 5); diff --git a/decoder/ixheaacd_initfuncs.c b/decoder/ixheaacd_initfuncs.c index b8f1eae..e95f504 100644 --- a/decoder/ixheaacd_initfuncs.c +++ b/decoder/ixheaacd_initfuncs.c @@ -373,9 +373,9 @@ ia_aac_decoder_struct *ixheaacd_aac_decoder_init( WORD32 sampling_rate = p_state_enhaacplus_dec->sampling_rate; i = 0; - while (sampling_rate != ((pstr_huffmann_tables->str_sample_rate_info[i] - .sampling_frequency)) && - (i < num_entries)) { + while ((i < num_entries) && + sampling_rate != ((pstr_huffmann_tables->str_sample_rate_info[i] + .sampling_frequency))) { i++; } if (i == 12) { diff --git a/decoder/ixheaacd_latmdemux.c b/decoder/ixheaacd_latmdemux.c index fb216f0..09c609d 100644 --- a/decoder/ixheaacd_latmdemux.c +++ b/decoder/ixheaacd_latmdemux.c @@ -147,7 +147,7 @@ static UWORD32 ixheaacd_latm_get_value(ia_bit_buf_struct *it_bit_buff) { if (bytes_read <= 3) return ixheaacd_read_bits_buf(it_bit_buff, 8 * bytes_read); else - return (ixheaacd_read_bits_buf(it_bit_buff, 24) << 24) + + return (ixheaacd_read_bits_buf(it_bit_buff, 24) << 8) + ixheaacd_read_bits_buf(it_bit_buff, 8); } @@ -203,9 +203,9 @@ IA_ERRORCODE ixheaacd_latm_stream_mux_config( : 0; pos = it_bit_buff->size - it_bit_buff->cnt_bits; - if (asc_len > it_bit_buff->size - 106 || asc_len > 2592) { - error_code = IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL; - return (error_code); + if (asc_len > it_bit_buff->size - 106 || asc_len > 2592 || + asc_len < 0) { + return IA_ENHAACPLUS_DEC_INIT_FATAL_DEC_INIT_FAIL; } if ((error_code = ixheaacd_ga_hdr_dec( @@ -269,6 +269,8 @@ IA_ERRORCODE ixheaacd_latm_stream_mux_config( latm_element->other_data_length <<= 8; latm_element->other_data_length += ixheaacd_read_bits_buf(it_bit_buff, 8); + if (latm_element->other_data_length > (UWORD32)it_bit_buff->cnt_bits) + return IA_FATAL_ERROR; } while (other_data_len); } } diff --git a/decoder/ixheaacd_longblock.c b/decoder/ixheaacd_longblock.c index 6f00ca8..7ac686b 100644 --- a/decoder/ixheaacd_longblock.c +++ b/decoder/ixheaacd_longblock.c @@ -113,10 +113,11 @@ WORD16 ixheaacd_read_section_data( sect_len_incr = 1; sect_len = (sect_len + sect_len_incr); - top = (sfb + sect_len); if (aac_spect_data_resil_flag) { - if (num_lines_sec_idx >= MAX_SFB_HCR) { + top = (sfb + sect_len); + if ((num_lines_sec_idx >= MAX_SFB_HCR) || + (top >= MAX_SCALE_FACTOR_BANDS_LONG)) { return -1; } ptr_num_sect_lines[num_lines_sec_idx] = @@ -173,23 +174,10 @@ VOID ixheaacd_read_scale_factor_data( UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next; WORD32 bit_pos = 7 - it_bit_buff->bit_pos; WORD32 read_word; - WORD32 diffbytes; - - diffbytes = it_bit_buff->ptr_bit_buf_end - ptr_read_next; - diffbytes++; - if (diffbytes >= 4) { - read_word = ixheaacd_aac_showbits_32(ptr_read_next); - diffbytes = 4; - ptr_read_next = it_bit_buff->ptr_read_next + 4; - } else { - WORD32 ii; - read_word = 0; - for (ii = 0; ii < diffbytes; ii++) { - read_word = (read_word << 8) | (*ptr_read_next); - ptr_read_next++; - } - read_word <<= ((4 - diffbytes) << 3); - } + WORD32 increment; + read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits, + &increment); + ptr_read_next += increment; ptr_code_book = ptr_aac_dec_channel_info->ptr_code_book; @@ -230,8 +218,9 @@ VOID ixheaacd_read_scale_factor_data( bit_pos += length; ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word, it_bit_buff->ptr_bit_buf_end); - while (bit_pos > 8) - ixheaacd_aac_read_byte(&ptr_read_next, &bit_pos, &read_word); + + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + it_bit_buff->ptr_bit_buf_end); norm_value = index - 60; } @@ -245,7 +234,8 @@ VOID ixheaacd_read_scale_factor_data( noise_start_value = temp; bit_pos += 9; - ixheaacd_aac_read_2bytes(&ptr_read_next, &bit_pos, &read_word); + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + it_bit_buff->ptr_bit_buf_end); norm_value = noise_start_value - 256; ptr_pns_info->pns_active = 1; @@ -302,7 +292,7 @@ VOID ixheaacd_read_scale_factor_data( } } - it_bit_buff->ptr_read_next = ptr_read_next - diffbytes; + it_bit_buff->ptr_read_next = ptr_read_next - increment; it_bit_buff->bit_pos = 7 - bit_pos; { diff --git a/decoder/ixheaacd_lpc.c b/decoder/ixheaacd_lpc.c index 70c514f..a1c9fb6 100644 --- a/decoder/ixheaacd_lpc.c +++ b/decoder/ixheaacd_lpc.c @@ -436,40 +436,22 @@ WORD32 ixheaacd_lpd_dec(ia_usac_data_struct *usac_data, 0, fac_length * sizeof(WORD32)); } - if (mod[0] == 0 && len_subfrm != LEN_FRAME) { - for (i = 0; i < 3 * len_subfrm; i++) - st->fd_synth[ORDER - len_subfrm + i] = (FLOAT32)( - (FLOAT32)usac_data - ->overlap_data_ptr[usac_data->present_chan][i - len_subfrm] / - 16384.0); - num_samples = min(3 * len_subfrm, MAX_PITCH + synth_delay); - } else { - for (i = 0; i < 2 * len_subfrm; i++) - st->fd_synth[ORDER + i] = (FLOAT32)( - (FLOAT32)usac_data->overlap_data_ptr[usac_data->present_chan][i] / - 16384.0); - num_samples = min(2 * len_subfrm, MAX_PITCH + synth_delay); - } + for (i = 0; i < 2 * len_subfrm; i++) + st->fd_synth[ORDER + i] = (FLOAT32)( + (FLOAT32)usac_data->overlap_data_ptr[usac_data->present_chan][i] / + 16384.0); + num_samples = min(2 * len_subfrm, MAX_PITCH + synth_delay); + ixheaacd_mem_cpy(st->fd_synth + ORDER, synth - 2 * len_subfrm, 2 * len_subfrm); - if (mod[0] == 0 && len_subfrm != LEN_FRAME) { - ixheaacd_preemphsis_tool_float(st->fd_synth + ORDER - len_subfrm, - PREEMPH_FILT_FAC, 3 * len_subfrm, mem); - } else { - ixheaacd_preemphsis_tool_float(st->fd_synth + ORDER, PREEMPH_FILT_FAC, - 2 * len_subfrm, mem); - } - if (mod[0] == 0 && len_subfrm != LEN_FRAME) { - ixheaacd_memset(tmp - len_subfrm, ORDER); - ixheaacd_mem_cpy(st->fd_synth + ORDER - len_subfrm, - tmp - len_subfrm + ORDER, 3 * len_subfrm); - tmp_start = -len_subfrm; - } else { - ixheaacd_memset(tmp, ORDER); - ixheaacd_mem_cpy(st->fd_synth + ORDER, tmp + ORDER, 2 * len_subfrm); - tmp_start = 0; - } + ixheaacd_preemphsis_tool_float(st->fd_synth + ORDER, PREEMPH_FILT_FAC, + 2 * len_subfrm, mem); + + ixheaacd_memset(tmp, ORDER); + ixheaacd_mem_cpy(st->fd_synth + ORDER, tmp + ORDER, 2 * len_subfrm); + tmp_start = 0; + ixheaacd_memset(ptr_tmp - len_subfrm, 3 * len_subfrm); memset(st->fd_synth, 0, ORDER * sizeof(WORD32)); length = (2 * len_subfrm - tmp_start) / LEN_SUBFR; @@ -480,8 +462,6 @@ WORD32 ixheaacd_lpd_dec(ia_usac_data_struct *usac_data, if (mod[0] != 0 && (len_subfrm == LEN_FRAME || mod[1] != 0)) { num_samples = min(len_subfrm, MAX_PITCH + INTER_LP_FIL_ORDER + 1); - } else if (mod[0] == 0 && len_subfrm != LEN_FRAME) { - num_samples = min(3 * len_subfrm, MAX_PITCH + INTER_LP_FIL_ORDER + 1); } else { num_samples = min(2 * len_subfrm, MAX_PITCH + INTER_LP_FIL_ORDER + 1); } @@ -592,6 +572,9 @@ WORD32 ixheaacd_lpd_dec(ia_usac_data_struct *usac_data, gain = pitch_gain[i]; if (gain > 0.0f) { synth_corr = 0.0f, synth_energy = 1e-6f; + if ((((i * LEN_SUBFR) + LEN_SUBFR) > LEN_SUPERFRAME) || + ((((i * LEN_SUBFR) + LEN_SUBFR) - tp) > LEN_SUPERFRAME)) + return -1; for (k = 0; k < LEN_SUBFR; k++) { synth_corr += synth[i * LEN_SUBFR + k] * synth[(i * LEN_SUBFR) - tp + k]; @@ -677,7 +660,6 @@ WORD32 ixheaacd_lpd_bpf_fix(ia_usac_data_struct *usac_data, fac_length = (usac_data->len_subfrm) / 2; ixheaacd_memset(synth_buf, MAX_PITCH + synth_delay + len_fr); - synth = synth_buf + MAX_PITCH + synth_delay; ixheaacd_mem_cpy(st->synth_prev, synth_buf, MAX_PITCH + synth_delay); ixheaacd_mem_cpy(out_buffer, synth_buf + MAX_PITCH - (LEN_SUBFR), synth_delay + len_fr + (LEN_SUBFR)); @@ -705,9 +687,12 @@ WORD32 ixheaacd_lpd_bpf_fix(ia_usac_data_struct *usac_data, tp = pitch[i]; if ((i * LEN_SUBFR + MAX_PITCH) < tp) { return -1; - } else if ((i * LEN_SUBFR + MAX_PITCH - tp) >= 1883) { + } else if (((i * LEN_SUBFR + MAX_PITCH - tp) >= 1883) || + (((i * LEN_SUBFR) + LEN_SUBFR) > LEN_SUPERFRAME) || + ((((i * LEN_SUBFR) + LEN_SUBFR) - tp) > LEN_SUPERFRAME)) { return -1; } + if (pitch_gain[i] > 0.0f) { synth_corr = 0.0f, synth_energy = 1e-6f; for (k = 0; k < LEN_SUBFR; k++) { diff --git a/decoder/ixheaacd_lpfuncs.c b/decoder/ixheaacd_lpfuncs.c index c42896e..5a83aac 100644 --- a/decoder/ixheaacd_lpfuncs.c +++ b/decoder/ixheaacd_lpfuncs.c @@ -98,7 +98,7 @@ static PLATFORM_INLINE WORD32 ixheaacd_shr32_drc(WORD32 a, WORD32 b) { else out_val = 0; } else { - a += (1 << (b - 1)); + a = ixheaacd_add32_sat(a, (1 << (b - 1))); out_val = (WORD32)a >> b; } @@ -163,10 +163,10 @@ VOID ixheaacd_process_win_seq(WORD32 *coef, WORD32 *prev, WORD16 *out, out[ch_fac * i] = ixheaacd_round16(accu << 2); - accu = (ixheaacd_shl32_dir_sat_limit(-(coef[SIZE15 - 1 - i]), - (q_shift - 1)) - - ixheaacd_mult32x16in32_drc(prev[i + SIZE01], - window_long[2 * SIZE07 - 2 - 2 * i])); + accu = ixheaacd_sub32_sat( + ixheaacd_shl32_dir_sat_limit(-(coef[SIZE15 - 1 - i]), (q_shift - 1)), + ixheaacd_mult32x16in32_drc(prev[i + SIZE01], + window_long[2 * SIZE07 - 2 - 2 * i])); out[ch_fac * (SIZE09 + i)] = ixheaacd_round16(accu << 2); } @@ -186,9 +186,10 @@ VOID ixheaacd_process_win_seq(WORD32 *coef, WORD32 *prev, WORD16 *out, WORD32 prev1 = *temp_prev--; WORD16 win4 = *temp_win_sh++; WORD16 win3 = *temp_win_sh++; - accu = ixheaacd_shl32_dir_sat_limit(ixheaacd_mult32x16in32(temp_coef, win1), - q_shift) - - ixheaacd_mult32x16in32_drc(prev1, win3); + accu = ixheaacd_sub32_sat( + ixheaacd_shl32_dir_sat_limit(ixheaacd_mult32x16in32(temp_coef, win1), + q_shift), + ixheaacd_mult32x16in32_drc(prev1, win3)); *out1 = ixheaacd_round16(accu << 2); out1 += ch_fac; @@ -217,21 +218,21 @@ static PLATFORM_INLINE VOID ixheaacd_long_short_win_process( WORD32 tmp2_cur = *current_tmp2++; WORD16 short1 = *short_ptr--; WORD16 short2 = *short_ptr--; - accu = - (ixheaacd_shl32_dir_sat_limit( - (ixheaacd_mult32x16in32(tmp1_cur, short2) - - ixheaacd_mult32x16in32(tmp2_cur, short1)), - q_shift) - - ixheaacd_mult32x16in32_drc(prev[i], long_window_prev[0 - 2 - 2 * i])); + accu = ixheaacd_sub32_sat( + ixheaacd_shl32_dir_sat_limit((ixheaacd_mult32x16in32(tmp1_cur, short2) - + ixheaacd_mult32x16in32(tmp2_cur, short1)), + q_shift), + ixheaacd_mult32x16in32_drc(prev[i], long_window_prev[0 - 2 - 2 * i])); out[ch_fac * (0 + i)] = ixheaacd_round16(accu << 2); if (flag) { - accu = (ixheaacd_shl32_dir_sat_limit( - (ixheaacd_mult32x16in32(-(tmp1_cur), short1) - - ixheaacd_mult32x16in32(tmp2_cur, short2)), - q_shift) - - ixheaacd_mult32x16in32_drc( - prev[SIZE02 - 1 - i], long_window_prev[-2 * SIZE02 + 2 * i])); + accu = ixheaacd_sub32_sat( + ixheaacd_shl32_dir_sat_limit( + (ixheaacd_mult32x16in32(-(tmp1_cur), short1) - + ixheaacd_mult32x16in32(tmp2_cur, short2)), + q_shift), + ixheaacd_mult32x16in32_drc(prev[SIZE02 - 1 - i], + long_window_prev[-2 * SIZE02 + 2 * i])); out[ch_fac * (SIZE02 - 1 - i)] = ixheaacd_round16(accu << 2); } } @@ -251,23 +252,24 @@ VOID ixheaacd_long_short_win_seq(WORD32 *current, WORD32 *prev, WORD16 *out, } for (i = 0; i < SIZE01; i++) { - accu = - (ixheaacd_shl32_dir_sat_limit( - ixheaacd_mult32x16in32(current[SIZE01 + i], - short_window_prev[2 * i]), - q_shift) - - ixheaacd_mult32x16in32_drc(prev[SIZE01 - 1 - i], - long_window_prev[2 * SIZE07 + 1 + 2 * i])); + accu = ixheaacd_sub32_sat( + ixheaacd_shl32_dir_sat_limit( + ixheaacd_mult32x16in32(current[SIZE01 + i], + short_window_prev[2 * i]), + q_shift), + ixheaacd_mult32x16in32_drc(prev[SIZE01 - 1 - i], + long_window_prev[2 * SIZE07 + 1 + 2 * i])); out[ch_fac * (SIZE07 + i)] = ixheaacd_round16(accu << 2); } for (i = 0; i < SIZE01; i++) { - accu = (ixheaacd_shl32_dir_sat_limit( - ixheaacd_mult32x16in32(-(current[SIZE02 - 1 - i]), - short_window_prev[SIZE02 - 2 * i - 1]), - q_shift) - - ixheaacd_mult32x16in32_drc(prev[i], - long_window_prev[SIZE16 - 2 - (2 * i)])); + accu = ixheaacd_sub32_sat( + ixheaacd_shl32_dir_sat_limit( + ixheaacd_mult32x16in32(-(current[SIZE02 - 1 - i]), + short_window_prev[SIZE02 - 2 * i - 1]), + q_shift), + ixheaacd_mult32x16in32_drc(prev[i], + long_window_prev[SIZE16 - 2 - (2 * i)])); out[ch_fac * (SIZE08 + i)] = ixheaacd_round16(accu << 2); } diff --git a/decoder/ixheaacd_lt_predict.c b/decoder/ixheaacd_lt_predict.c index 4e004f5..8d00bc8 100644 --- a/decoder/ixheaacd_lt_predict.c +++ b/decoder/ixheaacd_lt_predict.c @@ -74,7 +74,7 @@ VOID ixheaacd_lt_prediction( for (i = 0; i < num_samples; i++) { in_data[i] = - ixheaacd_shr32(ixheaacd_mult32x16in32_shl( + ixheaacd_shr32(ixheaacd_mult32x16in32_shl_sat( ixheaacd_codebook_Q30[ltp->coef], lt_pred_stat[num_samples + i - ltp->lag]), SHIFT_VAL); @@ -93,8 +93,8 @@ VOID ixheaacd_lt_prediction( if (ltp->long_used[sfb]) { for (bin = sfb_width - 1; bin >= 0; bin--) { WORD32 temp = *ptr_spec; - temp += ixheaacd_shr32(*ptr_x_est++, SHIFT_VAL1); - + temp = ixheaacd_add32_sat(temp, + ixheaacd_shr32(*ptr_x_est++, SHIFT_VAL1)); *ptr_spec++ = temp; } } else { diff --git a/decoder/ixheaacd_lt_predict.h b/decoder/ixheaacd_lt_predict.h index 4aa69e0..8e4fbfc 100644 --- a/decoder/ixheaacd_lt_predict.h +++ b/decoder/ixheaacd_lt_predict.h @@ -23,6 +23,12 @@ #define MAX_SFB 51 #define MAX_LTP_SFB 40 +#define MAX_LTP_SFB_SR_FIVE_PLUS_480 31 +#define MAX_LTP_SFB_SR_FIVE_480 38 +#define MAX_LTP_SFB_SR_FIVE_LESS_480 36 +#define MAX_LTP_SFB_SR_FIVE_PLUS_512 32 +#define MAX_LTP_SFB_SR_FIVE_512 38 +#define MAX_LTP_SFB_SR_FIVE_LESS_512 37 enum { ltp_buffer_size = (4 * 1024) }; diff --git a/decoder/ixheaacd_main.h b/decoder/ixheaacd_main.h index 55b8eb3..fe6355b 100644 --- a/decoder/ixheaacd_main.h +++ b/decoder/ixheaacd_main.h @@ -180,9 +180,10 @@ typedef struct ia_usac_data_main_struct { } ia_usac_data_struct; -VOID ixheaacd_tns_apply(ia_usac_data_struct *usac_data, WORD32 *spec, - WORD32 nbands, ia_sfb_info_struct *pstr_sfb_info, - ia_tns_frame_info_struct *pstr_tns); +IA_ERRORCODE ixheaacd_tns_apply(ia_usac_data_struct *usac_data, WORD32 *spec, + WORD32 nbands, + ia_sfb_info_struct *pstr_sfb_info, + ia_tns_frame_info_struct *pstr_tns); WORD32 ixheaacd_calc_max_spectral_line_dec(WORD32 *ptr_tmp, WORD32 size); diff --git a/decoder/ixheaacd_mps_parse.c b/decoder/ixheaacd_mps_parse.c index a2492bd..7f45d3f 100644 --- a/decoder/ixheaacd_mps_parse.c +++ b/decoder/ixheaacd_mps_parse.c @@ -243,8 +243,7 @@ static int ixheaacd_mps_getstridemap(int freq_res_stride, int band_start, static VOID ixheaacd_mps_ecdata_decoding( ia_mps_dec_state_struct *self, ia_handle_bit_buf_struct bitstream, int data[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS], int datatype) { - int i, j, pb, data_set, set_index, bs_data_pair, data_bands, - old_quant_coarse_xxx; + int i, j, pb, set_index, bs_data_pair, data_bands, old_quant_coarse_xxx; int strides[MAX_PARAMETER_BANDS + 1] = {0}; int band_stop = 0; @@ -272,13 +271,8 @@ static VOID ixheaacd_mps_ecdata_decoding( band_stop = self->bs_param_bands; } - data_set = 0; for (i = 0; i < self->num_parameter_sets; i++) { frame_xxx_data->bs_xxx_data_mode[i] = ixheaacd_read_bits_buf(bitstream, 2); - - if (frame_xxx_data->bs_xxx_data_mode[i] == 3) { - data_set++; - } } set_index = 0; @@ -674,7 +668,6 @@ static float ixheaacd_mps_de_quantize(int value, int param_type) { return ixheaacd_icc_de_quant_table[value]; case IPD: - assert((value % 16) < 16); return ixheaacd_ipd_de_quant_table[(value & 15)]; default: @@ -689,7 +682,7 @@ static WORD32 ixheaacd_mps_mapindexdata( int out_idx_data[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS], int cmp_idx_data[MAX_PARAMETER_SETS_MPS][MAX_PARAMETER_BANDS], int idx_prev[MAX_PARAMETER_BANDS], int param_type) { - int interpolate_local[MAX_PARAMETER_SETS_MPS]; + int interpolate_local[MAX_PARAMETER_SETS_MPS] = {0}; int map[MAX_PARAMETER_BANDS + 1]; int set_index, i, band, parm_slot; @@ -990,7 +983,7 @@ WORD32 ixheaacd_mps_frame_decode(ia_mps_dec_state_struct *self) { } WORD32 ixheaacd_mps_header_decode(ia_mps_dec_state_struct *self) { - self->time_slots = self->frame_length + 1; + self->time_slots = self->frame_length; self->frame_len = self->time_slots * self->qmf_band_count; self->bs_param_bands = ixheaacd_freq_res_table[self->config->bs_freq_res]; diff --git a/decoder/ixheaacd_mps_pre_mix.c b/decoder/ixheaacd_mps_pre_mix.c index 4aaf803..36426cf 100644 --- a/decoder/ixheaacd_mps_pre_mix.c +++ b/decoder/ixheaacd_mps_pre_mix.c @@ -55,8 +55,8 @@ extern const WORD32 ixheaacd_re_weight_Q28[16][8][31]; extern const WORD32 ixheaacd_beta_Q28[16][8][31]; extern const WORD32 ixheaacd_weight_Q28[16][8][31]; extern const WORD32 ixheaacd_c_l_table_Q31[31]; -extern const WORD32 ixheaacd_sin_table_Q31[16][31]; -extern const WORD32 ixheaacd_cos_table_Q31[16][31]; +extern const WORD32 ixheaacd_sin_table_Q31[8][31]; +extern const WORD32 ixheaacd_cos_table_Q31[8][31]; extern const WORD32 ixheaacd_atan_table_Q28[16][8][31]; extern WORD32 ixheaacd_ipd_de_quant_table_q28[16]; @@ -201,6 +201,8 @@ static VOID ixheaacd_mps_par2umx_ps_core(WORD32 cld[MAX_PARAMETER_BANDS], cld_idx = *cld++ + 15; icc_idx = *icc++; + icc_idx = icc_idx & 7; + c_l_temp = (ixheaacd_c_l_table_Q31[cld_idx]); c_r_temp = (ixheaacd_c_l_table_Q31[30 - cld_idx]); diff --git a/decoder/ixheaacd_mps_rom.c b/decoder/ixheaacd_mps_rom.c index 680d62a..858f7f3 100644 --- a/decoder/ixheaacd_mps_rom.c +++ b/decoder/ixheaacd_mps_rom.c @@ -4554,7 +4554,7 @@ const WORD32 ixheaacd_c_l_table_Q31[31] = { 2140740687, 2144096210, 2146410711, 2147144182, 2147376282, 2147449694, 2147483647}; -const WORD32 ixheaacd_sin_table_Q31[16][31] = { +const WORD32 ixheaacd_sin_table_Q31[8][31] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {750179061, 746245580, 743210706, 737870331, 728548620, 712505595, @@ -4598,59 +4598,9 @@ const WORD32 ixheaacd_sin_table_Q31[16][31] = { 595446097, 785304289, 1255861595, 2142108211, 997566324, 495493509, 298429982, 198205829, 139164109, 87059272, 56928133, 38231805, 26115252, 18039235, 9889297, 5483639, 3059686, 1713093, - 10}, - {329205034, 331044496, 332490231, 335092198, 339819934, 348560631, - 357215536, 370188297, 390176357, 422312259, 477650750, 539980675, - 644803507, 846880778, 1332052144, 2141128430, 1058086628, 534345646, - 323167286, 214970179, 151046430, 94543938, 61838785, 41535810, - 28374639, 19601005, 10746050, 5958876, 3324902, 1861600, - 10}, - {1497748045, 1503796643, 1508521727, 1516961790, 1532087179, 1559339680, - 1585420057, 1622844547, 1676673047, 1753885899, 1862379403, 1953397438, - 2051811629, 2131459107, 2134283647, 1989548276, 1695321762, 1344859778, - 1028341794, 777661527, 588936078, 392646144, 265734770, 182086153, - 125934391, 87688114, 48448851, 26975819, 15085217, 8456470, - 47}, - {1819124703, 1824556610, 1828777565, 1836267987, 1849532387, 1872907535, - 1894631673, 1924668687, 1965428606, 2018548171, 2081362225, 2121366279, - 2146115448, 2132815850, 2050987089, 1879164766, 1629156954, 1345715825, - 1075605664, 844531127, 658184527, 451896646, 311499442, 215951378, - 150495943, 105321331, 58487349, 32653976, 18287776, 10260236, - 58}, - {1923585203, 1928381715, 1932097038, 1938664124, 1950209521, 1970281404, - 1988600282, 2013343744, 2045676827, 2085120607, 2125770747, 2144599223, - 2143208195, 2102454500, 2000402838, 1825095804, 1588976455, 1326559108, - 1074148586, 853780328, 672227734, 466800358, 324217928, 225900884, - 157960135, 110797066, 61671040, 34474865, 19320970, 10844087, - 61}, - {1985155606, 1989395440, 1992670162, 1998437861, 2008511637, 2025809362, - 2041332134, 2061836802, 2087645355, 2116966052, 2142166480, 2147133001, - 2129677751, 2073262009, 1960755061, 1784738505, 1557483106, 1308139892, - 1067367301, 854789044, 677412520, 473929665, 330869491, 231341894, - 162148775, 113919632, 63514715, 35537809, 19926702, 11187193, - 63}, - {2020686784, 2024512419, 2027460265, 2032636996, 2041629534, 2056910757, - 2070427091, 2087934395, 2109221115, 2131716042, 2146880706, 2143192060, - 2116099812, 2050733580, 1932676750, 1756826697, 1535179711, 1293925414, - 1060562211, 853220127, 678903290, 477231777, 334289019, 234270092, - 164459870, 115668592, 64561995, 36145965, 20274603, 11384670, - 64}, - {2039090402, 2042664488, 2045414146, 2050233276, 2058573831, 2072646538, - 2084969290, 2100708700, 2119359676, 2137940103, 2147475978, 2139046746, - 2106802112, 2036793002, 1916001986, 1740449052, 1521934475, 1285129504, - 1055902322, 851569848, 679091531, 478625170, 335895872, 235703393, - 165614998, 116553480, 65097820, 36458876, 20454141, 11486747, - 64}, - {2044775589, 2048265671, 2050949194, 2055649103, 2063772641, 2077444225, - 2089372175, 2104529140, 2122316535, 2139624159, 2147348884, 2137411299, - 2103545985, 2032097722, 1910481747, 1735055157, 1517549594, 1282166983, - 1054270393, 850918765, 679051340, 479002183, 336364503, 236132053, - 165964731, 116823274, 65262221, 36555185, 20509492, 11518244, - 65} + 10}}; -}; - -const WORD32 ixheaacd_cos_table_Q31[16][31] = { +const WORD32 ixheaacd_cos_table_Q31[8][31] = { {2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, @@ -4700,57 +4650,6 @@ const WORD32 ixheaacd_cos_table_Q31[16][31] = { 151850025, 1901722232, 2089538753, 2126646554, 2138317205, 2142969755, 2145718225, 2146728955, 2147143299, 2147324850, 2147407880, 2147460877, 2147476647, 2147481468, 2147482965, - 2147483647}, - {-2122100390, -2121814214, -2121588147, -2121178738, -2120426474, - -2119007198, -2117565366, -2115336059, -2111740616, -2105549423, - -2093689514, -2078486682, -2048393140, -1973443429, -1684435545, - 165091079, 1868726493, 2079942487, 2123028244, 2136696946, - 2142165025, 2145401469, 2146593111, 2147081926, 2147296183, - 2147394193, 2147456761, 2147475381, 2147481074, 2147482841, - 2147483647}, - {-1538972648, -1533062841, -1528413627, -1520037153, -1504790648, - -1476531673, -1448492065, -1406435777, -1341809789, -1239181290, - -1069218864, -892145989, -633841507, -261855100, 237737945, - 808321517, 1318169239, 1674227642, 1885258383, 2001731392, - 2065148981, 2111282791, 2130978895, 2139750138, 2143787897, - 2145692618, 2146937057, 2147314212, 2147430664, 2147466998, - 2147483647}, - {-1141258661, -1132554280, -1125725826, -1113465715, -1091290965, - -1050668066, -1010968269, -952542107, -865318678, -732904701, - -528788529, -333902874, -76645308, 250564500, 636504499, - 1039435328, 1399118879, 1673539643, 1858698059, 1974450099, - 2044132860, 2099398828, 2124771544, 2136598002, 2142203769, - 2144899400, 2146687040, 2147235370, 2147405778, 2147459137, - 2147483647}, - {-954728226, -945002634, -937383089, -923724761, -899093346, -854211454, - -810650934, -747082986, -653369987, -513768503, -304605894, -111266315, - 135442430, 437459820, 781072662, 1131685170, 1444589853, 1688764919, - 1859540490, 1970468261, 2039557769, 2096135359, 2122868049, 2135568966, - 2141666317, 2144623517, 2146597937, 2147206907, 2147396731, 2147456268, - 2147483647}, - {-819050205, -808697596, -800594558, -786086595, -759978305, -712588553, - -666820168, -600429030, -503411252, -360750262, -151025800, 38805847, - 275968648, 559705870, 875857071, 1194317582, 1478489903, 1703072530, - 1863441189, 1970030890, 2037841578, 2094534958, 2121841511, 2134986404, - 2141353262, 2144459917, 2146544176, 2147189578, 2147391195, 2147454508, - 2147483647}, - {-726987579, -716264954, -707877738, -692872903, -665909053, -617093312, - -570103217, -502211092, -403574415, -259755142, -50884692, 135697496, - 365797219, 637320800, 936187267, 1235008492, 1501635533, 1713897034, - 1867322633, 1970710895, 2037345415, 2093785053, 2121305464, 2134667080, - 2141177006, 2144366292, 2146512932, 2147179426, 2147387939, 2147453470, - 2147483647}, - {-673644084, -662727550, -654191860, -638928424, -611522528, -561980736, - -514382230, -445767850, -346411003, -202232874, 5739490, 190171073, - 416017882, 680558805, 969856901, 1257983750, 1515058240, 1720502304, - 1869961578, 1971424564, 2037282678, 2093466973, 2121051622, 2134509295, - 2141087969, 2144318378, 2146496749, 2147174136, 2147386236, 2147452927, - 2147483647}, - {-656185042, -645208306, -636626596, -621283175, -593741108, -543977491, - -496195458, -427367659, -327808702, -183560558, 24058044, 207747337, - 432180873, 694452925, 980686245, 1265412826, 1519450311, 1722711191, - 1870882133, 1971705676, 2037296075, 2093380741, 2120977355, 2134461916, - 2141060888, 2144303696, 2146491757, 2147172498, 2147385708, 2147452758, 2147483647}}; const WORD32 diff --git a/decoder/ixheaacd_multichannel.c b/decoder/ixheaacd_multichannel.c index 008a98f..ae20586 100644 --- a/decoder/ixheaacd_multichannel.c +++ b/decoder/ixheaacd_multichannel.c @@ -129,7 +129,7 @@ WORD cblock_decode_huff_symbol(UWORD8 *ptr_read_next, WORD32 bit_pos, return tot_bits; } -WORD16 ixheaacd_dec_coupling_channel_element( +IA_ERRORCODE ixheaacd_dec_coupling_channel_element( ia_handle_bit_buf_struct bs, ia_aac_decoder_struct *aac_handle, WORD32 samp_rate_idx, ia_aac_dec_tables_struct *ptr_aac_tables, ixheaacd_misc_tables *common_tables_ptr, WORD *element_index_order, @@ -152,7 +152,7 @@ WORD16 ixheaacd_dec_coupling_channel_element( ptr_aac_tables->pstr_huffmann_tables->huffman_code_book_scl_index; WORD16 index, length; - WORD16 error_status = AAC_DEC_OK; + IA_ERRORCODE error_status = IA_NO_ERROR; element_instance_tag = ixheaacd_read_bits_buf(bs, 4); element_index_order[0] = element_instance_tag; @@ -179,7 +179,9 @@ WORD16 ixheaacd_dec_coupling_channel_element( } else ind_channel_info->elements_coupled[c] = 0; } - + if ((ind_sw_cce_flag == 0) && (num_gain_element_lists > MAX_BS_ELEMENT)) { + return IA_FATAL_ERROR; + } cc_domain = ixheaacd_read_bits_buf(bs, 1); gain_element_sign = ixheaacd_read_bits_buf(bs, 1); gain_element_scale = ixheaacd_read_bits_buf(bs, 2); @@ -207,13 +209,13 @@ WORD16 ixheaacd_dec_coupling_channel_element( else { common_gain_element_present[c] = ixheaacd_read_bits_buf(bs, 1); cge = common_gain_element_present[c]; - error_status = - (WORD)((WORD32)IA_ENHAACPLUS_DEC_EXE_FATAL_UNIMPLEMENTED_CCE); + return IA_ENHAACPLUS_DEC_EXE_FATAL_UNIMPLEMENTED_CCE; } if (cge) { UWORD8 *ptr_read_next = bs->ptr_read_next; WORD32 bit_pos = 7 - bs->bit_pos; - WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next); + WORD32 read_word = + ixheaacd_aac_showbits_32(bs->ptr_read_next, bs->cnt_bits, NULL); UWORD32 read_word1; read_word1 = read_word << bit_pos; @@ -238,18 +240,17 @@ WORD16 ixheaacd_dec_coupling_channel_element( ind_channel_info->cc_gain[c] = common_tables_ptr->cc_gain_scale[gain_element_scale]; for (i = 0; i < (-norm_value) - 1; i++) { - ind_channel_info->cc_gain[c] *= - common_tables_ptr->cc_gain_scale[gain_element_scale]; + ind_channel_info->cc_gain[c] = ixheaacd_mul32_sh( + ind_channel_info->cc_gain[c], + common_tables_ptr->cc_gain_scale[gain_element_scale], 29); } } } else { - error_status = - (WORD)((WORD32)IA_ENHAACPLUS_DEC_EXE_FATAL_UNIMPLEMENTED_CCE); + return IA_ENHAACPLUS_DEC_EXE_FATAL_UNIMPLEMENTED_CCE; } } if (bs->cnt_bits < 0) { - error_status = (WORD16)( - (WORD32)IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + return IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES; } return error_status; } diff --git a/decoder/ixheaacd_multichannel.h b/decoder/ixheaacd_multichannel.h index 2f280c7..9156f44 100644 --- a/decoder/ixheaacd_multichannel.h +++ b/decoder/ixheaacd_multichannel.h @@ -20,7 +20,7 @@ #ifndef IA_EAACP_DEC_MUTLCHANNEL_H #define IA_EAACP_DEC_MUTLCHANNEL_H -WORD16 ixheaacd_dec_coupling_channel_element( +IA_ERRORCODE ixheaacd_dec_coupling_channel_element( ia_handle_bit_buf_struct bs, ia_aac_decoder_struct *aac_handle, WORD32 sample_rate_idx, ia_aac_dec_tables_struct *ptr_aac_tables, ixheaacd_misc_tables *common_tables_ptr, WORD *element_index_order, diff --git a/decoder/ixheaacd_process.c b/decoder/ixheaacd_process.c index 2347834..d9e7175 100644 --- a/decoder/ixheaacd_process.c +++ b/decoder/ixheaacd_process.c @@ -97,7 +97,7 @@ VOID ixheaacd_allocate_sbr_scr(ia_sbr_scr_struct *sbr_scratch_struct, WORD total_elements, WORD ch_fac, WORD32 object_type); -WORD16 ixheaacd_applysbr( +IA_ERRORCODE ixheaacd_applysbr( ia_handle_sbr_dec_inst_struct self, ia_aac_dec_sbr_bitstream_struct *p_sbr_bit_stream, WORD16 *core_sample_buf, WORD16 *codec_num_channels, FLAG frame_status, FLAG down_samp_flag, @@ -105,11 +105,12 @@ WORD16 ixheaacd_applysbr( WORD32 ch_fac, WORD32 slot_element, ia_bit_buf_struct *it_bit_buff, ia_drc_dec_struct *pstr_drc_dec, WORD eld_sbr_flag, WORD32 object_type); -WORD16 ixheaacd_esbr_process(ia_usac_data_struct *usac_data, - ia_bit_buf_struct *it_bit_buff, - WORD32 stereo_config_idx, WORD16 num_channels, - WORD32 audio_object_type) { - WORD16 err_code = 0; +IA_ERRORCODE ixheaacd_esbr_process(ia_usac_data_struct *usac_data, + ia_bit_buf_struct *it_bit_buff, + WORD32 stereo_config_idx, + WORD16 num_channels, + WORD32 audio_object_type) { + WORD32 err_code = 0; ia_aac_dec_sbr_bitstream_struct *esbr_bit_str = &usac_data->esbr_bit_str[0]; ia_handle_sbr_dec_inst_struct self = usac_data->pstr_esbr_dec; @@ -203,10 +204,14 @@ static WORD32 ixheaacd_read_ext_element( } pstr_usac_dec_config->usac_ext_gain_payload_len += pay_load_length; } else { + if (it_bit_buff->cnt_bits < (WORD32)(pay_load_length << 3)) { + longjmp(*(it_bit_buff->xaac_jmp_buf), + IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES); + } it_bit_buff->ptr_read_next = it_bit_buff->ptr_read_next + pay_load_length; it_bit_buff->cnt_bits = - it_bit_buff->cnt_bits - (WORD32)(pay_load_length * 8); + it_bit_buff->cnt_bits - (WORD32)(pay_load_length << 3); } } } @@ -287,6 +292,7 @@ WORD32 ixheaacd_usac_process(ia_dec_data_struct *pstr_dec_data, WORD32 ch_offset = 0; WORD32 elem_idx = 0; + WORD32 num_ch_out = 0; WORD32 num_elements = pstr_usac_dec_config->num_elements; pstr_usac_dec_config->usac_ext_gain_payload_len = 0; @@ -304,21 +310,25 @@ WORD32 ixheaacd_usac_process(ia_dec_data_struct *pstr_dec_data, switch (ele_id = pstr_usac_dec_config->usac_element_type[elem_idx]) { case ID_USAC_SCE: nr_core_coder_channels = 1; + num_ch_out += 1; goto core_data_extracting; case ID_USAC_CPE: nr_core_coder_channels = (stereo_config_index == 1) ? 1 : 2; - if ((stereo_config_index > 1) && + if (((stereo_config_index > 1) || (stereo_config_index == 0)) && (p_state_aac_dec->num_of_output_ch < 2)) return -1; + num_ch_out += 2; goto core_data_extracting; case ID_USAC_LFE: nr_core_coder_channels = 1; + num_ch_out += 1; core_data_extracting: if (ch_offset >= MAX_NUM_CHANNELS_USAC_LVL2) return -1; + if (num_ch_out > MAX_NUM_CHANNELS_USAC_LVL2) return -1; err = ixheaacd_core_coder_data(ele_id, pstr_usac_data, elem_idx, - &ch_offset, it_bit_buff, + ch_offset, it_bit_buff, nr_core_coder_channels); if (err != 0) return -1; @@ -370,6 +380,13 @@ WORD32 ixheaacd_usac_process(ia_dec_data_struct *pstr_dec_data, (VOID *)(pstr_usac_data->pstr_esbr_dec->frame_buffer[ch]); } if (nr_core_coder_channels == 1) { + if (p_state_aac_dec->mps_dec_handle.res_ch_count != 0) { + ptr_inp[2] = pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1] + ->str_sbr_dec.pp_qmf_buf_real; + ptr_inp[2 + 1] = + pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1] + ->str_sbr_dec.pp_qmf_buf_imag; + } p_state_aac_dec->mps_dec_handle.p_sbr_dec[1] = (VOID *)(&pstr_usac_data->pstr_esbr_dec->pstr_sbr_channel[1] ->str_sbr_dec); diff --git a/decoder/ixheaacd_qmf_dec.c b/decoder/ixheaacd_qmf_dec.c index ffc0c84..8833289 100644 --- a/decoder/ixheaacd_qmf_dec.c +++ b/decoder/ixheaacd_qmf_dec.c @@ -133,11 +133,11 @@ VOID ixheaacd_fftposttw(WORD32 *out, temp[3] = *ptr_out_rev--; temp[2] = *ptr_out_rev++; - in2 = temp[3] - temp[1]; - in1 = temp[3] + temp[1]; + in2 = ixheaacd_sub32_sat(temp[3], temp[1]); + in1 = ixheaacd_add32_sat(temp[3], temp[1]); - temp[1] = temp[0] - temp[2]; - temp[3] = temp[0] + temp[2]; + temp[1] = ixheaacd_sub32_sat(temp[0], temp[2]); + temp[3] = ixheaacd_add32_sat(temp[0], temp[2]); twid_re = *twidle_fwd++; twid_im = *twidle_rev--; @@ -148,11 +148,11 @@ VOID ixheaacd_fftposttw(WORD32 *out, val1 = val1 << 1; val2 = val2 << 1; - *p_out_fwd++ = temp[3] + val1; - *p_out_fwd++ = in2 + val2; + *p_out_fwd++ = ixheaacd_add32_sat(temp[3], val1); + *p_out_fwd++ = ixheaacd_add32_sat(in2, val2); - *ptr_out_rev-- = -in2 + val2; - *ptr_out_rev-- = temp[3] - val1; + *ptr_out_rev-- = ixheaacd_sub32_sat(val2, in2); + *ptr_out_rev-- = ixheaacd_sub32_sat(temp[3], val1); } return; @@ -172,12 +172,13 @@ VOID ixheaacd_posttwdct2(WORD32 *inp, WORD16 *out_fwd, out_fwd2 = out_fwd + 65; out_re = *inp++; out_im = *inp++; - out_re1 = (out_re + out_im) >> 1; + out_re1 = + ixheaacd_sat64_32(ixheaacd_add64((WORD64)out_re, (WORD64)out_im) >> 1); re1 = ixheaacd_round16(ixheaacd_shl32(out_re1, (5 - 1))); *out_fwd++ = re1; - last_val = (out_re - out_im); + last_val = ixheaacd_sub32_sat(out_re, out_im); twidle_fwd = qmf_dec_tables_ptr->dct23_tw + 2; for (k = DCT2_LEN / 2 - 2; k >= 0; k--) { @@ -186,10 +187,10 @@ VOID ixheaacd_posttwdct2(WORD32 *inp, WORD16 *out_fwd, twid_re = *twidle_fwd++; twid_im = *twidle_fwd++; - out_re = ixheaacd_sub32(ixheaacd_mult32x16in32(inp_re, twid_re), - ixheaacd_mult32x16in32(inp_im, twid_im)); - out_im = ixheaacd_add32(ixheaacd_mult32x16in32(inp_im, twid_re), - ixheaacd_mult32x16in32(inp_re, twid_im)); + out_re = ixheaacd_sub32_sat(ixheaacd_mult32x16in32(inp_re, twid_re), + ixheaacd_mult32x16in32(inp_im, twid_im)); + out_im = ixheaacd_add32_sat(ixheaacd_mult32x16in32(inp_im, twid_re), + ixheaacd_mult32x16in32(inp_re, twid_im)); re1 = ixheaacd_round16(ixheaacd_shl32(out_re, (5 - 1))); im1 = ixheaacd_round16(ixheaacd_shl32(out_im, (5 - 1))); im2 = ixheaacd_negate16(im1); @@ -238,11 +239,11 @@ static PLATFORM_INLINE VOID ixheaacd_fftposttw_32( temp3 = *ptr_out_rev--; temp2 = *ptr_out_rev++; - in1 = temp1 + temp3; - in2 = -temp1 + temp3; + in1 = ixheaacd_add32_sat(temp1, temp3); + in2 = ixheaacd_sub32_sat(temp3, temp1); - temp1 = temp0 - temp2; - temp3 = temp0 + temp2; + temp1 = ixheaacd_sub32_sat(temp0, temp2); + temp3 = ixheaacd_add32_sat(temp0, temp2); twid_re = *twidle_fwd; twidle_fwd += 2; @@ -258,11 +259,11 @@ static PLATFORM_INLINE VOID ixheaacd_fftposttw_32( val1 = val1 << 1; val2 = val2 << 1; - *ptr_out_fwd++ = temp3 + val1; - *ptr_out_fwd++ = in2 + val2; + *ptr_out_fwd++ = ixheaacd_add32_sat(temp3, val1); + *ptr_out_fwd++ = ixheaacd_add32_sat(in2, val2); - *ptr_out_rev-- = -in2 + val2; - *ptr_out_rev-- = temp3 - val1; + *ptr_out_rev-- = ixheaacd_sub32_sat(val2, in2); + *ptr_out_rev-- = ixheaacd_sub32_sat(temp3, val1); } return; @@ -287,10 +288,11 @@ ixheaacd_posttwdct2_32(WORD32 *inp, WORD16 *out_fwd, out_re = *inp++; out_im = *inp++; - out_re1 = (out_re + out_im) >> 1; + out_re1 = + ixheaacd_sat64_32(ixheaacd_add64((WORD64)out_re, (WORD64)out_im) >> 1); re1 = ixheaacd_round16(ixheaacd_shl32_sat(out_re1, (5 - 1))); *out_fwd++ = re1; - last_val = (out_re - out_im); + last_val = ixheaacd_sub32_sat(out_re, out_im); twidle_fwd = qmf_dec_tables_ptr->dct23_tw + 4; for (k = 14; k >= 0; k--) { @@ -305,8 +307,8 @@ ixheaacd_posttwdct2_32(WORD32 *inp, WORD16 *out_fwd, inp_re = *inp++; - out_re = ixheaacd_sub32(temp1, ixheaacd_mult32x16in32(inp_re, twid_im)); - out_im = ixheaacd_add32(ixheaacd_mult32x16in32(inp_re, twid_re), temp2); + out_re = ixheaacd_sub32_sat(temp1, ixheaacd_mult32x16in32(inp_re, twid_im)); + out_im = ixheaacd_add32_sat(ixheaacd_mult32x16in32(inp_re, twid_re), temp2); out_re = ixheaacd_add32_sat(out_re, out_re); out_im = ixheaacd_add32_sat(out_im, out_im); diff --git a/decoder/ixheaacd_rev_vlc.c b/decoder/ixheaacd_rev_vlc.c index 12b16b1..5c51f64 100644 --- a/decoder/ixheaacd_rev_vlc.c +++ b/decoder/ixheaacd_rev_vlc.c @@ -99,6 +99,11 @@ #define LEFT_OFFSET 12 +#define ixheaacd_bitbuf_checkpoint(it_bit_buf, saved_bit_buf) \ + (saved_bit_buf) = (it_bit_buf) +#define ixheaacd_bitbuf_restore(it_bit_buf, saved_bit_buf) \ + (it_bit_buf) = (saved_bit_buf) + static int ixheaacd_rvlc_decode(short cw, int len, int *found) { short indx = 0; *found = 0; @@ -526,7 +531,7 @@ static VOID ixheaacd_rvlc_decode_forward( WORD16 dpcm; - ia_bit_buf_struct temp_buf; + ia_bit_buf_struct temp_buf = {0}; WORD16 factor = ptr_aac_dec_channel_info->global_gain; WORD16 position = 0; @@ -950,7 +955,7 @@ VOID ixheaacd_hcr_read(ia_bit_buf_struct *it_bit_buff, } } -static VOID ixheaacd_rvlc_init( +static WORD32 ixheaacd_rvlc_init( ia_rvlc_info_struct *ptr_rvlc, ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, ia_bit_buf_struct *it_bit_buff) { @@ -1001,6 +1006,10 @@ static VOID ixheaacd_rvlc_init( ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3); it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7); } + if (it_bit_buff->cnt_bits < 0) { + return IA_ENHAACPLUS_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES; + } else + return 0; } VOID ixheaacd_bi_dir_est_scf_prev_frame_reference( @@ -1276,8 +1285,8 @@ VOID ixheaacd_bi_dir_est_lower_scf_cur_frame( conceal_group_max = ptr_rvlc->conceal_max / max_scf_bands; if (ptr_rvlc->conceal_min == ptr_rvlc->conceal_max) { - WORD32 ref_fwd, ref_nrg_fwd, ref_scf_fwd; - WORD32 ref_bwd, ref_nrg_bwd, ref_scf_bwd; + WORD32 ref_fwd = 0, ref_nrg_fwd = 0, ref_scf_fwd = 0; + WORD32 ref_bwd = 0, ref_nrg_bwd = 0, ref_scf_bwd = 0; bnds = ptr_rvlc->conceal_min; ixheaacd_calc_ref_val_fwd(ptr_rvlc, ptr_aac_dec_channel_info, &ref_fwd, @@ -1734,17 +1743,18 @@ static VOID ixheaacd_rvlc_final_error_detection( } } -VOID ixheaacd_rvlc_dec(ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, - ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info, - ia_bit_buf_struct *it_bit_buff) { +IA_ERRORCODE ixheaacd_rvlc_dec( + ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, + ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info, + ia_bit_buf_struct *it_bit_buff) { ia_rvlc_info_struct *ptr_rvlc = &ptr_aac_dec_channel_info->ptr_rvlc_info; - WORD32 bit_cnt_offset; - UWORD32 save_bit_cnt; - - ixheaacd_rvlc_init(ptr_rvlc, ptr_aac_dec_channel_info, it_bit_buff); - - save_bit_cnt = it_bit_buff->cnt_bits; + ia_bit_buf_struct saved_it_bit_buff; + IA_ERRORCODE error_code = 0; + error_code = + ixheaacd_rvlc_init(ptr_rvlc, ptr_aac_dec_channel_info, it_bit_buff); + if (error_code) return error_code; + ixheaacd_bitbuf_checkpoint(*it_bit_buff, saved_it_bit_buff); if (ptr_rvlc->sf_esc_present) ixheaacd_rvlc_decode_escape( ptr_rvlc, ptr_aac_dec_channel_info->rvlc_scf_esc_arr, it_bit_buff); @@ -1758,12 +1768,6 @@ VOID ixheaacd_rvlc_dec(ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, ptr_aac_dec_channel_info->rvlc_intensity_used = ptr_rvlc->intensity_used; ptr_aac_dec_channel_info->str_pns_info.pns_active = ptr_rvlc->noise_used; - bit_cnt_offset = it_bit_buff->cnt_bits - save_bit_cnt; - if (bit_cnt_offset) { - it_bit_buff->cnt_bits -= bit_cnt_offset; - it_bit_buff->ptr_read_next = - it_bit_buff->ptr_bit_buf_base + - ((it_bit_buff->size - it_bit_buff->cnt_bits) >> 3); - it_bit_buff->bit_pos = ((it_bit_buff->size - it_bit_buff->cnt_bits) & 7); - } -} \ No newline at end of file + ixheaacd_bitbuf_restore(*it_bit_buff, saved_it_bit_buff); + return error_code; +} diff --git a/decoder/ixheaacd_rvlc.h b/decoder/ixheaacd_rvlc.h index a7a12e4..228e2e2 100644 --- a/decoder/ixheaacd_rvlc.h +++ b/decoder/ixheaacd_rvlc.h @@ -3,9 +3,10 @@ void ixheaacd_rvlc_read( ia_bit_buf_struct *itt_bit_buff, ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info); -void ixheaacd_rvlc_dec(ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, - ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info, - ia_bit_buf_struct *itt_bit_buff); +IA_ERRORCODE ixheaacd_rvlc_dec( + ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, + ia_aac_dec_overlap_info *ptr_aac_dec_static_channel_info, + ia_bit_buf_struct *itt_bit_buff); void ixheaacd_hcr_read(ia_bit_buf_struct *itt_bit_buff, ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info, WORD32 ele_type); @@ -14,7 +15,7 @@ void ixheaacd_carry_bit_branch_val(UWORD8 carry_bit, UWORD32 tree_node, UWORD32 *branch_val, UWORD32 *branch_node); VOID ixheaacd_huff_sfb_table(WORD32 it_bit_buff, WORD16 *huff_index, - WORD16 *len, const UWORD16 *code_book_tbl, + WORD32 *len, const UWORD16 *code_book_tbl, const UWORD32 *idx_table); #endif diff --git a/decoder/ixheaacd_sbr_const.h b/decoder/ixheaacd_sbr_const.h index c75fa0c..9137c93 100644 --- a/decoder/ixheaacd_sbr_const.h +++ b/decoder/ixheaacd_sbr_const.h @@ -204,26 +204,31 @@ #define MAX_OV_DELAY 12 #define LD_TRAN 1 +#define LD_ENV_TIME_SLOT 7 +#define LD_ENV_TBL_512 16 +#define LD_ENV_TBL_480 15 +#define LD_ENV_TBL_SIZE 4 #define SBR_TRAN_BITS 4 #define SBRLD_CLA_BITS 1 #define SBR_ENVT_NUMENV 0 #define SBR_ENVT_TRANIDX 3 -static const int ixheaacd_ld_env_table_512[16][4] = { +static const int ixheaacd_ld_env_table_512[LD_ENV_TBL_512][LD_ENV_TBL_SIZE] = { {2, 4, -1, 0}, {2, 5, -1, 0}, {3, 2, 6, 1}, {3, 3, 7, 1}, {3, 4, 8, 1}, {3, 5, 9, 1}, {3, 6, 10, 1}, {3, 7, 11, 1}, {3, 8, 12, 1}, {3, 9, 13, 1}, {3, 10, 14, 1}, {2, 11, -1, 1}, {2, 12, -1, 1}, {2, 13, -1, 1}, {2, 14, -1, 1}, {2, 15, -1, 1}, }; -static const int ixheaacd_ld_env_table_480[15][4] = { +static const int ixheaacd_ld_env_table_480[LD_ENV_TBL_480][LD_ENV_TBL_SIZE] = { {2, 4, -1, 0}, {2, 5, -1, 0}, {3, 2, 6, 1}, {3, 3, 7, 1}, {3, 4, 8, 1}, {3, 5, 9, 1}, {3, 6, 10, 1}, {3, 7, 11, 1}, {3, 8, 12, 1}, {3, 9, 13, 1}, {2, 10, -1, 1}, {2, 11, -1, 1}, {2, 12, -1, 1}, {2, 13, -1, 1}, {2, 14, -1, 1}, }; -static const int ixheaacd_ld_env_table_time_slot[7] = {8, 5, 0, 0, 0, 0, 0}; +static const int ixheaacd_ld_env_table_time_slot[LD_ENV_TIME_SLOT] = { + 8, 5, 0, 0, 0, 0, 0}; #define SBR_CLA_BITS 2 #define SBR_ABS_BITS 2 diff --git a/decoder/ixheaacd_sbr_crc.c b/decoder/ixheaacd_sbr_crc.c index 0c90373..ee6c9b9 100644 --- a/decoder/ixheaacd_sbr_crc.c +++ b/decoder/ixheaacd_sbr_crc.c @@ -69,7 +69,7 @@ static PLATFORM_INLINE WORD32 ixheaacd_sbr_crc(ia_bit_buf_struct* it_bit_buff, FLAG ixheaacd_sbr_crccheck(ia_bit_buf_struct* it_bit_buff, WORD32 crc_bits_len) { - struct ia_bit_buf_struct it_bit_buff_local; + struct ia_bit_buf_struct it_bit_buff_local = {0}; WORD32 num_crc_bits; WORD32 calc_crc_sum; WORD32 bits_available; diff --git a/decoder/ixheaacd_sbr_dec.c b/decoder/ixheaacd_sbr_dec.c index 049433d..e58f2d4 100644 --- a/decoder/ixheaacd_sbr_dec.c +++ b/decoder/ixheaacd_sbr_dec.c @@ -158,6 +158,7 @@ VOID ixheaacd_hbe_repl_spec(WORD32 x_over_qmf[MAX_NUM_PATCHES], start_band--; } } + if (!ixheaacd_num_bands) break; for (col = 0; col < no_bins; col++) { WORD32 i = 0; band = target + ixheaacd_num_bands - 1; @@ -573,8 +574,8 @@ WORD32 ixheaacd_sbr_dec(ia_sbr_dec_struct *ptr_sbr_dec, WORD16 *ptr_time_data, WORD save_lb_scale; WORD op_delay; - WORD32 *p_arr_qmf_buf_real[MAX_ENV_COLS + MAX_ENV_COLS]; - WORD32 **p_arr_qmf_buf_imag = &p_arr_qmf_buf_real[MAX_ENV_COLS]; + WORD32 *p_arr_qmf_buf_real[MAX_ENV_COLS] = {0}; + WORD32 *p_arr_qmf_buf_imag[MAX_ENV_COLS] = {0}; WORD32 *ptr; WORD hbe_flag = ptr_header_data->hbe_flag; @@ -612,6 +613,10 @@ WORD32 ixheaacd_sbr_dec(ia_sbr_dec_struct *ptr_sbr_dec, WORD16 *ptr_time_data, WORD32 num = op_delay; WORD32 *ptr_pers_qmf_real = ptr_sbr_dec->ptr_sbr_overlap_buf; WORD32 *p_scr_qmf_real = ptr_work_buf_core + (2 << (6 + !low_pow_flag)); + + if ((no_bins < LPC_ORDER) || ((no_bins + op_delay) > MAX_ENV_COLS)) + return -1; + if (!low_pow_flag) { num = num << 1; } @@ -636,7 +641,7 @@ WORD32 ixheaacd_sbr_dec(ia_sbr_dec_struct *ptr_sbr_dec, WORD16 *ptr_time_data, if (apply_processing) { ixheaacd_rescale_x_overlap(ptr_sbr_dec, ptr_header_data, ptr_frame_data, ptr_frame_data_prev, p_arr_qmf_buf_real, - low_pow_flag); + p_arr_qmf_buf_imag, low_pow_flag); } } diff --git a/decoder/ixheaacd_sbr_dec.h b/decoder/ixheaacd_sbr_dec.h index 69a4d23..0461d39 100644 --- a/decoder/ixheaacd_sbr_dec.h +++ b/decoder/ixheaacd_sbr_dec.h @@ -20,6 +20,8 @@ #ifndef IXHEAACD_SBR_DEC_H #define IXHEAACD_SBR_DEC_H +#include + typedef struct { WORD32 x_over_qmf[MAX_NUM_PATCHES]; WORD32 max_stretch; @@ -121,6 +123,7 @@ struct ia_sbr_dec_inst_struct { FLAG prev_sbr_mode; FLAG inter_tes_flag; FLAG aot_usac_flag; + jmp_buf *xaac_jmp_buf; }; typedef struct ia_sbr_pers_struct { @@ -205,7 +208,8 @@ VOID ixheaacd_rescale_x_overlap( ia_sbr_dec_struct *ptr_sbr_dec, ia_sbr_header_data_struct *ptr_header_data, ia_sbr_frame_info_data_struct *ptr_frame_data, ia_sbr_prev_frame_data_struct *ptr_frame_data_prev, - WORD32 **pp_overlap_buffer_real, FLAG low_pow_flag); + WORD32 **pp_overlap_buffer_real, WORD32 **pp_overlap_buffer_imag, + FLAG low_pow_flag); WORD32 ixheaacd_qmf_hbe_data_reinit( ia_esbr_hbe_txposer_struct *ptr_hbe_transposer_str, diff --git a/decoder/ixheaacd_sbrdec_initfuncs.c b/decoder/ixheaacd_sbrdec_initfuncs.c index 7ec8ac8..524b80a 100644 --- a/decoder/ixheaacd_sbrdec_initfuncs.c +++ b/decoder/ixheaacd_sbrdec_initfuncs.c @@ -66,7 +66,7 @@ #include "ixheaacd_env_dec.h" #include "ixheaacd_basic_funcs.h" #include "ixheaacd_sbr_crc.h" - +#include "ixheaacd_error_standards.h" #include "ixheaacd_sbrqmftrans.h" #include "ixheaacd_audioobjtypes.h" diff --git a/decoder/ixheaacd_sbrdec_lpfuncs.c b/decoder/ixheaacd_sbrdec_lpfuncs.c index 0504f66..33213ec 100644 --- a/decoder/ixheaacd_sbrdec_lpfuncs.c +++ b/decoder/ixheaacd_sbrdec_lpfuncs.c @@ -349,6 +349,10 @@ WORD32 ixheaacd_reset_hf_generator(ia_sbr_hf_generator_struct *ptr_hf_gen_str, patch = 0; + if ((goal_sb < sb) && (lsb > src_start_band)) { + return -1; + } + while (((sb - usb) < 0) && (patch < MAX_NUM_PATCHES)) { ia_patch_param_struct *ptr_loc_patch_param = &p_str_patch_param[patch]; @@ -427,12 +431,12 @@ VOID ixheaacd_rescale_x_overlap( ia_sbr_dec_struct *ptr_sbr_dec, ia_sbr_header_data_struct *ptr_header_data, ia_sbr_frame_info_data_struct *ptr_frame_data, ia_sbr_prev_frame_data_struct *ptr_frame_data_prev, - WORD32 **pp_overlap_buffer_real, FLAG low_pow_flag) { + WORD32 **pp_overlap_buffer_real, WORD32 **pp_overlap_buffer_imag, + FLAG low_pow_flag) { WORD32 k, l; WORD32 start_band, end_band; WORD32 target_lsb, target_usb; WORD32 source_scale, target_scale, delta_scale, reserve; - WORD32 **pp_overlap_buffer_imag = &pp_overlap_buffer_real[MAX_ENV_COLS]; WORD32 old_lsb = ptr_frame_data_prev->max_qmf_subband_aac; WORD32 start_slot = @@ -954,7 +958,9 @@ WORD32 ixheaacd_generate_hf(FLOAT32 ptr_src_buf_real[][64], ia_auto_corr_ele_struct str_auto_corr; WORD16 *ptr_invf_band_tbl = - &ptr_header_data->pstr_freq_band_data->freq_band_tbl_noise[1]; + &ptr_header_data->pstr_freq_band_data + ->freq_band_tbl_noise[1]; // offest 1 used as base address of + // ptr_invf_band_tbl WORD32 num_if_bands = ptr_header_data->pstr_freq_band_data->num_nf_bands; WORD32 sub_band_start = ptr_header_data->pstr_freq_band_data->sub_band_start; WORD16 *f_master_tbl = ptr_header_data->pstr_freq_band_data->f_master_tbl; @@ -1116,8 +1122,12 @@ WORD32 ixheaacd_generate_hf(FLOAT32 ptr_src_buf_real[][64], for (k2 = sb; k2 < sb + num_bands_in_patch; k2++) { k = k2 - patch_stride; bw_index = 0; - while (k2 >= ptr_invf_band_tbl[bw_index]) bw_index++; + while (k2 >= ptr_invf_band_tbl[bw_index]) { + bw_index++; + if (bw_index >= MAX_NOISE_COEFFS) return -1; + } + if (bw_index >= MAX_NUM_PATCHES) return -1; bw = bw_array[bw_index]; a0r = bw * alpha_real[k][0]; @@ -1161,6 +1171,8 @@ WORD32 ixheaacd_generate_hf(FLOAT32 ptr_src_buf_real[][64], FLOAT32 alpha_real[2], alpha_imag[2]; bw_index = 0, patch = 1; + if (NULL == ptr_ph_vocod_buf_real || NULL == ptr_ph_vocod_buf_imag) + return -1; for (k2 = sub_band_start; k2 < f_master_tbl[num_mf_bands]; k2++) { ixheaacd_esbr_calc_co_variance(&str_auto_corr, &ptr_ph_vocod_buf_real[0], @@ -1206,8 +1218,12 @@ WORD32 ixheaacd_generate_hf(FLOAT32 ptr_src_buf_real[][64], alpha_imag[1] = 0.0f; } - while (k2 >= ptr_invf_band_tbl[bw_index]) bw_index++; + while (k2 >= ptr_invf_band_tbl[bw_index]) { + bw_index++; + if (bw_index >= MAX_NOISE_COEFFS) return -1; + } + if (bw_index >= MAX_NUM_PATCHES) return -1; bw = bw_array[bw_index]; a0r = bw * alpha_real[0]; diff --git a/decoder/ixheaacd_sbrdecoder.c b/decoder/ixheaacd_sbrdecoder.c index e357af2..4ab91f7 100644 --- a/decoder/ixheaacd_sbrdecoder.c +++ b/decoder/ixheaacd_sbrdecoder.c @@ -238,16 +238,14 @@ WORD32 ixheaacd_prepare_upsamp(ia_sbr_header_data_struct **ptr_header_data, return err; } -WORD16 ixheaacd_applysbr(ia_handle_sbr_dec_inst_struct self, - ia_aac_dec_sbr_bitstream_struct *p_sbr_bit_stream, - WORD16 *core_sample_buf, WORD16 *codec_num_channels, - FLAG frame_status, FLAG down_samp_flag, - FLAG down_mix_flag, - ia_sbr_scr_struct *sbr_scratch_struct, - WORD32 ps_enable, WORD32 ch_fac, WORD32 slot_element, - ia_bit_buf_struct *it_bit_buff, - ia_drc_dec_struct *pstr_drc_dec, WORD eld_sbr_flag, - WORD32 audio_object_type) { +IA_ERRORCODE ixheaacd_applysbr( + ia_handle_sbr_dec_inst_struct self, + ia_aac_dec_sbr_bitstream_struct *p_sbr_bit_stream, WORD16 *core_sample_buf, + WORD16 *codec_num_channels, FLAG frame_status, FLAG down_samp_flag, + FLAG down_mix_flag, ia_sbr_scr_struct *sbr_scratch_struct, WORD32 ps_enable, + WORD32 ch_fac, WORD32 slot_element, ia_bit_buf_struct *it_bit_buff, + ia_drc_dec_struct *pstr_drc_dec, WORD eld_sbr_flag, + WORD32 audio_object_type) { WORD32 k; FLAG prev_ps_flag = 0; FLAG ps_flag = 0; @@ -351,7 +349,7 @@ WORD16 ixheaacd_applysbr(ia_handle_sbr_dec_inst_struct self, } for (k = 0; k < num_elements; k++) { - struct ia_bit_buf_struct local_bit_buf; + struct ia_bit_buf_struct local_bit_buf = {0}; ia_sbr_element_stream_struct *ptr_bit_str_ele = &p_sbr_bit_stream->str_sbr_ele[k]; ele_channels = @@ -383,6 +381,7 @@ WORD16 ixheaacd_applysbr(ia_handle_sbr_dec_inst_struct self, ptr_bit_str_ele->size_payload); it_bit_buff = &local_bit_buf; + it_bit_buff->xaac_jmp_buf = self->xaac_jmp_buf; if (audio_object_type == AOT_ER_AAC_ELD) { if (eld_sbr_flag != 1) { ixheaacd_read_bits_buf(&local_bit_buf, LEN_NIBBLE); @@ -563,8 +562,10 @@ WORD16 ixheaacd_applysbr(ia_handle_sbr_dec_inst_struct self, if (ptr_header_data[0]->sync_state == SBR_ACTIVE) { if (ptr_frame_data[0]->sbr_mode == PVC_SBR) { - ixheaacd_dec_sbrdata_for_pvc(ptr_header_data[0], ptr_frame_data[0], - pstr_sbr_channel[0]->pstr_prev_frame_data); + err = ixheaacd_dec_sbrdata_for_pvc( + ptr_header_data[0], ptr_frame_data[0], + pstr_sbr_channel[0]->pstr_prev_frame_data); + if (err) return err; } else if (ptr_frame_data[0]->sbr_mode == ORIG_SBR) { err = ixheaacd_dec_sbrdata( ptr_header_data[0], ptr_header_data[1], ptr_frame_data[0], diff --git a/decoder/ixheaacd_sbrdecoder.h b/decoder/ixheaacd_sbrdecoder.h index cd0cebd..21c90c0 100644 --- a/decoder/ixheaacd_sbrdecoder.h +++ b/decoder/ixheaacd_sbrdecoder.h @@ -64,7 +64,7 @@ typedef struct { VOID *extra_scr_1k[2]; } ia_sbr_scr_struct; -WORD16 ixheaacd_applysbr( +IA_ERRORCODE ixheaacd_applysbr( ia_handle_sbr_dec_inst_struct self, ia_aac_dec_sbr_bitstream_struct *p_sbr_bit_stream, WORD16 *core_sample_buf, WORD16 *codec_num_channels, FLAG frame_status, FLAG down_samp_flag, diff --git a/decoder/ixheaacd_sbrqmftrans.h b/decoder/ixheaacd_sbrqmftrans.h index 7c3e61a..2b856b9 100644 --- a/decoder/ixheaacd_sbrqmftrans.h +++ b/decoder/ixheaacd_sbrqmftrans.h @@ -32,8 +32,8 @@ WORD32 ixheaacd_qmf_hbe_data_reinit( WORD16 *ptr_freq_band_tbl[MAX_FREQ_COEFFS + 1], WORD16 *ptr_num_sf_bands, WORD32 upsamp_4_flag); -VOID ixheaacd_hbe_post_anal_process(ia_esbr_hbe_txposer_struct *ptr_hbe_txposer, - WORD32 pitch_in_bins, - WORD32 sbr_upsamp_4_flg); +IA_ERRORCODE ixheaacd_hbe_post_anal_process( + ia_esbr_hbe_txposer_struct *ptr_hbe_txposer, WORD32 pitch_in_bins, + WORD32 sbr_upsamp_4_flg); #endif diff --git a/decoder/ixheaacd_spectrum_dec.c b/decoder/ixheaacd_spectrum_dec.c index dff3713..c827a02 100644 --- a/decoder/ixheaacd_spectrum_dec.c +++ b/decoder/ixheaacd_spectrum_dec.c @@ -243,8 +243,10 @@ VOID ixheaacd_section_data(ia_usac_data_struct *usac_data, WORD32 is_1_group = 1; WORD32 bb = 0, i; - WORD32 read_word = ixheaacd_aac_showbits_32(ptr_read_next); - ptr_read_next = g_bs->ptr_read_next + 4; + WORD32 increment; + WORD32 read_word = + ixheaacd_aac_showbits_32(ptr_read_next, g_bs->cnt_bits, &increment); + ptr_read_next = g_bs->ptr_read_next + increment; trans_sfb = info->sfb_per_sbk; temp_ptr_scale_fac = factors; @@ -278,7 +280,8 @@ VOID ixheaacd_section_data(ia_usac_data_struct *usac_data, ixheaacd_huffman_decode(read_word1, &index, &length, hscf, idx_tab); bit_pos += length; - ixheaacd_aac_read_2bytes(&ptr_read_next, &bit_pos, &read_word); + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + g_bs->ptr_bit_buf_end); norm_val = index - 60; if (cb_num > NOISE_HCB) { @@ -312,8 +315,11 @@ VOID ixheaacd_section_data(ia_usac_data_struct *usac_data, } } } + ptr_read_next = ptr_read_next - increment; + ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word, + g_bs->ptr_bit_buf_end); - g_bs->ptr_read_next = ptr_read_next - 4; + g_bs->ptr_read_next = ptr_read_next; g_bs->bit_pos = 7 - bit_pos; { diff --git a/decoder/ixheaacd_struct_def.h b/decoder/ixheaacd_struct_def.h index 95ad94b..ee52f0c 100644 --- a/decoder/ixheaacd_struct_def.h +++ b/decoder/ixheaacd_struct_def.h @@ -20,6 +20,8 @@ #ifndef IXHEAACD_STRUCT_DEF_H #define IXHEAACD_STRUCT_DEF_H +#include + #define MAX_OUTPUT_CHANNELS (8) #define MAX_NUM_OTT (1) @@ -230,6 +232,8 @@ typedef struct ia_aac_dec_state_struct { UWORD8 *header_ptr; WORD32 header_length; ia_sbr_header_data_struct str_sbr_config; + jmp_buf xaac_jmp_buf; + WORD32 decode_create_done; } ia_aac_dec_state_struct; typedef struct ia_exhaacplus_dec_api_struct { diff --git a/decoder/ixheaacd_tns.c b/decoder/ixheaacd_tns.c index ab3792b..9a6cdf1 100644 --- a/decoder/ixheaacd_tns.c +++ b/decoder/ixheaacd_tns.c @@ -178,10 +178,11 @@ static VOID ixheaacd_tns_ar_filter_usac(WORD32 *spectrum, WORD32 size, } } -VOID ixheaacd_tns_apply(ia_usac_data_struct *usac_data, WORD32 *spec, - WORD32 nbands, ia_sfb_info_struct *pstr_sfb_info, - ia_tns_frame_info_struct *pstr_tns) { - WORD32 f, max_order, start, stop, size, inc; +IA_ERRORCODE ixheaacd_tns_apply(ia_usac_data_struct *usac_data, WORD32 *spec, + WORD32 nbands, + ia_sfb_info_struct *pstr_sfb_info, + ia_tns_frame_info_struct *pstr_tns) { + WORD32 f, start, stop, size, inc; WORD32 n_filt, coef_res, order, direction; WORD32 *ptr_spec; WORD32 scale_spec; @@ -197,7 +198,6 @@ VOID ixheaacd_tns_apply(ia_usac_data_struct *usac_data, WORD32 *spec, WORD32 nbins = (pstr_sfb_info->islong) ? 1024 : 128; WORD32 i, j, idx; - max_order = (pstr_sfb_info->islong) ? 15 : 7; idx = (pstr_sfb_info->islong) ? 0 : 1; ptr_spec = &usac_data->scratch_buffer[0]; @@ -222,10 +222,6 @@ VOID ixheaacd_tns_apply(ia_usac_data_struct *usac_data, WORD32 *spec, start = filt->start_band; stop = filt->stop_band; - if (order > max_order) { - fprintf(stderr, "Error in tns max order: %d %d\n", order, max_order); - } - if (!order) continue; ixheaacd_tns_dec_coef_usac(usac_data, filt, coef_res, @@ -240,10 +236,12 @@ VOID ixheaacd_tns_apply(ia_usac_data_struct *usac_data, WORD32 *spec, start = ixheaacd_min32(start, tmp); start = ixheaacd_min32(start, nbands); + if (start > pstr_sfb_info->sfb_per_sbk) return -1; start = sfb_offset(start); stop = ixheaacd_min32(stop, tmp); stop = ixheaacd_min32(stop, nbands); + if (stop > pstr_sfb_info->sfb_per_sbk) return -1; stop = sfb_offset(stop); guard_band = 31 - ixheaacd_norm32(filt->order); @@ -310,4 +308,5 @@ VOID ixheaacd_tns_apply(ia_usac_data_struct *usac_data, WORD32 *spec, spec += pstr_sfb_info->bins_per_sbk; } + return 0; } diff --git a/decoder/ixheaacd_type_def.h b/decoder/ixheaacd_type_def.h index b762b2f..2205550 100644 --- a/decoder/ixheaacd_type_def.h +++ b/decoder/ixheaacd_type_def.h @@ -84,6 +84,7 @@ typedef unsigned int UWORD; /* ulp SLOOPIDX ulp_index */ typedef LOOPIDX LOOPINDEX; /* lp LOOPIDX lp_index */ typedef ULOOPIDX ULOOPINDEX; /* ulp SLOOPIDX ulp_index */ +typedef WORD32 IA_ERRORCODE; #define PLATFORM_INLINE __inline #endif /* IXHEAACD_TYPE_DEF_H */ diff --git a/libxaac_blacklist.txt b/libxaac_blacklist.txt new file mode 100644 index 0000000..f7c61b7 --- /dev/null +++ b/libxaac_blacklist.txt @@ -0,0 +1,113 @@ +[cfi] +# CFI blacklist for external/libhevc + +# assembly functions where CFI has issues +fun:ixheaacd_fix_div_armv7 +fun:ixheaacd_covariance_matrix_calc_armv7 +fun:ixheaacd_covariance_matrix_calc_2_armv7 +fun:ixheaacd_over_lap_add1_armv7 +fun:ixheaacd_over_lap_add2_armv7 +fun:ixheaacd_decorr_filter2_armv7 +fun:ixheaacd_decorr_filter1_armv7 +fun:ixheaacd_divide16_pos_armv7 +fun:ixheaacd_decorrelation_armv7 +fun:ixheaacd_apply_rot_armv7 +fun:ixheaacd_conv_ergtoamplitudelp_armv7 +fun:ixheaacd_conv_ergtoamplitude_armv7 +fun:ixheaacd_adjust_scale_armv7 +fun:ixheaacd_expsubbandsamples_armv7 +fun:ixheaacd_enery_calc_per_subband_armv7 +fun:ixheaacd_harm_idx_zerotwolp_armv7 +fun:ixheaacd_tns_ar_filter_fixed_armv7 +fun:ixheaacd_tns_ar_filter_armv7 +fun:ixheaacd_tns_parcor_lpc_convert_armv7 +fun:ixheaacd_calc_max_spectral_line_armv7 +fun:ixheaacd_post_twiddle_armv7 +fun:ixheaacd_post_twid_overlap_add_armv7 +fun:ixheaacd_neg_shift_spec_armv7 +fun:ixheaacd_spec_to_overlapbuf_armv7 +fun:ixheaacd_overlap_buf_out_armv7 +fun:ixheaacd_overlap_out_copy_armv7 +fun:ixheaacd_pretwiddle_compute_armv7 +fun:ixheaacd_imdct_using_fft_armv7 +fun:ixheaacd_complex_fft_p2_armv7 +fun:ixheaacd_mps_complex_fft_64_armv7 +fun:ixheaacd_mps_synt_pre_twiddle_armv7 +fun:ixheaacd_mps_synt_post_twiddle_armv7 +fun:ixheaacd_calc_pre_twid_armv7 +fun:ixheaacd_calc_post_twid_armv7 +fun:ixheaacd_mps_synt_post_fft_twiddle_armv7 +fun:ixheaacd_mps_synt_out_calc_armv7 +fun:ixheaacd_fft_15_ld_armv7 +fun:ia_aac_ld_dec_rearrange_armv7 +fun:ixheaacd_imdct_using_fft_armv7 +fun:ixheaacd_fft32x32_ld2_armv7 +fun:ixheaacd_neg_expo_inc_arm +fun:ixheaacd_inv_dit_fft_8pt_armv7 +fun:ixheaacd_scale_factor_process_armv7 +fun:ixheaacd_fix_div_dec +fun:ixheaacd_covariance_matrix_calc_dec +fun:ixheaacd_covariance_matrix_calc_2_dec +fun:ixheaacd_over_lap_add1_armv8 +fun:ixheaacd_over_lap_add2_armv8 +fun:ixheaacd_decorr_filter2_dec +fun:ixheaacd_decorr_filter1_dec +fun:ixheaacd_divide16_pos_dec +fun:ixheaacd_decorrelation_dec +fun:ixheaacd_apply_rot_dec +fun:ixheaacd_conv_ergtoamplitudelp_dec +fun:ixheaacd_conv_ergtoamplitude_dec +fun:ixheaacd_adjust_scale_dec +fun:ixheaacd_expsubbandsamples_dec +fun:ixheaacd_enery_calc_per_subband_dec +fun:ixheaacd_harm_idx_zerotwolp_dec +fun:ixheaacd_tns_ar_filter_fixed_armv8 +fun:ixheaacd_tns_ar_filter_dec +fun:ixheaacd_tns_parcor_lpc_convert_dec +fun:ixheaacd_calc_max_spectral_line_armv8 +fun:ixheaacd_post_twiddle_armv8 +fun:ixheaacd_post_twid_overlap_add_armv8 +fun:ixheaacd_neg_shift_spec_armv8 +fun:ixheaacd_spec_to_overlapbuf_dec +fun:ixheaacd_overlap_buf_out_dec +fun:ixheaacd_overlap_out_copy_dec +fun:ixheaacd_pretwiddle_compute_armv8 +fun:ixheaacd_imdct_using_fft_armv8 +fun:ixheaacd_complex_fft_p2_dec +fun:ixheaacd_mps_complex_fft_64_dec +fun:ixheaacd_mps_synt_pre_twiddle_dec +fun:ixheaacd_mps_synt_post_twiddle_dec +fun:ixheaacd_calc_pre_twid_dec +fun:ixheaacd_calc_post_twid_dec +fun:ixheaacd_mps_synt_post_fft_twiddle_dec +fun:ixheaacd_mps_synt_out_calc_dec +fun:ixheaacd_fft_15_ld_dec +fun:ixheaacd_rearrange_dec +fun:ixheaacd_imdct_using_fft_armv8 +fun:ixheaacd_fft32x32_ld2_armv8 +fun:ixheaacd_neg_expo_inc_arm +fun:ixheaacd_inv_dit_fft_8pt_armv8 +fun:ixheaacd_scale_factor_process_armv8 +fun:ixheaacd_aac_tns_process +fun:ixheaacd_acelp_imdct +fun:ixheaacd_apply_ps +fun:ixheaacd_calc_sbrenvelope +fun:ixheaacd_cblock_scale_spect_data +fun:ixheaacd_complex_fft +fun:ixheaacd_complex_fft_p3 +fun:ixheaacd_esbr_cos_sin_mod +fun:ixheaacd_fft_480_ld +fun:ixheaacd_filter1_lp +fun:ixheaacd_hf_generator +fun:ixheaacd_hybrid_analysis +fun:ixheaacd_imdct_process +fun:ixheaacd_inverse_transform +fun:ixheaacd_inverse_transform_512 +fun:ixheaacd_low_pow_hf_generator +fun:ixheaacd_mdct_480_ld +fun:ixheaacd_mps_synt_calc +fun:ixheaacd_read_spectral_data +fun:ixheaacd_tns_apply +fun:ixheaacd_cplx_synt_qmffilt +fun:ixheaacd_sbr_qmfsyn64_winadd +fun:ixheaacd_filt_8_ch diff --git a/test/Android.bp b/test/Android.bp index 7990708..d131c94 100644 --- a/test/Android.bp +++ b/test/Android.bp @@ -9,9 +9,9 @@ cc_test { "-UARM_PROFILE_HW", "-UARM_PROFILE_BOARD", "-DECLIPSE", - "-DDRC_ENABLE", - "-DMULTICHANNEL_ENABLE", - "-DENABLE_DRC" + "-DDRC_ENABLE", + "-DMULTICHANNEL_ENABLE", + "-DENABLE_DRC" ], include_dirs: [ @@ -19,10 +19,10 @@ cc_test { ], srcs: [ - "ixheaacd_error.c", - "ixheaacd_fileifc.c", - "ixheaacd_main.c", - "ixheaacd_metadata_read.c" + "ixheaacd_error.c", + "ixheaacd_fileifc.c", + "ixheaacd_main.c", + "ixheaacd_metadata_read.c" ], static_libs: ["libxaacdec"], diff --git a/test/impd_drc_config_params.h b/test/impd_drc_config_params.h index 8d15f2f..3bc7989 100644 --- a/test/impd_drc_config_params.h +++ b/test/impd_drc_config_params.h @@ -21,41 +21,37 @@ #ifndef IMPD_DRC_CONFIG_PARAMS_H #define IMPD_DRC_CONFIG_PARAMS_H +#define IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ 0x0000 +#define IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ 0x0001 +#define IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS 0x0002 +#define IA_DRC_DEC_CONFIG_PARAM_DEC_TYPE 0x0003 +#define IA_DRC_DEC_CONFIG_PARAM_PEAK_LIMITER 0x0004 +#define IA_DRC_DEC_CONFIG_PARAM_CTRL_PARAM 0x0005 +#define IA_DRC_DEC_CONFIG_PARAM_VER_MODE 0x0006 +#define IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT 0x0007 +#define IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT 0x0008 +#define IA_DRC_DEC_CONFIG_PARAM_DELAY_MODE 0x0009 +#define IA_DRC_DEC_CONFIG_PARAM_GAIN_DELAY 0x000A +#define IA_DRC_DEC_CONFIG_PARAM_AUDIO_DELAY 0x000B +#define IA_DRC_DEC_CONFIG_PARAM_CON_DELAY_MODE 0x000C +#define IA_DRC_DEC_CONFIG_PARAM_ABSO_DELAY_OFF 0x000D +#define IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE 0x000E +#define IA_DRC_DEC_CONFIG_PROC_OUT_PTR 0x000F +#define IA_DRC_DEC_CONFIG_GAIN_STREAM_FLAG 0x0010 +#define IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE 0x0011 +#define IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS 0x0012 +#define IA_DRC_DEC_CONFIG_DRC_LOUD_NORM 0x0013 -#define IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ 0x0000 -#define IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ 0x0001 -#define IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS 0x0002 -#define IA_DRC_DEC_CONFIG_PARAM_DEC_TYPE 0x0003 -#define IA_DRC_DEC_CONFIG_PARAM_PEAK_LIMITER 0x0004 -#define IA_DRC_DEC_CONFIG_PARAM_CTRL_PARAM 0x0005 -#define IA_DRC_DEC_CONFIG_PARAM_VER_MODE 0x0006 -#define IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT 0x0007 -#define IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT 0x0008 -#define IA_DRC_DEC_CONFIG_PARAM_DELAY_MODE 0x0009 -#define IA_DRC_DEC_CONFIG_PARAM_GAIN_DELAY 0x000A -#define IA_DRC_DEC_CONFIG_PARAM_AUDIO_DELAY 0x000B -#define IA_DRC_DEC_CONFIG_PARAM_CON_DELAY_MODE 0x000C -#define IA_DRC_DEC_CONFIG_PARAM_ABSO_DELAY_OFF 0x000D -#define IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE 0x000E -#define IA_DRC_DEC_CONFIG_PROC_OUT_PTR 0x000F -#define IA_DRC_DEC_CONFIG_GAIN_STREAM_FLAG 0x0010 -#define IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE 0x0011 -#define IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS 0x0012 -#define IA_DRC_DEC_CONFIG_DRC_LOUD_NORM 0x0013 +#define IA_API_CMD_SET_INPUT_BYTES_BS 0x0026 +#define IA_API_CMD_SET_INPUT_BYTES_IC_BS 0x0027 +#define IA_API_CMD_SET_INPUT_BYTES_IL_BS 0x0029 +#define IA_API_CMD_SET_INPUT_BYTES_IN_BS 0x002A +#define IA_CMD_TYPE_INIT_CPY_BSF_BUFF 0x0201 +#define IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF 0x0202 +#define IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF 0x0203 +#define IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF 0x0205 -#define IA_API_CMD_SET_INPUT_BYTES_BS 0x0026 -#define IA_API_CMD_SET_INPUT_BYTES_IC_BS 0x0027 -#define IA_API_CMD_SET_INPUT_BYTES_IL_BS 0x0029 -#define IA_API_CMD_SET_INPUT_BYTES_IN_BS 0x002A - - -#define IA_CMD_TYPE_INIT_CPY_BSF_BUFF 0x0201 -#define IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF 0x0202 -#define IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF 0x0203 -#define IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF 0x0205 - - -#define IA_CMD_TYPE_INIT_SET_BUFF_PTR 0x020B +#define IA_CMD_TYPE_INIT_SET_BUFF_PTR 0x020B #endif diff --git a/test/ixheaacd_fileifc.c b/test/ixheaacd_fileifc.c index 8a5b13b..ce1e32b 100644 --- a/test/ixheaacd_fileifc.c +++ b/test/ixheaacd_fileifc.c @@ -49,8 +49,11 @@ FileWrapperPtr FileWrapper_Open(char fileName[]) { if ((transport->fileCtxt = it_fopen((void *)fileName, 1, 0)) == NULL) { transport->inputFile = fopen(fileName, "rb"); - if (!transport->inputFile) + if (!transport->inputFile) { + free(transport); return 0; + } + else return transport; } @@ -58,9 +61,10 @@ FileWrapperPtr FileWrapper_Open(char fileName[]) { if ((transport->mp4Ctxt = it_mp4_parser_init(transport->fileCtxt, NULL)) == NULL) { transport->inputFile = fopen(fileName, "rb"); - if (!transport->inputFile) + if (!transport->inputFile) { + free(transport); return 0; - else + } else return transport; } transport->isMp4File = 1; @@ -68,14 +72,16 @@ FileWrapperPtr FileWrapper_Open(char fileName[]) { /* As max channels is 8 and +2 for upto two Ind CoupCh */ transport->interim_buffer = malloc(10 * 768); if (transport->interim_buffer == NULL) { + free(transport); return 0; } return transport; #else transport->inputFile = fopen(fileName, "rb"); - if (!transport->inputFile) + if (!transport->inputFile) { + free(transport); return 0; - else + } else return transport; #endif } diff --git a/test/ixheaacd_main.c b/test/ixheaacd_main.c index feec6c5..757c78a 100644 --- a/test/ixheaacd_main.c +++ b/test/ixheaacd_main.c @@ -41,6 +41,7 @@ IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, WORD32 i_idx, VOID ixheaacd_error_handler_init(); VOID ia_testbench_error_handler_init(); +VOID metadata_mp4_stsz_size_free(metadata_info *meta_info); extern ia_error_info_struct ixheaacd_ia_testbench_error_info; extern ia_error_info_struct ixheaacd_error_info; @@ -59,7 +60,6 @@ extern ia_error_info_struct ixheaacd_error_info; #define IA_MAX_CMD_LINE_LENGTH 300 #define IA_MAX_ARGS 20 #define IA_SCREEN_WIDTH 80 -#define PARAMFILE "paramfilesimple.txt" /*****************************************************************************/ /* Error codes for the testbench */ @@ -98,8 +98,7 @@ WORD g_w_malloc_count; FILE *g_pf_out; FileWrapperPtr g_pf_inp; /* file pointer to bitstream file (mp4) */ -FILE *g_pf_interface; -WORD32 interface_file_present = 0; +WORD32 mpeg_d_drc_on = 0; metadata_info meta_info; // metadata pointer; WORD32 ixheaacd_i_bytes_to_read; @@ -588,21 +587,27 @@ IA_ERRORCODE ixheaacd_set_config_param(WORD32 argc, pWORD8 argv[], /*For MPEG-D DRC effect type*/ if (!strncmp((pCHAR8)argv[i], "-effect:", 8)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 8); - WORD32 ui_effect = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &ui_effect); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 8); + WORD32 ui_effect = atoi(pb_arg_val); + err_code = + (*p_ia_process_api)(p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, + IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &ui_effect); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + mpeg_d_drc_on = 1; } /*For MPEG-D DRC target loudness*/ if (!strncmp((pCHAR8)argv[i], "-target_loudness:", 17)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 17); - WORD32 ui_target_loudness = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &ui_target_loudness); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 17); + WORD32 ui_target_loudness = atoi(pb_arg_val); + if ((ui_target_loudness > 0) || (ui_target_loudness < -63)) { + ui_target_loudness = 0; + } + ui_target_loudness = -(ui_target_loudness << 2); + err_code = (*p_ia_process_api)( + p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, + IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &ui_target_loudness); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + mpeg_d_drc_on = 1; } if (!strncmp((pCHAR8)argv[i], "-ld_testing:", 12)) { pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 12); @@ -775,13 +780,13 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { pVOID pv_ia_drc_process_api_obj; UWORD32 pui_api_size; -/* First part */ -/* Error Handler Init */ -/* Get Library Name, Library Version and API Version */ -/* Initialize API structure + Default config set */ -/* Set config params from user */ -/* Initialize memory tables */ -/* Get memory information and allocate memory */ + /* First part */ + /* Error Handler Init */ + /* Get Library Name, Library Version and API Version */ + /* Initialize API structure + Default config set */ + /* Set config params from user */ + /* Initialize memory tables */ + /* Get memory information and allocate memory */ UWORD8 drc_ip_buf[8192 * 4]; UWORD8 drc_op_buf[8192 * 4]; @@ -923,7 +928,6 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { /* Allocate memory for API */ g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(pui_api_size + 4); - memset(g_pv_arr_alloc_memory[g_w_malloc_count], 0, pui_api_size); if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) { _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info, (pWORD8) "API struct alloc", err_code); @@ -942,7 +946,6 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - /* ******************************************************************/ /* Set config parameters got from the user present in argc argv */ /* ******************************************************************/ @@ -1212,10 +1215,24 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { if (raw_testing) { ixheaacd_i_bytes_to_read = get_metadata_dec_exec(meta_info, frame_counter); + + if (ixheaacd_i_bytes_to_read > (WORD32)ui_inp_size) + return IA_FATAL_ERROR; + + if (ixheaacd_i_bytes_to_read <= 0) { + err_code = (*p_ia_process_api)(pv_ia_process_api_obj, + IA_API_CMD_INPUT_OVER, 0, NULL); + + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + + return IA_NO_ERROR; + } + /* Set number of bytes to be processed */ err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0, &ixheaacd_i_bytes_to_read); + init_iteration++; } else { /* Set number of bytes to be processed */ err_code = (*p_ia_process_api)( @@ -1236,6 +1253,10 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT, IA_CMD_TYPE_INIT_DONE_QUERY, &ui_init_done); + if (init_iteration > 2 && ui_init_done == 0) { + frame_counter++; + } + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); /* How much buffer is used in input buffers */ @@ -1247,7 +1268,7 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { } while (!ui_init_done); - if (interface_file_present == 1) { + if (mpeg_d_drc_on == 1) { err_code = (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq, &i_num_chan, &i_pcm_wd_sz, &i_channel_mask); @@ -1279,51 +1300,67 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { /*Set Effect Type*/ { - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, &i_effect_type); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - err_code = - ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + err_code = (*p_ia_process_api)( + pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, + IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, &i_effect_type); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + err_code = + ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, + IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); } /*Set target loudness */ { - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &i_target_loudness); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - err_code = - ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + err_code = (*p_ia_process_api)( + pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, + IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, + &i_target_loudness); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + err_code = ia_drc_dec_api( + pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, + IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); } /*Set loud_norm_flag*/ { - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM, &i_loud_norm); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - err_code = - ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + err_code = (*p_ia_process_api)( + pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, + IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM, &i_loud_norm); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + err_code = + ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, + IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); } + /* Get memory info tables size */ + err_code = + ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_GET_MEMTABS_SIZE, + 0, &ui_proc_mem_tabs_size); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(ui_proc_mem_tabs_size); + if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) { + err_code = IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED; + _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Mem tables alloc", err_code); + } + /* Set pointer for process memory tables */ + err_code = ia_drc_dec_api( + pv_ia_drc_process_api_obj, IA_API_CMD_SET_MEMTABS_PTR, 0, + (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count])); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + + g_w_malloc_count++; err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_INIT, IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, NULL); @@ -1486,10 +1523,9 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { /*Read interface buffer config file bitstream*/ - if(mpegd_drc_present==1){ + if (mpegd_drc_present == 1) { WORD32 interface_is_present = 1; - err_code = ia_drc_dec_api( pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT, &interface_is_present); @@ -1550,10 +1586,11 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { #ifdef ENABLE_LD_DEC if (0 != frame_counter) { #endif - FileWrapper_Read(g_pf_inp, (unsigned char *)(pb_inp_buf + i_buff_size - - i_bytes_consumed), - ((WORD32)ui_inp_size - (WORD32)(i_buff_size - i_bytes_consumed)), - (pUWORD32)&i_bytes_read); + FileWrapper_Read( + g_pf_inp, + (unsigned char *)(pb_inp_buf + i_buff_size - i_bytes_consumed), + ((WORD32)ui_inp_size - (WORD32)(i_buff_size - i_bytes_consumed)), + (pUWORD32)&i_bytes_read); #ifdef ENABLE_LD_DEC } else i_bytes_read = 0; @@ -1577,6 +1614,8 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { ixheaacd_i_bytes_to_read = get_metadata_dec_exec(meta_info, frame_counter); + if (ixheaacd_i_bytes_to_read > (WORD32)ui_inp_size) return IA_FATAL_ERROR; + if (ixheaacd_i_bytes_to_read <= 0) { err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INPUT_OVER, 0, NULL); @@ -1623,7 +1662,7 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - if (interface_file_present == 1) { + if (mpeg_d_drc_on == 1) { if (ui_exec_done != 1) { VOID *p_array; // ITTIAM:buffer to handle gain payload WORD32 buf_size = 0; // ITTIAM:gain payload length @@ -1689,36 +1728,27 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { if (mpegd_drc_present == 1) { memcpy(drc_ip_buf, pb_out_buf, i_out_bytes); - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &i_sbr_mode); + pv_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, + IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &i_sbr_mode); _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + if (i_sbr_mode != 0) { + WORD32 frame_length; + if (i_sbr_mode == 1) { + frame_length = 2048; + } else if (i_sbr_mode == 3) { + frame_length = 4096; + } else { + frame_length = 1024; + } - if (i_sbr_mode != 0) - { - WORD32 frame_length; - if (i_sbr_mode == 1) - { - frame_length = 2048; - } - else if(i_sbr_mode == 3) - { - frame_length = 4096; - } - else - { - frame_length = 1024; - } - - err_code = - ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE, &frame_length); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); + err_code = ia_drc_dec_api( + pv_ia_drc_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, + IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE, &frame_length); + _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); } - err_code = ia_drc_dec_api(pv_ia_drc_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0, &i_out_bytes); @@ -1732,7 +1762,6 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { memcpy(pb_out_buf, drc_op_buf, i_out_bytes); } - if (total_samples != 0) // Usac stream { if (raw_testing) { @@ -1784,9 +1813,7 @@ int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) { #endif } - if (i_out_bytes) { - frame_counter++; - } + frame_counter++; #ifdef _DEBUG if (frame_counter == 80) frame_counter = frame_counter; @@ -1958,370 +1985,109 @@ void print_usage() { /*******************************************************************************/ int main(WORD32 argc, char *argv[]) { - FILE *param_file_id; - - WORD8 curr_cmd[IA_MAX_CMD_LINE_LENGTH]; - WORD32 fargc, curpos; - WORD32 processcmd = 0; - - WORD8 fargv[IA_MAX_ARGS][IA_MAX_CMD_LINE_LENGTH]; - - pWORD8 pargv[IA_MAX_ARGS]; - - WORD8 pb_input_file_path[IA_MAX_CMD_LINE_LENGTH] = ""; - WORD8 pb_output_file_path[IA_MAX_CMD_LINE_LENGTH] = ""; + WORD32 i, err_code = IA_NO_ERROR; ia_testbench_error_handler_init(); - if (argc == 1) { - param_file_id = fopen(PARAMFILE, "r"); - if (param_file_id == NULL) { - print_usage(); - return IA_NO_ERROR; + g_pf_inp = NULL; + g_pf_meta = NULL; + g_pf_out = NULL; + + for (i = 1; i < argc; i++) { + printf("%s ", argv[i]); + + if (!strncmp((const char *)argv[i], "-ifile:", 7)) { + pWORD8 pb_arg_val = (pWORD8)argv[i] + 7; + + g_pf_inp = FileWrapper_Open((char *)pb_arg_val); + if (g_pf_inp == NULL) { + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Input File", err_code); + exit(1); + } + raw_testing = 0; } - /* Process one line at a time */ - while (fgets((char *)curr_cmd, IA_MAX_CMD_LINE_LENGTH, param_file_id)) { - curpos = 0; - fargc = 0; - /* if it is not a param_file command and if */ - /* CLP processing is not enabled */ - if (curr_cmd[0] != '@' && !processcmd) { /* skip it */ - continue; + if (!strncmp((const char *)argv[i], "-imeta:", 7)) { + pWORD8 pb_arg_val = (pWORD8)argv[i] + 7; + + g_pf_meta = fopen((const char *)pb_arg_val, "r"); + + if (g_pf_meta == NULL) { + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Metadata File", err_code); + exit(1); } - while (sscanf((char *)curr_cmd + curpos, "%s", fargv[fargc]) != EOF) { - if (fargv[0][0] == '/' && fargv[0][1] == '/') break; - if (strcmp((const char *)fargv[0], "@echo") == 0) break; - if (strcmp((const char *)fargv[fargc], "@New_line") == 0) { - fgets((char *)curr_cmd + curpos, IA_MAX_CMD_LINE_LENGTH, - param_file_id); - continue; - } - curpos += strlen((const char *)fargv[fargc]); - while (*(curr_cmd + curpos) == ' ' || *(curr_cmd + curpos) == '\t') - curpos++; - fargc++; + err_code = ixheaacd_read_metadata_info(g_pf_meta, &meta_info); + + if (err_code == -1) { + exit(1); } - - if (fargc < 1) /* for blank lines etc. */ - continue; - - if (strcmp((const char *)fargv[0], "@Output_path") == 0) { - if (fargc > 1) - strcpy((char *)pb_output_file_path, (const char *)fargv[1]); - else - strcpy((char *)pb_output_file_path, ""); - continue; - } - - if (strcmp((const char *)fargv[0], "@Input_path") == 0) { - if (fargc > 1) - strcpy((char *)pb_input_file_path, (const char *)fargv[1]); - else - strcpy((char *)pb_input_file_path, ""); - continue; - } - - if (strcmp((const char *)fargv[0], "@Start") == 0) { - processcmd = 1; - continue; - } - - if (strcmp((const char *)fargv[0], "@Stop") == 0) { - processcmd = 0; - continue; - } - - /* otherwise if this a normal command and its enabled for execution */ - if (processcmd) { - int i; - int err_code = IA_NO_ERROR; - int file_count = 0; - - for (i = 0; i < fargc; i++) { - printf("%s ", fargv[i]); - pargv[i] = fargv[i]; - - if (!strncmp((const char *)fargv[i], "-ifile:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_input_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_input_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_input_file_name, (const char *)pb_arg_val); - - g_pf_inp = NULL; - g_pf_inp = FileWrapper_Open((char *)pb_input_file_name); - - if (g_pf_inp == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input File", err_code); - exit(1); - } - file_count++; - raw_testing = 0; - } - - if (!strncmp((const char *)fargv[i], "-imeta:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_metadata_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_metadata_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_metadata_file_name, (const char *)pb_arg_val); - - g_pf_meta = fopen((const char *)pb_metadata_file_name, "r"); - - if (g_pf_meta == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Metadata File", err_code); - exit(1); - } - - metadata_info_init(&meta_info); - err_code = ixheaacd_read_metadata_info(g_pf_meta, &meta_info); - - if (err_code == -1) exit(1); - - raw_testing = 1; - - file_count++; - } - - if (!strncmp((const char *)fargv[i], "-ofile:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_output_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_output_file_name, - (const char *)pb_output_file_path); - strcat((char *)pb_output_file_name, (const char *)pb_arg_val); - - g_pf_out = NULL; - g_pf_out = fopen((const char *)pb_output_file_name, "wb"); - if (g_pf_out == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Output File", err_code); - exit(1); - } - file_count++; - } - if (!strncmp((const char *)fargv[i], "-infile:", 8)) { - pWORD8 pb_arg_val = fargv[i] + 8; - WORD8 pb_interface_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_interface_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_interface_file_name, (const char *)pb_arg_val); - - g_pf_interface = NULL; - g_pf_interface = fopen((const char *)pb_interface_file_name, "rb"); - - if (g_pf_interface == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "DRC Interface File", err_code); - exit(1); - } - interface_file_present = 1; - file_count++; - } - } - g_w_malloc_count = 0; - - printf("\n"); - - if (file_count != 4 && file_count != 3 && file_count != 2) - { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input or Output File", err_code); - } - - if (err_code == IA_NO_ERROR) { - if (g_pf_inp->isMp4File == 1) { - strcpy((pCHAR8)fargv[fargc], "-mp4:1"); - pargv[fargc] = fargv[fargc]; - fargc++; - } - - for (i = 0; i < fargc; i++) { - if (strcmp((pCHAR8)fargv[i], "-eld_testing:1")) - eld_testing = 0; - else { - eld_testing = 1; - break; - } - } - - ixheaacd_main_process(fargc, pargv); - } - - for (i = 0; i < g_w_malloc_count; i++) { - if (g_pv_arr_alloc_memory[i]) free(g_pv_arr_alloc_memory[i]); - } - if (g_pf_out) fclose(g_pf_out); - - if (g_pf_meta) { - raw_testing = 0; - fclose(g_pf_meta); - memset_metadata(meta_info); - g_pf_meta=NULL; - } - FileWrapper_Close(g_pf_inp); - - if (g_pf_interface) { - fclose(g_pf_interface); - interface_file_present = 0; - } - } - } - } else { - int i; - int err_code = IA_NO_ERROR; - int file_count = 0; - - for (i = 1; i < argc; i++) { - pargv[i] = fargv[i]; - strcpy((pCHAR8)fargv[i], (pCHAR8)argv[i]); - printf("%s ", pargv[i]); - - if (!strncmp((const char *)pargv[i], "-ifile:", 7)) { - pWORD8 pb_arg_val = pargv[i] + 7; - WORD8 pb_input_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - err_code = IA_NO_ERROR; - strcat((char *)pb_input_file_name, (const char *)pb_input_file_path); - strcat((char *)pb_input_file_name, (const char *)pb_arg_val); - - g_pf_inp = NULL; - g_pf_inp = FileWrapper_Open((char *)pb_input_file_name); - if (g_pf_inp == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input File", err_code); - exit(1); - } - file_count++; - raw_testing = 0; - } - - if (!strncmp((const char *)fargv[i], "-imeta:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_metadata_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_metadata_file_name, (const char *)pb_input_file_path); - strcat((char *)pb_metadata_file_name, (const char *)pb_arg_val); - - g_pf_meta = NULL; - g_pf_meta = fopen((const char *)pb_metadata_file_name, "r"); - - if (g_pf_meta == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Metadata File", err_code); - exit(1); - } - - metadata_info_init(&meta_info); - err_code = ixheaacd_read_metadata_info(g_pf_meta, &meta_info); - - if (err_code == -1) { - exit(1); - } - - raw_testing = 1; - - file_count++; - } - - if (!strncmp((const char *)pargv[i], "-ofile:", 7)) { - pWORD8 pb_arg_val = pargv[i] + 7; - WORD8 pb_output_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_output_file_name, (const char *)pb_output_file_path); - strcat((char *)pb_output_file_name, (const char *)pb_arg_val); - - g_pf_out = NULL; - g_pf_out = fopen((const char *)pb_output_file_name, "wb"); - if (g_pf_out == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Output File", err_code); - exit(1); - } - file_count++; - } - - if (!strncmp((const char *)fargv[i], "-infile:", 8)) { - pWORD8 pb_arg_val = fargv[i] + 8; - WORD8 pb_interface_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_interface_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_interface_file_name, (const char *)pb_arg_val); - - g_pf_interface = NULL; - g_pf_interface = fopen((const char *)pb_interface_file_name, "rb"); - - if (g_pf_interface == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "DRC Interface File", err_code); - exit(1); - } - interface_file_present = 1; - file_count++; - } - } - g_w_malloc_count = 0; - - printf("\n"); - - if (file_count != 4 && file_count != 3 && file_count != 2) - { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input or Output File", err_code); + raw_testing = 1; } - if (err_code == IA_NO_ERROR) { - if (g_pf_inp->isMp4File == 1) { - strcpy((pCHAR8)fargv[argc], "-mp4:1"); - pargv[argc] = fargv[argc]; - argc++; + if (!strncmp((const char *)argv[i], "-ofile:", 7)) { + pWORD8 pb_arg_val = (pWORD8)argv[i] + 7; + + g_pf_out = fopen((const char *)pb_arg_val, "wb"); + if (g_pf_out == NULL) { + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Output File", err_code); + exit(1); } - - for (i = 0; i < argc; i++) { - if (strcmp((pCHAR8)fargv[i], "-eld_testing:1")) - eld_testing = 0; - else { - eld_testing = 1; - break; - } - } - - ixheaacd_main_process(argc - 1, &pargv[1]); - } - - for (i = 0; i < g_w_malloc_count; i++) { - if (g_pv_arr_alloc_memory[i]) free(g_pv_arr_alloc_memory[i]); - } - if (g_pf_out) fclose(g_pf_out); - - if (g_pf_meta) { - fclose(g_pf_meta); - memset_metadata(meta_info); - } - FileWrapper_Close(g_pf_inp); - if (g_pf_interface) { - fclose(g_pf_interface); - interface_file_present = 0; } } + if ((g_pf_inp == NULL) || (g_pf_out == NULL)) { + print_usage(); + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Input or Output File", err_code); + exit(1); + } + + g_w_malloc_count = 0; + + printf("\n"); + + for (i = 0; i < argc; i++) { + if (!strcmp((pCHAR8)argv[i], "-mp4:1")) { + if (g_pf_meta == NULL) { + print_usage(); + err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; + ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, + (pWORD8) "Metadata File", err_code); + exit(1); + } + } + } + + for (i = 0; i < argc; i++) { + if (strcmp((pCHAR8)argv[i], "-eld_testing:1")) + eld_testing = 0; + else { + eld_testing = 1; + break; + } + } + + ixheaacd_main_process(argc - 1, (pWORD8 *)(&argv[1])); + + for (i = 0; i < g_w_malloc_count; i++) { + if (g_pv_arr_alloc_memory[i]) free(g_pv_arr_alloc_memory[i]); + } + if (g_pf_out) fclose(g_pf_out); + + if (g_pf_meta) { + fclose(g_pf_meta); + metadata_mp4_stsz_size_free(&meta_info); + } + FileWrapper_Close(g_pf_inp); + mpeg_d_drc_on = 0; + return IA_NO_ERROR; } /* end ixheaacd_main */ diff --git a/test/ixheaacd_main_flush_csd.c b/test/ixheaacd_main_flush_csd.c deleted file mode 100644 index d469437..0000000 --- a/test/ixheaacd_main_flush_csd.c +++ /dev/null @@ -1,2477 +0,0 @@ -/*****************************************************************************/ -/* */ -/* Enhanced aacPlus Decoder */ -/* */ -/* ITTIAM SYSTEMS PVT LTD, BANGALORE */ -/* COPYRIGHT(C) 2004 */ -/* */ -/* This program is proprietary to Ittiam Systems Pvt. Ltd. and is protected */ -/* under Indian Copyright Act as an unpublished work.Its use and disclosure */ -/* is limited by the terms and conditions of a license agreement. It may */ -/* be copied or otherwise reproduced or disclosed to persons outside the */ -/* licensee 's organization except in accordance with the terms and */ -/* conditions of such an agreement. All copies and reproductions shall be */ -/* the property of Ittiam Systems Pvt. Ltd. and must bear this notice */ -/* in its entirety. */ -/* */ -/*****************************************************************************/ - -/* - Main for enhanced aacPlus decoding - */ - -#include -#include -#include - -#define AOSP_CHANGE - -#include "ixheaacd_fileifc.h" -#include -#include "ixheaacd_error_standards.h" -#include "ixheaacd_error_handler.h" -#include "ixheaacd_apicmd_standards.h" -#include "ixheaacd_memory_standards.h" -#include "ixheaacd_aac_config.h" -#include "ixheaacd_metadata_read.h" - -IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, WORD32 i_idx, - pVOID pv_value); - -VOID ixheaacd_error_handler_init(); -VOID ia_testbench_error_handler_init(); - -extern ia_error_info_struct ixheaacd_ia_testbench_error_info; -extern ia_error_info_struct ixheaacd_error_info; -// extern int num_of_output_ch; - -/*****************************************************************************/ -/* Process select hash defines */ -/*****************************************************************************/ -#define WAV_HEADER -#define DISPLAY_MESSAGE -//#define REINIT_FOR_ERROR -//#define ERROR_PATTERN_READ -//#define TEST_INSUFFICIENT_INPUT 1 -//#define TEST_FRAMEWISE_INPUT - -#ifdef TEST_FRAMEWISE_INPUT -// Include header file for array of frame sizes : Audio_FrameSize -//#include "0_3gp_4.h" -#endif - -/*****************************************************************************/ -/* Constant hash defines */ -/*****************************************************************************/ -#define MAX_STACK_PROC 10 -#define MAX_MEM_ALLOCS 100 -#define IA_MAX_CMD_LINE_LENGTH 300 -#define IA_MAX_ARGS 20 -#define IA_SCREEN_WIDTH 80 -#define PARAMFILE "paramfilesimple.txt" - -/*****************************************************************************/ -/* Error codes for the testbench */ -/*****************************************************************************/ -#define IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED 0xFFFF8000 -#define IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED 0xFFFF8001 - -#define IA_HE_AAC_DEC_TABLE_RELOCATABLE_ENABLE 0 - -#ifdef ARM_PROFILE -#include "armtimer.h" -#endif - -#ifdef ARM_PROFILE_HW -#include -#define CLK_FREQ_BOARD_MHZ 716 // a9 omap4430 board -//#define CLK_FREQ_BOARD_MHZ 1555 //Nexus6P -//#define CLK_FREQ_BOARD_MHZ 2035 //Tegra Board -//#define CLK_FREQ_BOARD_MHZ 550 //a8 board -//#define CLK_FREQ_BOARD_MHZ 297 //dm365 board -//#define CLK_FREQ_BOARD_MHZ 1209.6 //a5 board -#endif -#ifdef ARM_PROFILE_HW -long long itGetMs(void) { - struct timeval t; - long long currTime; - - if (gettimeofday(&t, NULL) == -1) { - printf("Error in gettimeofday. It has returned -1. \n"); - } - currTime = ((t.tv_sec * 1000 * 1000) + (t.tv_usec)); - return currTime; -} -#endif -/*****************************************************************************/ -/* Global variables */ -/*****************************************************************************/ -pVOID g_pv_arr_alloc_memory[MAX_MEM_ALLOCS]; -WORD g_w_malloc_count; -FILE *g_pf_out; -FileWrapperPtr g_pf_inp; /* file pointer to bitstream file (mp4) */ - -metadata_info meta_info; // metadata pointer; -WORD32 ixheaacd_i_bytes_to_read; -FILE *g_pf_meta; - -WORD32 raw_testing = 0; - -#define _IA_PRINT_ERROR(p_mod_err_info, context, e) \ - if ((e) != IA_NO_ERROR) { \ - ixheaacd_error_handler((p_mod_err_info), (context), (e)); \ - } - -#ifdef ERROR_PATTERN_READ -FILE *g_pf_err = NULL; /* file pointer to error pattern file */ -#endif - -//#define CHECK_STACK_USAGE -#ifdef CHECK_STACK_USAGE -int *stack_corrupt, stack_used; -void stack_corrupt_func() { - int i, stack_val2; - stack_corrupt = &stack_val2; - for (i = 10; i < 2048; i++) { - stack_corrupt[-(i)] = 0xcfadbe3d; - } -} -#endif - -#ifndef WIN32 -#ifdef ITTIAM_BIG_ENDIAN - -int ia_fwrite(pVOID buffer[], int size, int nwords, FILE *fp) { - int i, k; - pWORD8 pb_buf = (pWORD8)buffer; - - for (i = 0; i < nwords; i++) { - for (k = size - 1; k >= 0; k--) { - putc(pb_buf[i * size + k], fp); - } - } - return 1; -} - -#else -int ia_fwrite(pVOID buffer[], int size, int nwords, FILE *fp) { - int i, j; - pWORD8 pb_buf = (pWORD8)buffer; - - for (i = 0; i < nwords; i++) { - for (j = 0; j < size; j++) { - putc(pb_buf[i * size + j], fp); - } - } - return 1; -} - -#endif -#endif -#ifdef ERROR_PATTERN_READ -/*****************************************************************************/ -/* */ -/* Function name : ReadErrorPatternFile */ -/* */ -/* Description : The function reads the frameError flag from a file. */ -/* */ -/* Inputs : FILE *epf (Input file to read from) */ -/* */ -/* Globals : none */ -/* */ -/* Outputs : none */ -/* */ -/* Returns : 1 if the frame is ok, else 0 */ -/* */ -/* Issues : none */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 29 07 2005 Ittiam Created */ -/* */ -/*****************************************************************************/ - -static char ReadErrorPatternFile(FILE *epf) { - char tmp; - int readOk; - - if (!epf) return 1; - - readOk = fscanf(epf, "%c\n", &tmp); - if (readOk != 1) { - rewind(epf); - fscanf(epf, "%c\n", &tmp); - } - if (tmp == '0') - return 1; - else - return 0; -} -#endif - -#ifdef WAV_HEADER -#ifndef ARM_PROFILE_BOARD -/*****************************************************************************/ -/* */ -/* Function name : ixheaacd_write16_bits_lh */ -/* */ -/* Description : write 16 bits low high (always little endian) */ -/* */ -/* Inputs : none */ -/* */ -/* Globals : pVOID g_pv_arr_alloc_memory[MAX_MEM_ALLOCS]; */ -/* WORD g_w_malloc_count; */ -/* FILE *g_pf_inp, *g_pf_out; */ -/* */ -/* Processing : write 16 bits low high (always little endian) */ -/* */ -/* Outputs : none */ -/* */ -/* Returns : none */ -/* */ -/* Issues : none */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 29 07 2005 Ittiam Created */ -/* */ -/*****************************************************************************/ - -static VOID ixheaacd_write16_bits_lh(FILE *fp, WORD32 i) { - putc(i & 0xff, fp); - putc((i >> 8) & 0xff, fp); -} - -/*****************************************************************************/ -/* */ -/* Function name : ixheaacd_write32_bits_lh */ -/* */ -/* Description : write 32 bits low high (always little endian) */ -/* */ -/* Inputs : none */ -/* */ -/* Globals : FILE* fp (file to write) */ -/* WORD32 i (value to write) */ -/* */ -/* Processing : write 32 bits low high (always little endian) */ -/* */ -/* Outputs : none */ -/* */ -/* Returns : none */ -/* */ -/* Issues : none */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 29 07 2005 Ittiam Created */ -/* */ -/*****************************************************************************/ - -static VOID ixheaacd_write32_bits_lh(FILE *fp, WORD32 i) { - ixheaacd_write16_bits_lh(fp, (WORD32)(i & 0xffffL)); - ixheaacd_write16_bits_lh(fp, (WORD32)((i >> 16) & 0xffffL)); -} - -/*****************************************************************************/ -/* */ -/* Function name : write_wav_header */ -/* */ -/* Description : Write wav header to a wav file */ -/* */ -/* Inputs : none */ -/* */ -/* Globals : FILE* fp (file to write) */ -/* WORD32 pcmbytes (total bytes in wav file) */ -/* WORD32 freq (sampling freq) */ -/* WORD32 channels (output channels) */ -/* WORD32 bits (bits per sample) */ -/* */ -/* Processing : Write wav header */ -/* */ -/* Outputs : none */ -/* */ -/* Returns : none */ -/* */ -/* Issues : none */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 29 07 2005 Ittiam Created */ -/* */ -/*****************************************************************************/ - -WORD32 write_wav_header(FILE *fp, WORD32 pcmbytes, WORD32 freq, WORD32 channels, - WORD32 bits, WORD32 i_channel_mask) { - if (channels > 2) { - WORD32 bytes = (bits + 7) / 8; - fwrite("RIFF", 1, 4, fp); /* label */ - ixheaacd_write32_bits_lh( - fp, pcmbytes + 44 - 8); /* length in bytes without header */ - fwrite("WAVEfmt ", 2, 4, fp); /* 2 labels */ - /* tag for WAVE_FORMAT_EXTENSIBLE */ - if (channels > 2) { - ixheaacd_write16_bits_lh(fp, 0x28); - ixheaacd_write16_bits_lh(fp, 0x00); - ixheaacd_write16_bits_lh(fp, 0xfffe); - } else { - ixheaacd_write32_bits_lh( - fp, 2 + 2 + 4 + 4 + 2 + 2); /* length of PCM format decl area */ - ixheaacd_write16_bits_lh(fp, 1); /* is pcm? */ - } - - ixheaacd_write16_bits_lh(fp, channels); - ixheaacd_write32_bits_lh(fp, freq); - ixheaacd_write32_bits_lh(fp, freq * channels * bytes); /* bps */ - ixheaacd_write16_bits_lh(fp, channels * bytes); - ixheaacd_write16_bits_lh(fp, bits); - - /* tag for WAVE_FORMAT_EXTENSIBLE */ - if (channels > 2) { - ixheaacd_write16_bits_lh(fp, 0x16); - ixheaacd_write16_bits_lh(fp, 0x10); /*Samples.wReserved*/ - ixheaacd_write32_bits_lh(fp, i_channel_mask); /* dwChannelMask */ - - ixheaacd_write32_bits_lh(fp, 0x0001); /* SubFormat.Data1 */ - ixheaacd_write32_bits_lh( - fp, 0x00100000); /* SubFormat.Data2 and SubFormat.Data3 */ - - ixheaacd_write16_bits_lh(fp, 0x0080); - ixheaacd_write16_bits_lh(fp, 0xAA00); - - ixheaacd_write16_bits_lh(fp, 0x3800); - ixheaacd_write16_bits_lh(fp, 0x719b); - /* - ixheaacd_write16_bits_lh(fp, 0x6166); - ixheaacd_write16_bits_lh(fp, 0x7463); - - ixheaacd_write16_bits_lh(fp, 0x0004); - ixheaacd_write16_bits_lh(fp, 0x0000); - - ixheaacd_write16_bits_lh(fp, 0x5800); - ixheaacd_write16_bits_lh(fp, 0x0028); - */ } - - fwrite("data", 1, 4, fp); - ixheaacd_write32_bits_lh(fp, pcmbytes); - - return (ferror(fp) ? -1 : 0); - - } else { - WORD32 bytes = (bits + 7) / 8; - fwrite("RIFF", 1, 4, fp); /* label */ - ixheaacd_write32_bits_lh( - fp, pcmbytes + 44 - 8); /* length in bytes without header */ - fwrite("WAVEfmt ", 2, 4, fp); /* 2 labels */ - ixheaacd_write32_bits_lh( - fp, 2 + 2 + 4 + 4 + 2 + 2); /* length of PCM format decl area */ - ixheaacd_write16_bits_lh(fp, 1); /* is pcm? */ - ixheaacd_write16_bits_lh(fp, channels); - ixheaacd_write32_bits_lh(fp, freq); - ixheaacd_write32_bits_lh(fp, freq * channels * bytes); /* bps */ - ixheaacd_write16_bits_lh(fp, channels * bytes); - ixheaacd_write16_bits_lh(fp, bits); - fwrite("data", 1, 4, fp); - ixheaacd_write32_bits_lh(fp, pcmbytes); - - return (ferror(fp) ? -1 : 0); - } -} -#endif /* WAV_HEADER */ -#endif /*ARM_PROFILE_BOARD*/ - -#ifdef DISPLAY_MESSAGE - -/*****************************************************************************/ -/* */ -/* Function name : ia_display_id_message */ -/* */ -/* Description : Display the ID message of the process */ -/* */ -/* Inputs : WORD8 lib_name[] (library name) */ -/* WORD8 lib_version[] (library version) */ -/* WORD8 api_version[] (API version) */ -/* */ -/* Globals : none */ -/* */ -/* Processing : Display all the information about the process */ -/* */ -/* Outputs : none */ -/* */ -/* Returns : none */ -/* */ -/* Issues : none */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 29 07 2005 Tejaswi/Vishal Created */ -/* */ -/*****************************************************************************/ - -VOID ia_display_id_message(WORD8 lib_name[], WORD8 lib_version[]) { - WORD8 str[4][IA_SCREEN_WIDTH] = {"ITTIAM SYSTEMS PVT LTD, BANGALORE\n", - "http:\\\\www.ittiam.com\n", "", ""}; - WORD8 spaces[IA_SCREEN_WIDTH / 2 + 1]; - WORD32 i, spclen; - - strcpy((pCHAR8)str[2], (pCHAR8)lib_name); - strcat((pCHAR8)str[2], (pCHAR8)lib_version); - strcat((pCHAR8)str[2], "\n"); - strcat((pCHAR8)str[4 - 1], "\n"); - - for (i = 0; i < IA_SCREEN_WIDTH / 2 + 1; i++) { - spaces[i] = ' '; - } - - for (i = 0; i < 4; i++) { - spclen = IA_SCREEN_WIDTH / 2 - strlen((pCHAR8)str[i]) / 2; - spaces[spclen] = '\0'; - printf("%s", (pCHAR8)spaces); - spaces[spclen] = ' '; - printf("%s", (pCHAR8)str[i]); - } -} -#endif /* DISPLAY_MESSAGE */ - -/*****************************************************************************/ -/* */ -/* Function name : ixheaacd_set_config_param */ -/* */ -/* Description : Set config parameters */ -/* */ -/* Inputs : pVOID p_ia_process_api_obj (process API obj) */ -/* WORD32 argc (Arguments count) */ -/* pWORD8 argv[] (Argument strings) */ -/* */ -/* Globals : none */ -/* */ -/* Processing : Set config params inside API */ -/* */ -/* Outputs : none */ -/* */ -/* Returns : IA_ERRORCODE error_value (Error value) */ -/* */ -/* Issues : none */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 29 07 2005 Ittiam Created */ -/* */ -/*****************************************************************************/ - -IA_ERRORCODE ixheaacd_set_config_param(WORD32 argc, pWORD8 argv[], - pVOID p_ia_process_api_obj) { - LOOPIDX i; - IA_ERRORCODE err_code = IA_NO_ERROR; - /* the process API function */ - IA_ERRORCODE(*p_ia_process_api) - (pVOID p_ia_process_api_obj, WORD32 i_cmd, WORD32 i_idx, pVOID pv_value) = - ixheaacd_dec_api; - ia_error_info_struct *p_proc_err_info = &ixheaacd_error_info; - - for (i = 0; i < argc; i++) { - /* PCM Word Size (For single input file) */ - if (!strncmp((pCHAR8)argv[i], "-pcmsz:", 7)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 7); - UWORD32 ui_pcm_wd_sz = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_PCM_WDSZ, &ui_pcm_wd_sz); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* Down-mix stereo to mono. */ - if (!strncmp((pCHAR8)argv[i], "-dmix:", 6)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 6); - UWORD32 ui_down_mix = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DOWNMIX, &ui_down_mix); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } -#ifdef RESAMPLE_SUPPORT - /* Resample the output to 8 kHz. */ - if (!strncmp((pCHAR8)argv[i], "-f08:", 5)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 5); - UWORD32 ui_08khz_out = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_OUT08KHZ, &ui_08khz_out); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* Resample the output to 16 kHz. */ - if (!strncmp((pCHAR8)argv[i], "-f16:", 5)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 5); - UWORD32 ui_16khz_out = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_OUT16KHZ, &ui_16khz_out); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } -#endif - /* Interleave mono output to stereo */ - if (!strncmp((pCHAR8)argv[i], "-tostereo:", 10)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 10); - UWORD32 ui_to_stereo = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_TOSTEREO, &ui_to_stereo); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* Downsampled synthesis to be used */ - if (!strncmp((pCHAR8)argv[i], "-dsample:", 9)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 9); - UWORD32 ui_dsample = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DSAMPLE, &ui_dsample); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* To indicate if its a MP4 file or not. */ - if (!strncmp((pCHAR8)argv[i], "-mp4:", 5)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 5); - UWORD32 ui_mp4_flag = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_ISMP4, &ui_mp4_flag); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - -#ifdef HEAACV2_AS_AACLC - /* To indicate if its a MP4 file or not. */ - if (!strncmp((pCHAR8)argv[i], "-aac_lc_only:", 13)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 13); - UWORD32 ui_aac_lc_only = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_AAC_ONLY, &ui_aac_lc_only); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } -#endif - -#ifdef LATM_LOAS - /* To indicate if its a LOAS file or not. */ - if (!strncmp((pCHAR8)argv[i], "-isLOAS:", 8)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 8); - UWORD32 ui_loas_flag = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_ISLOAS, &ui_loas_flag); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - -#endif - -#ifdef DRC_ENABLE - if (!strncmp((pCHAR8)argv[i], "-drc:", 5)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 5); - UWORD32 ui_drc_enable = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_ENABLE, &ui_drc_enable); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - if (!strncmp((pCHAR8)argv[i], "-drc_cut_fac:", 13)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 13); - UWORD32 ui_drc_enable = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT, &ui_drc_enable); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - if (!strncmp((pCHAR8)argv[i], "-drc_boost_fac:", 15)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 15); - UWORD32 ui_drc_enable = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST, &ui_drc_enable); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - if (!strncmp((pCHAR8)argv[i], "-drc_target_level:", 18)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 18); - UWORD32 ui_drc_enable = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL, &ui_drc_enable); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } -#endif - /* To indicate if its a MP4 file or not. */ - if (!strncmp((pCHAR8)argv[i], "-nosync:", 8)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 8); - UWORD32 ui_disable_sync = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DISABLE_SYNC, &ui_disable_sync); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* To indicate SBR upsampling. */ - if (!strncmp((pCHAR8)argv[i], "-sbrup:", 7)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 7); - UWORD32 ui_auto_sbr_upsample = atoi(pb_arg_val); - err_code = - (*p_ia_process_api)(p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_AUTO_SBR_UPSAMPLE, - &ui_auto_sbr_upsample); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* To indicate sample rate for a RAW bit-stream. */ - if (!strncmp((pCHAR8)argv[i], "-fs:", 4)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 4); - UWORD32 ui_samp_freq = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_SAMP_FREQ, &ui_samp_freq); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* To indicate the number of maximum channels */ - if (!strncmp((pCHAR8)argv[i], "-maxchannel:", 12)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 12); - UWORD32 ui_max_channel = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_MAX_CHANNEL, &ui_max_channel); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - - /* To indicate the number of coupling channels to be used for coupling */ - if (!strncmp((pCHAR8)argv[i], "-coupchannel:", 13)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 13); - UWORD32 ui_coupling_channel = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_COUP_CHANNEL, &ui_coupling_channel); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - - /* Down-mix N.1 to stereo */ - if (!strncmp((pCHAR8)argv[i], "-downmix:", 9)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 9); - UWORD32 ui_downmix = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_DOWNMIX_STEREO, &ui_downmix); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - - /* For LD files, to indicate */ - if (!strncmp((pCHAR8)argv[i], "-fs480:", 7)) { - pCHAR8 pb_arg_val = (pCHAR8)(argv[i] + 7); - UWORD32 ui_fs480 = atoi(pb_arg_val); - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_FRAMESIZE, &ui_fs480); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - } - - return IA_NO_ERROR; -} - -/*****************************************************************************/ -/* */ -/* Function name : ixheaacd_get_config_param */ -/* */ -/* Description : Get config parameters */ -/* */ -/* Inputs : pVOID p_ia_process_api_obj (process API obj) */ -/* pWORD32 pi_samp_freq (Ptr for samp freq param) */ -/* pWORD32 pi_num_chan (Ptr for num chan param) */ -/* pWORD32 pi_pcm_wd_sz (Ptr for PCM Word size param) */ -/* */ -/* Globals : none */ -/* */ -/* Processing : Get config params from API */ -/* */ -/* Outputs : none */ -/* */ -/* Returns : IA_ERRORCODE error_value (Error value) */ -/* */ -/* Issues : none */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 29 07 2005 Ittiam Created */ -/* */ -/*****************************************************************************/ - -IA_ERRORCODE ixheaacd_get_config_param(pVOID p_ia_process_api_obj, - pWORD32 pi_samp_freq, - pWORD32 pi_num_chan, - pWORD32 pi_pcm_wd_sz, - pWORD32 pi_channel_mask) { - IA_ERRORCODE err_code = IA_NO_ERROR; - /* the process API function */ - IA_ERRORCODE(*p_ia_process_api) - (pVOID p_ia_process_api_obj, WORD32 i_cmd, WORD32 i_idx, pVOID pv_value) = - ixheaacd_dec_api; - ia_error_info_struct *p_proc_err_info = &ixheaacd_error_info; - - /* Sampling frequency */ - { - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_SAMP_FREQ, pi_samp_freq); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* Total Number of Channels */ - { - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_NUM_CHANNELS, pi_num_chan); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* PCM word size */ - { - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_PCM_WDSZ, pi_pcm_wd_sz); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - /* channel mask to tell the arrangement of channels in bit stream */ - { - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MASK, pi_channel_mask); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - - /* Channel mode to tell MONO/STEREO/DUAL-MONO/NONE_OF_THESE */ - { - UWORD32 ui_channel_mode; - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MODE, &ui_channel_mode); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - if (ui_channel_mode == 0) - printf("Channel Mode: MONO_OR_PS\n"); - else if (ui_channel_mode == 1) - printf("Channel Mode: STEREO\n"); - else if (ui_channel_mode == 2) - printf("Channel Mode: DUAL-MONO\n"); - else - printf("Channel Mode: NONE_OF_THESE or MULTICHANNEL\n"); - } - - /* Channel mode to tell SBR PRESENT/NOT_PRESENT */ - { - UWORD32 ui_sbr_mode; - err_code = (*p_ia_process_api)( - p_ia_process_api_obj, IA_API_CMD_GET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &ui_sbr_mode); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - if (ui_sbr_mode == 0) - printf("SBR Mode: NOT_PRESENT\n"); - else if (ui_sbr_mode == 1) - printf("SBR Mode: PRESENT\n"); - else - printf("SBR Mode: ILLEGAL\n"); - } - return IA_NO_ERROR; -} - -/*****************************************************************************/ -/* */ -/* Function name : ixheaacd_main_process */ -/* */ -/* Description : Stacked processing with function pointer selection */ -/* */ -/* Inputs : WORD32 argc (Arguments count) */ -/* pWORD8 argv[] (Argument strings) */ -/* */ -/* Globals : pVOID g_pv_arr_alloc_memory[MAX_MEM_ALLOCS]; */ -/* WORD g_w_malloc_count; */ -/* FILE *g_pf_inp, *g_pf_out; */ -/* */ -/* Processing : Stacked processing of multiple components */ -/* Loop1: Set params + Mem alloc */ -/* Loop2: Set params + Init process + Get params */ -/* Loop3: Execute */ -/* */ -/* Outputs : None */ -/* */ -/* Returns : IA_ERRORCODE error_value (Error value) */ -/* */ -/* Issues : none */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 29 07 2005 Tejaswi/Vishal Created */ -/* */ -/*****************************************************************************/ - -#ifdef REINIT_FOR_ERROR -int ixheaacd_main_process(WORD32 argc, pWORD8 argv[], - pWORD8 pb_output_file_name) -#else -int ixheaacd_main_process(WORD32 argc, pWORD8 argv[]) -#endif -{ - LOOPIDX i; - WORD frame_counter = 0; -#ifdef DISPLAY_MESSAGE - /* Library Info and Identification strings */ - WORD8 pb_process_name[IA_SCREEN_WIDTH] = ""; - WORD8 pb_lib_version[IA_SCREEN_WIDTH] = ""; -#endif - - /* Error code */ - IA_ERRORCODE err_code = IA_NO_ERROR; - IA_ERRORCODE err_code_reinit = IA_NO_ERROR; - - /* API obj */ - pVOID pv_ia_process_api_obj; - /* First part */ - /* Error Handler Init */ - /* Get Library Name, Library Version and API Version */ - /* Initialize API structure + Default config set */ - /* Set config params from user */ - /* Initialize memory tables */ - /* Get memory information and allocate memory */ - - /* Memory variables */ - UWORD32 n_mems, ui_rem; - UWORD32 ui_proc_mem_tabs_size; - /* API size */ - UWORD32 pui_ap_isize; - /* Process initing done query variable */ - UWORD32 ui_init_done, ui_exec_done; - pWORD8 pb_inp_buf = 0, pb_out_buf = 0; - pWORD8 pb_inp_buf1 = 0; - // pWORD16 litt2big; - - UWORD32 ui_inp_size = 0; - WORD32 i_bytes_consumed, i_bytes_read; - WORD32 i_buff_size; - WORD32 prev_sampling_rate = 0; - WORD32 skip_samples = 0; - WORD32 total_samples = 0; - WORD32 write_flag = 1; - WORD32 bytes_to_write = 0; - WORD32 ixheaacd_drc_offset = 0; - WORD32 current_samples = 0; - WORD32 samples_written = 0; - WORD32 init_iteration = 1; -#ifdef REINIT_FOR_ERROR - WORD32 i_persist_size; - WORD32 i_process_err = 0, i_op_file_cnt = 0; - WORD32 i_error_in_init = 0; - WORD32 i_count_init_errors = 0; - - pVOID pv_persist_ptr; -#endif - -#ifdef ARM_PROFILE_HW - int frame_count_b = 0; - long long cycles_b = 0; - long long start1_b, stop1_b; - double Curr_b, Ave_b = 0, Sum_b = 0; - double Peak_b = 0; - WORD32 Peak_frame_b = 0; -#endif -#ifdef TEST_INSUFFICIENT_INPUT - WORD32 buff_pos, read_bytes = 330, input_buff_size; -#endif - WORD32 i_out_bytes, i_total_bytes = 0; - WORD32 i_samp_freq, i_num_chan, i_pcm_wd_sz, i_channel_mask; - - /* The process API function */ - IA_ERRORCODE(*p_ia_process_api) - (pVOID p_ia_process_api_obj, WORD32 i_cmd, WORD32 i_idx, pVOID pv_value); - - /* The set config from argc argv */ - IA_ERRORCODE(*p_set_config_param) - (WORD32 argc, pWORD8 argv[], pVOID p_ia_process_api_obj); - - /* The get config from API */ - IA_ERRORCODE(*p_get_config_param) - (pVOID p_ia_process_api_obj, pWORD32 pi_samp_freq, pWORD32 pi_num_chan, - pWORD32 pi_pcm_wd_sz, pWORD32 pi_channel_mask); - -#ifdef TEST_FRAMEWISE_INPUT - // Open the file with config header data - FILE *fp_hdr = fopen("0_3gp_4.hdr", "rb"); -#endif - /* The error init function */ - VOID (*p_error_init)(); - - /* The process error info structure */ - ia_error_info_struct *p_proc_err_info; - -#ifdef ARM_PROFILE - - for (profile_index = 0; profile_index < MAX_MODULE; profile_index++) { - profile_instance[profile_index].peak = 0; - profile_instance[profile_index].average = 0; - profile_instance[profile_index].cycles = 0; - profile_instance[profile_index].sum = 0; - profile_instance[profile_index].peak_frame = 0; - // profile_instance[profile_index].info=profile_info[profile_index]; - } - -#endif - - /* Process struct initing */ - p_ia_process_api = ixheaacd_dec_api; - p_set_config_param = ixheaacd_set_config_param; - p_get_config_param = ixheaacd_get_config_param; - p_error_init = ixheaacd_error_handler_init; - p_proc_err_info = &ixheaacd_error_info; - /* Process struct initing end */ - - /* ******************************************************************/ - /* Initialize the error handler */ - /* ******************************************************************/ - (*p_error_init)(); - -/* ******************************************************************/ -/* Get the library name, library version and API version */ -/* ******************************************************************/ - -#ifdef DISPLAY_MESSAGE - /* Get the library name string */ - err_code = (*p_ia_process_api)(NULL, IA_API_CMD_GET_LIB_ID_STRINGS, - IA_CMD_TYPE_LIB_NAME, pb_process_name); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* Get the library version string */ - err_code = (*p_ia_process_api)(NULL, IA_API_CMD_GET_LIB_ID_STRINGS, - IA_CMD_TYPE_LIB_VERSION, pb_lib_version); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* Display the ittiam identification message */ - ia_display_id_message(pb_process_name, pb_lib_version); -#endif - - /* ******************************************************************/ - /* Initialize API structure and set config params to default */ - /* ******************************************************************/ - - /* Get the API size */ - err_code = - (*p_ia_process_api)(NULL, IA_API_CMD_GET_API_SIZE, 0, &pui_ap_isize); -#ifdef MEM_PROFILE - { - float temp = 0; - temp = (float)((float)pui_ap_isize / 1024); - printf("Get the API size %d = %f \n", pui_ap_isize, temp); // added by siva - } -#endif - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* Allocate memory for API */ - g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(pui_ap_isize + 4); - - if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED; - _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info, - (pWORD8) "API struct alloc", err_code); - } - - /* API object requires 4 bytes (WORD32) alignment */ - ui_rem = ((WORD32)g_pv_arr_alloc_memory[g_w_malloc_count] & 3); - /* Set API object with the memory allocated */ - pv_ia_process_api_obj = - (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] + 4 - ui_rem); - - g_w_malloc_count++; - - /* Set the config params to default values */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT, - IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, NULL); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* ******************************************************************/ - /* Set config parameters got from the user present in argc argv */ - /* ******************************************************************/ - - err_code = (*p_set_config_param)(argc, argv, pv_ia_process_api_obj); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - -/* ******************************************************************/ -/* Table Relocatibility */ -/* ******************************************************************/ -#if IA_HE_AAC_DEC_TABLE_RELOCATABLE_ENABLE - - /* Get number of tables required */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_GET_N_TABLES, - 0, &n_mems); -#ifdef MEM_PROFILE - printf("Get number of tables required: %d \n", n_mems); // added by siva -#endif - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - for (i = 0; i < (WORD32)n_mems; i++) { - int ui_size, ui_alignment; - pVOID pv_alloc_ptr = NULL, pv_curr_ptr = NULL; - LOOPIDX k; - - /* Get table size */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_TABLE_INFO_SIZE, i, &ui_size); -#ifdef MEM_PROFILE - { - float temp = 0; - temp = (float)((float)ui_size / 1024); - printf("get table size: %d =%f\n", ui_size, temp); // added by siva - } -#endif - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* Get table alignment */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_TABLE_INFO_ALIGNMENT, i, - &ui_alignment); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(ui_size + ui_alignment); - - if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) { - _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Mem for table relocation alloc", - IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED); - } - - ui_rem = ((WORD32)g_pv_arr_alloc_memory[g_w_malloc_count] % ui_alignment); - pv_alloc_ptr = (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] + - ui_alignment - ui_rem); - - g_w_malloc_count++; - - /* Get the current table pointer */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_TABLE_PTR, i, &pv_curr_ptr); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - for (k = 0; k < ui_size; k++) { - ((pWORD8)pv_alloc_ptr)[k] = ((pWORD8)pv_curr_ptr)[k]; - /* Disabled for multiple files running -((pWORD8)pv_curr_ptr)[k] = (WORD8)0xab; */ - } - - /* Set the relocated table pointer */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_SET_TABLE_PTR, i, pv_alloc_ptr); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } -#endif - /* ******************************************************************/ - /* Initialize Memory info tables */ - /* ******************************************************************/ - - /* Get memory info tables size */ - err_code = - (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_GET_MEMTABS_SIZE, 0, - &ui_proc_mem_tabs_size); -#ifdef MEM_PROFILE - printf("memory info table size: %d \n", - ui_proc_mem_tabs_size); // added by siva -#endif - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(ui_proc_mem_tabs_size + 4); - - if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED; - _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Mem tables alloc", err_code); - } - - /* API object requires 4 bytes (WORD32) alignment */ - ui_rem = ((WORD32)g_pv_arr_alloc_memory[g_w_malloc_count] & 3); - - /* Set pointer for process memory tables */ - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_SET_MEMTABS_PTR, 0, - (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] + 4 - ui_rem)); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - g_w_malloc_count++; - - /* initialize the API, post config, fill memory tables */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT, - IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, NULL); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* ******************************************************************/ - /* Allocate Memory with info from library */ - /* ******************************************************************/ - - /* Get number of memory tables required */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_N_MEMTABS, 0, &n_mems); -#ifdef MEM_PROFILE - printf("Get number of memory tables required %d \n", n_mems); // added by - // siva -#endif - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - for (i = 0; i < (WORD32)n_mems; i++) { - int ui_size, ui_alignment, ui_type; - pVOID pv_alloc_ptr; - - /* Get memory size */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_MEM_INFO_SIZE, i, &ui_size); -#ifdef MEM_PROFILE - { - float temp = 0; - printf("memory size: %d =%f \n", ui_size, - temp = (float)((float)ui_size / 1024)); // added by siva - } -#endif - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* Get memory alignment */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_MEM_INFO_ALIGNMENT, i, - &ui_alignment); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* Get memory type */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_MEM_INFO_TYPE, i, &ui_type); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - err_code = - (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq, &i_num_chan, - &i_pcm_wd_sz, &i_channel_mask); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - // ui_size += 20*1024*sizeof(WORD8); - - if (ui_type == IA_MEMTYPE_OUTPUT) { - // ui_size = 8192; - if (i_pcm_wd_sz == 16) - ui_size = 16384 * sizeof(WORD16); // refer SAMPLE_BUF_SIZE value in - // audio.c file //Ramesh - else - ui_size = - 16384 * 3 * - sizeof( - WORD8); // refer SAMPLE_BUF_SIZE value in audio.c file //Ramesh - } - - g_pv_arr_alloc_memory[g_w_malloc_count] = malloc(ui_size + ui_alignment); - - if (g_pv_arr_alloc_memory[g_w_malloc_count] == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_MEM_ALLOC_FAILED; - _IA_HANDLE_ERROR(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Mem tables alloc", err_code); - } - - ui_rem = ((WORD32)g_pv_arr_alloc_memory[g_w_malloc_count] % ui_alignment); - pv_alloc_ptr = (pVOID)((WORD8 *)g_pv_arr_alloc_memory[g_w_malloc_count] + - ui_alignment - ui_rem); - - g_w_malloc_count++; - - /* Set the buffer pointer */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_SET_MEM_PTR, i, pv_alloc_ptr); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - if (ui_type == IA_MEMTYPE_INPUT) { - pb_inp_buf = pv_alloc_ptr; - ui_inp_size = ui_size; -#ifdef TEST_INSUFFICIENT_INPUT - input_buff_size = ui_size; -#endif - } -#ifdef REINIT_FOR_ERROR - if (ui_type == IA_MEMTYPE_PERSIST) { - i_persist_size = ui_size; - pv_persist_ptr = pv_alloc_ptr; - } -#endif - if (ui_type == IA_MEMTYPE_OUTPUT) { - pb_out_buf = pv_alloc_ptr; - } - } - -/* End first part */ - -/* Second part */ -/* Initialize process */ -/* Get config params */ - -/* ******************************************************************/ -/* Initialize process in a loop (to handle junk data at beginning) */ -/* ******************************************************************/ - -#ifndef TEST_FRAMEWISE_INPUT - i_bytes_consumed = ui_inp_size; - i_buff_size = ui_inp_size; - -#else - -#ifdef REINIT_FOR_ERROR -INIT_AGAIN: -#endif - /* Clear input buffer */ - memset(pb_inp_buf, 0, ui_inp_size); - /* Read the config header */ - i_buff_size = fread((unsigned char *)pb_inp_buf, 1, 5, fp_hdr); - /* Reset the read pointer of header file - useful in case of errors */ - fseek(fp_hdr, 0, SEEK_SET); - - /* Read this frame data*/ - i_buff_size += fread((unsigned char *)pb_inp_buf + i_buff_size, 1, - Audio_FrameSize[frame_counter], g_pf_inp->inputFile); - - i_bytes_consumed = 0; -#endif - -#ifdef TEST_INSUFFICIENT_INPUT - buff_pos = 0; -#endif - - do { -#ifndef TEST_FRAMEWISE_INPUT - -#ifdef REINIT_FOR_ERROR - INIT_AGAIN: -#endif - i_bytes_read = 0; - -#ifndef TEST_INSUFFICIENT_INPUT - if ((ui_inp_size - (i_buff_size - i_bytes_consumed)) > 0) { - for (i = 0; i < (i_buff_size - i_bytes_consumed); i++) { - pb_inp_buf[i] = pb_inp_buf[i + i_bytes_consumed]; - } - - FileWrapper_Read(g_pf_inp, (unsigned char *)(pb_inp_buf + i_buff_size - - i_bytes_consumed), - (ui_inp_size - (i_buff_size - i_bytes_consumed)), - (pUWORD32)&i_bytes_read); - - i_buff_size = i_buff_size - (i_bytes_consumed - i_bytes_read); - - /* Tell input is over, if algorithm returns with insufficient input and - there is no - more input left in the bitstream*/ - if ((i_buff_size <= 0) || - ((err_code_reinit == 0x00001804) && i_bytes_read == 0)) - - { - i_buff_size = 0; - /* Tell that the input is over in this buffer */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_INPUT_OVER, 0, NULL); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - } -#else - if ((ui_inp_size - (i_buff_size - i_bytes_consumed)) > 0) { - WORD32 read_bytes_act = read_bytes; - - for (i = 0; i < (i_buff_size - i_bytes_consumed); i++) { - pb_inp_buf[i] = pb_inp_buf[i + i_bytes_consumed]; - } - - if (buff_pos + read_bytes > input_buff_size) - read_bytes_act = input_buff_size - buff_pos; - - FileWrapper_Read(g_pf_inp, (unsigned char *)(pb_inp_buf + buff_pos), - read_bytes_act, (pUWORD32)&i_bytes_read); - - buff_pos += i_bytes_read; - - i_buff_size = i_buff_size - (i_bytes_consumed - i_bytes_read); - - if (i_buff_size <= 0) { - i_buff_size = 0; - /* Tell that the input is over in this buffer */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_INPUT_OVER, 0, NULL); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - } -#endif - -#else - - if (i_bytes_consumed != 0) { - for (i = 0; i < (i_buff_size - i_bytes_consumed); i++) { - pb_inp_buf[i] = pb_inp_buf[i + i_bytes_consumed]; - } - i_buff_size -= i_bytes_consumed; - } -#endif - // if( i_buff_size <= 0) - if ((i_buff_size <= 0) || - ((err_code_reinit == 0x00001804) && i_bytes_read == 0)) { - i_buff_size = 0; - /* Tell that the input is over in this buffer */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_INPUT_OVER, 0, NULL); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); -#ifdef WAV_HEADER -#ifndef ARM_PROFILE_BOARD - /* ******************************************************************/ - /* Get config params from API */ - /* ******************************************************************/ - - err_code = - (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq, - &i_num_chan, &i_pcm_wd_sz, &i_channel_mask); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - // This is done in those cases, where file decodes ends at init time - // Since init is incomplete, sampling freq might be zero and will result - // in - // writing invalid wave header - - if (i_samp_freq == 0) i_samp_freq = prev_sampling_rate; - - if (!fseek(g_pf_out, 0, SEEK_SET)) - write_wav_header(g_pf_out, i_total_bytes, i_samp_freq, i_num_chan, - i_pcm_wd_sz, i_channel_mask); -#endif -#endif - return 1; - } - - if (init_iteration == 1) { - if (raw_testing) - ixheaacd_i_bytes_to_read = get_metadata_dec_info_init(meta_info); - else - ixheaacd_i_bytes_to_read = i_buff_size; - - /* Set number of bytes to be processed */ - err_code = - (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, - 0, &ixheaacd_i_bytes_to_read); - init_iteration++; - - } else { - /* Set number of bytes to be processed */ - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0, &i_buff_size); - } - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* Initialize the process */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT, - IA_CMD_TYPE_INIT_PROCESS, NULL); - err_code_reinit = err_code; - -#ifdef REINIT_FOR_ERROR - - if (err_code != 0) { - i_process_err = 1; - i_error_in_init = 1; - /* Adding some error code so that the re-init will be - printed as non-fatal error by testbench */ - err_code = 0x00000000; - i_count_init_errors++; - } - // _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8)"", err_code); - if (err_code_reinit == - 0x00001804 /*IA_ENHAACPLUS_DEC_EXE_FATAL_INSUFFICIENT_INPUT_BYTES*/) { - _IA_PRINT_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } else if (err_code_reinit) { - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } -#else - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); -#endif - - /* Checking for end of initialization */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT, - IA_CMD_TYPE_INIT_DONE_QUERY, &ui_init_done); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* How much buffer is used in input buffers */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, - &i_bytes_consumed); - - // printf("%d \n",i_bytes_consumed); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); -#ifdef REINIT_FOR_ERROR - - if (i_process_err == 1) { - /* To avoid going into loop in case of initialization errors - beyond a certain limit */ - if (i_count_init_errors > 6000) { - ixheaacd_error_handler(p_proc_err_info, (pWORD8) "", err_code_reinit); - -#ifdef WAV_HEADER // removed -#ifndef ARM_PROFILE_BOARD - if (!fseek(g_pf_out, 0, SEEK_SET)) - write_wav_header(g_pf_out, i_total_bytes, i_samp_freq, i_num_chan, - i_pcm_wd_sz, i_channel_mask); -#endif -#endif - /* Try decoding next file */ - return 1; - } - -// frame_counter++; -#ifndef ARM_PROFILE_BOARD -// fprintf(stderr,"\r[%5d]",frame_counter); -#endif - goto HANDLE_ERROR_AT_INIT; - } -#endif - -#ifdef TEST_INSUFFICIENT_INPUT - // shift out consumed data - buff_pos -= i_bytes_consumed; -#endif - - } while (!ui_init_done); - - /* ******************************************************************/ - /* Get config params from API */ - /* ******************************************************************/ - - err_code = (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq, - &i_num_chan, &i_pcm_wd_sz, &i_channel_mask); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - if (raw_testing) { - skip_samples = get_start_offset_in_samples(meta_info); - total_samples = get_play_time_in_samples(meta_info); - } - -/* End second part */ - -#ifdef WAV_HEADER -// This condition is added so as to avoid re-writing wave header in -// middle of wave file in case of errors and when we are not opening -// new file in case of errors. - -#ifndef WRITE_NEW_FILE - if (frame_counter == 0) -#endif -#ifndef ARM_PROFILE_BOARD - - write_wav_header(g_pf_out, 0, i_samp_freq, i_num_chan, i_pcm_wd_sz, - i_channel_mask); -#endif -#endif - prev_sampling_rate = i_samp_freq; - -#ifdef TEST_INSUFFICIENT_INPUT - buff_pos = i_buff_size; -#endif - do { -#ifndef TEST_FRAMEWISE_INPUT -#ifndef TEST_INSUFFICIENT_INPUT - if ((ui_inp_size - (i_buff_size - i_bytes_consumed)) > 0) { - for (i = 0; i < (i_buff_size - i_bytes_consumed); i++) { - pb_inp_buf[i] = pb_inp_buf[i + i_bytes_consumed]; - } -#ifdef ENABLE_LD_DEC - if (0 != frame_counter) { -#endif - FileWrapper_Read(g_pf_inp, (unsigned char *)(pb_inp_buf + i_buff_size - - i_bytes_consumed), - (ui_inp_size - (i_buff_size - i_bytes_consumed)), - (pUWORD32)&i_bytes_read); -#ifdef ENABLE_LD_DEC - } else - i_bytes_read = 0; -#endif - - if (i_bytes_read == 0) { - i_bytes_read = i_bytes_read; - } - - i_buff_size = i_buff_size - (i_bytes_consumed - i_bytes_read); - - if ((i_buff_size <= 0) || - ((err_code_reinit == 0x00001804) && i_bytes_read == 0)) { - i_buff_size = 0; - raw_testing = 0; - /* Tell that the input is over in this buffer */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_INPUT_OVER, 0, NULL); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - // if(i_buff_size == 0) - // break; - } - } -#else - if ((ui_inp_size - (i_buff_size - i_bytes_consumed)) > 0) { - WORD32 read_bytes_act = read_bytes; - - if (buff_pos + read_bytes > input_buff_size) - read_bytes_act = input_buff_size - buff_pos; - - for (i = 0; i < (i_buff_size - i_bytes_consumed); i++) { - pb_inp_buf[i] = pb_inp_buf[i + i_bytes_consumed]; - } - - FileWrapper_Read(g_pf_inp, (unsigned char *)(pb_inp_buf + buff_pos), - read_bytes_act, (pUWORD32)&i_bytes_read); - - buff_pos += i_bytes_read; - - i_buff_size = i_buff_size - (i_bytes_consumed - i_bytes_read); - - if (i_buff_size <= 0) { - i_buff_size = 0; - raw_testing = 0; - /* Tell that the input is over in this buffer */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_INPUT_OVER, 0, NULL); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } - } -#endif -#else // removed - if (i_bytes_consumed != 0) { - /* Clear input buffer*/ - memset(pb_inp_buf, 0, ui_inp_size); - - /* Set frame data to input buffer */ - i_buff_size = fread((unsigned char *)pb_inp_buf, 1, - Audio_FrameSize[frame_counter], g_pf_inp->inputFile); - - if ((i_buff_size <= 0) || - ((err_code_reinit == 0x00001804) && i_bytes_read == 0)) { -#ifdef WAV_HEADER -#ifndef ARM_PROFILE_BOARD - if (!fseek(g_pf_out, 0, SEEK_SET)) - write_wav_header(g_pf_out, i_total_bytes, i_samp_freq, i_num_chan, - i_pcm_wd_sz, i_channel_mask); -#endif -#endif - return 0; - } - } -#endif - - if (raw_testing) { - ixheaacd_i_bytes_to_read = - get_metadata_dec_exec(meta_info, frame_counter); - err_code = - (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, - 0, &ixheaacd_i_bytes_to_read); - } else { - /* Set number of bytes to be processed */ - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0, &i_buff_size); - } - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - -#ifdef ERROR_PATTERN_READ - { - /* Reading error pattern from file and set config param */ - UWORD32 frame_status = ReadErrorPatternFile(g_pf_err); - - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_SET_CONFIG_PARAM, - IA_ENHAACPLUS_DEC_CONFIG_PARAM_FRAMEOK, &frame_status); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } -#endif - -#ifdef CHECK_STACK_USAGE - stack_corrupt_func stack_corrupt -= 2048; -#endif - -#ifdef ARM_PROFILE_HW - // start1 = times(&start); - start1_b = itGetMs(); -// printf("start1_b = %lld\t",start1_b); -#endif - -#ifdef ARM_PROFILE - - IttiamStartTimer1 // Initialize Timer - uiStartTime = IttiamGetTimer1 // Read Start Time -#endif // ARM_PROFILE - /* Execute process */ - - if (frame_counter % 10 == 0) { - do { - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_INIT, IA_CMD_TYPE_FLUSH_MEM, - NULL); // api implemented to handle flush call - - err_code = - (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT, - IA_CMD_TYPE_INIT_DONE_QUERY, &ui_init_done); - - if (i_buff_size != 0) { - err_code = - (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_SET_INPUT_BYTES, 0, &i_buff_size); - } else { - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_SET_INPUT_BYTES, 0, - &ixheaacd_i_bytes_to_read); - } - - } while (!ui_init_done); - - err_code = - (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, - 0, &ixheaacd_i_bytes_to_read); - } - - if (ixheaacd_i_bytes_to_read == 2) // Check to indicate GA header - { - do { - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_INIT, IA_CMD_TYPE_GA_HDR, - NULL); // api implemented to handle multiple ga_hdr decode - - err_code = - (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT, - IA_CMD_TYPE_INIT_DONE_QUERY, &ui_init_done); - - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, - &i_bytes_consumed); - - if ((ui_inp_size - (i_buff_size - i_bytes_consumed)) > 0) { - for (i = 0; i < (i_buff_size - i_bytes_consumed); i++) { - pb_inp_buf[i] = pb_inp_buf[i + i_bytes_consumed]; - } - - FileWrapper_Read( - g_pf_inp, - (unsigned char *)(pb_inp_buf + i_buff_size - i_bytes_consumed), - (ui_inp_size - (i_buff_size - i_bytes_consumed)), - (pUWORD32)&i_bytes_read); - i_buff_size = i_buff_size - (i_bytes_consumed - i_bytes_read); - } - - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_SET_INPUT_BYTES, 0, &i_buff_size); - - } while (!ui_init_done); - - // frame_counter++; - } - - else { - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_EXECUTE, - IA_CMD_TYPE_DO_EXECUTE, NULL); - } - - err_code_reinit = err_code; - -#ifdef ARM_PROFILE - - uiEndTime = IttiamGetTimer1 // Read End Time - IttiamStopTimer1 // Stop Timer */ - - // Compute cycles taken (timer decrement type) - profile_instance[EAAC_PLUS_DECODER] - .cycles = uiStartTime - uiEndTime; - -#endif // ARM_PROFILE - -#ifdef ARM_PROFILE_HW - stop1_b = itGetMs(); - cycles_b = (stop1_b - start1_b); -// printf("stop1_b = %lld\n",stop1_b); -#endif - -#ifdef CHECK_STACK_USAGE - for (i = 5; i < 2048; i++) { - if ((stack_corrupt[i] != 0xcfadbe3d)) { - stack_used = (2048 - i) * 4; - break; - } - } - printf("Stack used bytes = %d\n", stack_used); -#endif - -#ifdef REINIT_FOR_ERROR - if (err_code != 0) { - i_process_err = 1; - /* Adding some error code so that the re-init will be - printed as non-fatal error by testbench */ - - err_code = 0x00000000; - } - if (err_code_reinit == - 0x00001804 /*IA_ENHAACPLUS_DEC_EXE_FATAL_INSUFFICIENT_INPUT_BYTES*/) { - _IA_PRINT_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } else if (err_code) { - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - } -#else - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); -#endif - - /* Checking for end of processing */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_EXECUTE, - IA_CMD_TYPE_DONE_QUERY, &ui_exec_done); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* How much buffer is used in input buffers */ - err_code = (*p_ia_process_api)(pv_ia_process_api_obj, - IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, - &i_bytes_consumed); - // printf("%d \n",i_bytes_consumed); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - -// fprintf(stderr,"i_bytes_consumed :: [%5d]\n",i_bytes_consumed); - -#ifdef TEST_INSUFFICIENT_INPUT - // shift out consumed data - buff_pos -= i_bytes_consumed; -#endif - - /* Get the output bytes */ - err_code = (*p_ia_process_api)( - pv_ia_process_api_obj, IA_API_CMD_GET_OUTPUT_BYTES, 0, &i_out_bytes); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - i_total_bytes += i_out_bytes; - - if (total_samples != 0) // Usac stream - { - if (raw_testing) { - if (i_total_bytes <= skip_samples * i_num_chan * (i_pcm_wd_sz >> 3)) { - err_code = - (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq, - &i_num_chan, &i_pcm_wd_sz, &i_channel_mask); - - write_flag = 0; - } else { - write_flag = 1; - bytes_to_write = - i_total_bytes - skip_samples * i_num_chan * (i_pcm_wd_sz >> 3); - if (bytes_to_write < i_out_bytes) { - ixheaacd_drc_offset = i_out_bytes - bytes_to_write; - // i_total_bytes = i_total_bytes - i_out_bytes + bytes_to_write; - i_out_bytes = bytes_to_write; - current_samples = - bytes_to_write / (i_num_chan * (i_pcm_wd_sz >> 3)); - } else { - ixheaacd_drc_offset = 0; - current_samples = i_out_bytes / (i_num_chan * (i_pcm_wd_sz >> 3)); - } - } - } - - if (raw_testing) { - samples_written += current_samples; - - if (samples_written > total_samples) { - i_out_bytes = (total_samples - (samples_written - current_samples)) * - (i_num_chan * (i_pcm_wd_sz >> 3)); // hack - if (i_out_bytes < 0) i_out_bytes = 0; - } - } - } - - // printf("i_out_bytes = %d\n",i_out_bytes); - - if (write_flag) { -#ifndef WIN32 -#ifndef ARM_PROFILE_BOARD - ia_fwrite((pVOID)(pb_out_buf + ixheaacd_drc_offset), (i_pcm_wd_sz / 8), - i_out_bytes / (i_pcm_wd_sz / 8), g_pf_out); -#endif -#else -#ifndef ARM_PROFILE_BOARD - fwrite(pb_out_buf + ixheaacd_drc_offset, sizeof(WORD8), i_out_bytes, - g_pf_out); - fflush(g_pf_out); -#endif -#endif - } - - if (i_out_bytes) frame_counter++; - - printf("\r frame count =%d", frame_counter); - -#ifndef ARM_PROFILE_BOARD -// fprintf(stdout,"\r[%5d]\n ",frame_counter); -#endif -#ifdef ARM_PROFILE_HW - if (i_out_bytes != 0) { - int i_out_samples = i_out_bytes >> 2; - if (frame_count_b) { - double i_out_samples_per_ch = - (i_out_bytes) / ((i_pcm_wd_sz / 8) * i_num_chan); - Curr_b = (((double)cycles_b / 1000000) * CLK_FREQ_BOARD_MHZ) / - (i_out_samples_per_ch / i_samp_freq); - frame_count_b++; - // fprintf(stderr, "Microseconds: %d\t", cycles_b); - // fprintf(stderr, "MCPS: %f\n", Curr_b); - Sum_b += Curr_b; - Ave_b = Sum_b / frame_count_b; - if (Peak_b < Curr_b) { - Peak_b = Curr_b; - Peak_frame_b = frame_count_b; - } - } else { - frame_count_b++; - } - - cycles_b = 0; - } -#endif - -#ifdef ARM_PROFILE - if (i_out_bytes) { - WORD32 samples; - samples = (i_out_bytes >> 1) / i_num_chan; - - if (frame_counter == 1) { - fprintf(fprofile, "\t"); - fprintf(fprofile, "EnhAACPlusDec\t"); - for (profile_index = 0; profile_index < MAX_MODULE; profile_index++) - profile_instance[profile_index].cycles = 0; - - fprintf(fprofile, "\n"); - - } else { - fprintf(fprofile, "%d\t", frame_counter); - - for (profile_index = 0; profile_index < MAX_MODULE; profile_index++) { - curr = ((double)(profile_instance[profile_index].cycles) * - TIMER_RESOLUTION_256) / - (samples); - curr = (curr * i_samp_freq) / 1000000.0; - profile_instance[profile_index].sum += curr; - profile_instance[profile_index].average = - profile_instance[profile_index].sum / frame_counter; - fprintf(fprofile, "%f\t", curr); - - if (profile_instance[profile_index].peak < curr) { - profile_instance[profile_index].peak = curr; - profile_instance[profile_index].peak_frame = frame_counter; - } - profile_instance[profile_index].cycles = 0; - } - - fprintf(fprofile, "\n"); - } - } -#endif - -#ifdef REINIT_FOR_ERROR - HANDLE_ERROR_AT_INIT: - if (i_process_err == 1) { - WORD8 pb_file_cnt_arr[9]; - i_process_err = 0; - - ixheaacd_error_handler(p_proc_err_info, (pWORD8) "", err_code_reinit); - // Do re-init only for fatal errors - if (err_code_reinit < 0 || i_error_in_init) { - memset(pv_persist_ptr, 0, i_persist_size); - /* Set the config params to default values */ - err_code = - (*p_ia_process_api)(pv_ia_process_api_obj, IA_API_CMD_INIT, - IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, NULL); - - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - /* ******************************************************************/ - /* Set config parameters got from the user present in argc argv */ - /* ******************************************************************/ - - err_code = (*p_set_config_param)(argc, argv, pv_ia_process_api_obj); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - - // removed /* Open new file only if the - // error - // occured - // during process */ - if (!i_error_in_init) { -//#define WRITE_NEW_FILE -#ifdef WRITE_NEW_FILE -#ifdef WAV_HEADER -#ifndef ARM_PROFILE_BOARD - if (!fseek(g_pf_out, 0, SEEK_SET)) - write_wav_header(g_pf_out, i_total_bytes, i_samp_freq, i_num_chan, - i_pcm_wd_sz, i_channel_mask); -#endif -#endif - i_op_file_cnt++; - sprintf((char *)pb_file_cnt_arr, "_%03d.wav", i_op_file_cnt); - fclose(g_pf_out); - i_total_bytes = 0; - if (i_op_file_cnt == 1) - (strcpy((char *)(pb_output_file_name + - strlen((char *)pb_output_file_name) - 4), - (const char *)pb_file_cnt_arr), - "wb"); - else - (strcpy((char *)(pb_output_file_name + - strlen((char *)pb_output_file_name) - 8), - (const char *)pb_file_cnt_arr), - "wb"); - g_pf_out = fopen((const char *)pb_output_file_name, "wb"); - if (g_pf_out == 0) { - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "Output file", - IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED); - } -#endif - - } else { - i_error_in_init = 0; - } - - goto INIT_AGAIN; - } - } -#endif - /* Do till the process execution is done */ - } while (!ui_exec_done); - -#ifdef ARM_PROFILE_HW - fprintf(stdout, "\n Peak MCPS = %f\n", Peak_b); - fprintf(stdout, " Avg MCPS = %f\n", Ave_b); - fprintf(stdout, " Peak frame = %d\n", Peak_frame_b); -#endif - -#ifdef ARM_PROFILE - - fprintf(fprofile, "Enh AAC Plus Decoder\n"); - fprintf(fprofile, "Peak MCPS = %lf\n", - profile_instance[EAAC_PLUS_DECODER].peak); - fprintf(fprofile, "Peak frame = %d\n", - profile_instance[EAAC_PLUS_DECODER].peak_frame); - fprintf(fprofile, "Avg MCPS = %lf\n\n", - profile_instance[EAAC_PLUS_DECODER].average); - -#endif - // EXIT: - - fprintf(stderr, "TOTAL FRAMES : [%5d] \n", frame_counter); - - // i_num_chan = num_of_output_ch; - err_code = (*p_get_config_param)(pv_ia_process_api_obj, &i_samp_freq, - &i_num_chan, &i_pcm_wd_sz, &i_channel_mask); - _IA_HANDLE_ERROR(p_proc_err_info, (pWORD8) "", err_code); - -#ifdef WAV_HEADER -#ifndef ARM_PROFILE_BOARD - if (!fseek(g_pf_out, 0, SEEK_SET)) - write_wav_header(g_pf_out, i_total_bytes, i_samp_freq, i_num_chan, - i_pcm_wd_sz, i_channel_mask); -#endif -#endif - - return IA_NO_ERROR; -} - -/*****************************************************************************/ -/* */ -/* Function Name : ixheaacd_main */ -/* */ -/* Description : Main function */ -/* */ -/* Inputs : None */ -/* */ -/* Globals : None */ -/* */ -/* Processing : Parse the parameter file and run the ixheaacd_main process - */ -/* */ -/* Outputs : None */ -/* */ -/* Returns : 0 on success, -1 on error */ -/* */ -/* Issues : None */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 04 09 2005 Ittiam Created */ -/* */ -/*****************************************************************************/ - -void print_usage() { - printf("\n Usage \n"); - printf("\n -ifile: -ofile: [options]\n"); - printf("\n[options] can be,"); -#ifdef ERROR_PATTERN_READ - printf("\n[-errfile:]"); -#endif - printf("\n[-pcmsz:]"); - printf("\n[-dmix:]"); -#ifdef RESAMPLE_SUPPORT - /* By default not available */ - printf("\n[-f08:]"); - printf("\n[-f16:]"); -#endif - printf("\n[-tostereo:]"); - printf("\n[-dsample:]"); - printf("\n[-fs:]"); - printf("\n[-nosync:]"); - printf("\n[-sbrup:]"); - - printf("\n[-maxchannel:]"); -#ifdef MULTICHANNEL_ENABLE - printf("\n[-coupchannel:]"); - printf("\n[-downmix:]"); -#endif - - printf("\n\nwhere, \n is the input AAC file name"); - printf("\n is the output file name"); -#ifdef ERROR_PATTERN_READ - printf("\n is the error pattern file name"); -#endif - printf("\n is the bits per sample info. Only 16 is valid"); - - printf("\n is to enable/disable always mono output. Default 0"); -#ifdef RESAMPLE_SUPPORT - printf("\n is to enable/disable 8 kHz output. Default 0 "); - printf("\n is to enable/disable 16 kHz output. Default 0 "); -#endif - printf("\n is to enable/disable always "); - printf("\n interleaved to stereo output. Default 1 "); - printf("\n is to enable/disable down-sampled SBR "); - printf("\n output. Default auto identification from header"); - printf("\n is to indicate the core AAC sample rate for"); - printf("\n a RAW stream. If this is specified no other file format"); - printf("\n headers are searched for. \n"); - printf("\n is to disable the ADTS/ADIF sync search i.e"); - printf("\n when enabled the decoder expects the header to "); - printf("\n be at the start of input buffer. Default 0"); - printf( - "\n is to enable(1) or disable(0) auto SBR " - "upsample "); - printf( - "\n in case of stream changing from SBR present to SBR not present. " - "Default 1"); - printf("\n is the number of maxiumum "); - printf("\n channels the input may have. Default is 6 (5.1)"); - -#ifdef MULTICHANNEL_ENABLE - printf("\n is element instance tag of "); - printf("\n independent coupling channel to be mixed. Default is 0"); - printf("\n is flag for Downmix. Give 1 to"); - printf("\n get stereo (downmix) output. Default is 0"); -#endif -} - -/*****************************************************************************/ -/* */ -/* Function Name : ixheaacd_main */ -/* */ -/* Description : Main function */ -/* */ -/* Inputs : None */ -/* */ -/* Globals : None */ -/* */ -/* Processing : Parse the parameter file and run the ixheaacd_main process - */ -/* */ -/* Outputs : None */ -/* */ -/* Returns : 0 on success, -1 on error */ -/* */ -/* Issues : None */ -/* */ -/* Revision history : */ -/* */ -/* DD MM YYYY Author Changes */ -/* 04 09 2005 Ittiam Created */ -/* */ -/*****************************************************************************/ - -int main(WORD32 argc, pWORD8 argv[]) { - FILE *param_file_id; - - WORD8 curr_cmd[IA_MAX_CMD_LINE_LENGTH]; - WORD32 fargc, curpos; - WORD32 processcmd = 0; - - WORD8 fargv[IA_MAX_ARGS][IA_MAX_CMD_LINE_LENGTH]; - - pWORD8 pargv[IA_MAX_ARGS]; - - WORD8 pb_input_file_path[IA_MAX_CMD_LINE_LENGTH] = ""; - WORD8 pb_output_file_path[IA_MAX_CMD_LINE_LENGTH] = ""; -#ifdef REINIT_FOR_ERROR - WORD8 pb_output_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; -#endif - - ia_testbench_error_handler_init(); -#ifdef ARM_PROFILE - fprofile = fopen("profile.txt", "wt"); - - if (fprofile == NULL) { - printf("Unable to open profile file\n"); - exit(0); - } -#endif - -#ifdef RVDS_DEBUG - argc = 1; -#endif // siva - - if (argc == 1) { - param_file_id = fopen(PARAMFILE, "r"); - if (param_file_id == NULL) { - print_usage(); - return IA_NO_ERROR; - } - - /* Process one line at a time */ - while (fgets((char *)curr_cmd, IA_MAX_CMD_LINE_LENGTH, param_file_id)) { - curpos = 0; - fargc = 0; - /* if it is not a param_file command and if */ - /* CLP processing is not enabled */ - if (curr_cmd[0] != '@' && !processcmd) { /* skip it */ - continue; - } - - while (sscanf((char *)curr_cmd + curpos, "%s", fargv[fargc]) != EOF) { - if (fargv[0][0] == '/' && fargv[0][1] == '/') break; - if (strcmp((const char *)fargv[0], "@echo") == 0) break; - if (strcmp((const char *)fargv[fargc], "@New_line") == 0) { - fgets((char *)curr_cmd + curpos, IA_MAX_CMD_LINE_LENGTH, - param_file_id); - continue; - } - curpos += strlen((const char *)fargv[fargc]); - while (*(curr_cmd + curpos) == ' ' || *(curr_cmd + curpos) == '\t') - curpos++; - fargc++; - } - - if (fargc < 1) /* for blank lines etc. */ - continue; - - if (strcmp((const char *)fargv[0], "@Output_path") == 0) { - if (fargc > 1) - strcpy((char *)pb_output_file_path, (const char *)fargv[1]); - else - strcpy((char *)pb_output_file_path, ""); - continue; - } - - if (strcmp((const char *)fargv[0], "@Input_path") == 0) { - if (fargc > 1) - strcpy((char *)pb_input_file_path, (const char *)fargv[1]); - else - strcpy((char *)pb_input_file_path, ""); - continue; - } - - if (strcmp((const char *)fargv[0], "@Start") == 0) { - processcmd = 1; - continue; - } - - if (strcmp((const char *)fargv[0], "@Stop") == 0) { - processcmd = 0; - continue; - } - - /* otherwise if this a normal command and its enabled for execution */ - if (processcmd) { - int i; - int err_code = IA_NO_ERROR; - int file_count = 0; - - for (i = 0; i < fargc; i++) { - printf("%s ", fargv[i]); - pargv[i] = fargv[i]; - - if (!strncmp((const char *)fargv[i], "-ifile:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_input_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_input_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_input_file_name, (const char *)pb_arg_val); - - g_pf_inp = NULL; - g_pf_inp = FileWrapper_Open((char *)pb_input_file_name); - - if (g_pf_inp == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input File", err_code); - exit(1); - } - file_count++; - raw_testing = 0; - } - - if (!strncmp((const char *)fargv[i], "-imeta:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_metadata_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_metadata_file_name, - (const char *)pb_input_file_path); - strcat((char *)pb_metadata_file_name, (const char *)pb_arg_val); - - g_pf_meta = NULL; - g_pf_meta = fopen((const char *)pb_metadata_file_name, "r"); - - if (g_pf_meta == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Metadata File", err_code); - exit(1); - } - - metadata_info_init(&meta_info); - err_code = ixheaacd_read_metadata_info(g_pf_meta, &meta_info); - - if (err_code == -1) exit(1); - - raw_testing = 1; - - file_count++; - } - - if (!strncmp((const char *)fargv[i], "-ofile:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; -#ifndef REINIT_FOR_ERROR - WORD8 pb_output_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; -#endif - -#ifdef REINIT_FOR_ERROR - strcpy((char *)pb_output_file_name, - (const char *)pb_output_file_path); -#else - strcat((char *)pb_output_file_name, - (const char *)pb_output_file_path); -#endif - strcat((char *)pb_output_file_name, (const char *)pb_arg_val); - - g_pf_out = NULL; - g_pf_out = fopen((const char *)pb_output_file_name, "wb"); - if (g_pf_out == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Output File", err_code); - exit(1); - } - file_count++; - } -#ifdef ARM_PROFILE - fprintf(fprofile, "%s\n", fargv[i] + 7); -#endif - -#ifdef ERROR_PATTERN_READ - if (!strncmp((const char *)fargv[i], "-errfile:", 9)) { - pWORD8 pb_arg_val = fargv[i] + 9; - g_pf_err = fopen((const char *)pb_arg_val, "r"); - if (g_pf_err == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Error Pattern File", err_code); - } - } -#endif - } - g_w_malloc_count = 0; - - printf("\n"); - if (file_count != 3 && file_count != 2) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input or Output File", err_code); - } - - if (err_code == IA_NO_ERROR) { - if (g_pf_inp->isMp4File == 1) { - strcpy((pCHAR8)fargv[fargc], "-mp4:1"); - pargv[fargc] = fargv[fargc]; - fargc++; - } - -#ifdef REINIT_FOR_ERROR - ixheaacd_main_process(fargc, pargv, pb_output_file_name); -#else - - ixheaacd_main_process(fargc, pargv); -#endif - } - - for (i = 0; i < g_w_malloc_count; i++) { - if (g_pv_arr_alloc_memory[i]) free(g_pv_arr_alloc_memory[i]); - } - if (g_pf_out) fclose(g_pf_out); - - if (g_pf_meta) { - raw_testing = 0; - fclose(g_pf_meta); - memset_metadata(meta_info); - } - FileWrapper_Close(g_pf_inp); -#ifdef ERROR_PATTERN_READ - if (g_pf_err) fclose(g_pf_err); -#endif - } - } - } else { - int i; - int err_code = IA_NO_ERROR; - int file_count = 0; - - for (i = 1; i < argc; i++) { - pargv[i] = fargv[i]; - strcpy((pCHAR8)fargv[i], (pCHAR8)argv[i]); - printf("%s ", pargv[i]); - - if (!strncmp((const char *)pargv[i], "-ifile:", 7)) { - pWORD8 pb_arg_val = pargv[i] + 7; - WORD8 pb_input_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - err_code = IA_NO_ERROR; - strcat((char *)pb_input_file_name, (const char *)pb_input_file_path); - strcat((char *)pb_input_file_name, (const char *)pb_arg_val); - - g_pf_inp = NULL; - g_pf_inp = FileWrapper_Open((char *)pb_input_file_name); - if (g_pf_inp == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input File", err_code); - exit(1); - } - file_count++; - raw_testing = 0; - } - - if (!strncmp((const char *)fargv[i], "-imeta:", 7)) { - pWORD8 pb_arg_val = fargv[i] + 7; - WORD8 pb_metadata_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; - - strcat((char *)pb_metadata_file_name, (const char *)pb_input_file_path); - strcat((char *)pb_metadata_file_name, (const char *)pb_arg_val); - - g_pf_meta = NULL; - g_pf_meta = fopen((const char *)pb_metadata_file_name, "r"); - - if (g_pf_meta == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Metadata File", err_code); - exit(1); - } - - metadata_info_init(&meta_info); - err_code = ixheaacd_read_metadata_info(g_pf_meta, &meta_info); - - if (err_code == -1) { - exit(1); - } - - raw_testing = 1; - - file_count++; - } - - if (!strncmp((const char *)pargv[i], "-ofile:", 7)) { - pWORD8 pb_arg_val = pargv[i] + 7; -#ifndef REINIT_FOR_ERROR - WORD8 pb_output_file_name[IA_MAX_CMD_LINE_LENGTH] = ""; -#endif - - strcat((char *)pb_output_file_name, (const char *)pb_output_file_path); - strcat((char *)pb_output_file_name, (const char *)pb_arg_val); - - g_pf_out = NULL; - g_pf_out = fopen((const char *)pb_output_file_name, "wb"); - if (g_pf_out == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Output File", err_code); - exit(1); - } - file_count++; - } - -#ifdef ERROR_PATTERN_READ - if (!strncmp((const char *)pargv[i], "-errfile:", 9)) { - pWORD8 pb_arg_val = pargv[i] + 9; - g_pf_err = fopen((const char *)pb_arg_val, "r"); - if (g_pf_err == NULL) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Error Pattern File", err_code); - } - } -#endif - } - g_w_malloc_count = 0; - - printf("\n"); - if (file_count != 2 && file_count != 3) { - err_code = IA_TESTBENCH_MFMAN_FATAL_FILE_OPEN_FAILED; - ixheaacd_error_handler(&ixheaacd_ia_testbench_error_info, - (pWORD8) "Input or Output File", err_code); - } - - if (err_code == IA_NO_ERROR) { - if (g_pf_inp->isMp4File == 1) { - strcpy((pCHAR8)fargv[argc], "-mp4:1"); - pargv[argc] = fargv[argc]; - argc++; - } - - ixheaacd_main_process(argc - 1, &pargv[1] -#ifdef REINIT_FOR_ERROR - , - pb_output_file_name -#endif - ); - } - - for (i = 0; i < g_w_malloc_count; i++) { - // printf("I am here %d\n",__LINE__); - if (g_pv_arr_alloc_memory[i]) free(g_pv_arr_alloc_memory[i]); - // printf("I am here %d\n",__LINE__); - } - if (g_pf_out) fclose(g_pf_out); - - if (g_pf_meta) { - fclose(g_pf_meta); - memset_metadata(meta_info); - } - FileWrapper_Close(g_pf_inp); -#ifdef ERROR_PATTERN_READ - if (g_pf_err) fclose(g_pf_err); -#endif - } - -#ifdef ARM_PROFILE - fclose(fprofile); -#endif - - return IA_NO_ERROR; -} /* end ixheaacd_main */ diff --git a/test/ixheaacd_metadata_read.c b/test/ixheaacd_metadata_read.c index c997350..6eda6a0 100644 --- a/test/ixheaacd_metadata_read.c +++ b/test/ixheaacd_metadata_read.c @@ -25,96 +25,90 @@ #define IA_MAX_CMDLINE_LENGTH 100 -void metadata_info_init(metadata_info *meta_info) { - meta_info = (metadata_info *)malloc(sizeof(metadata_info)); -} - -void metadata_free(metadata_info *meta_info) { - if (meta_info->ia_mp4_stsz_size != NULL) free(meta_info->ia_mp4_stsz_size); - // free(meta_info); +void metadata_mp4_stsz_size_free(metadata_info *meta_info) { + if (meta_info->ia_mp4_stsz_size != NULL) { + free(meta_info->ia_mp4_stsz_size); + meta_info->ia_mp4_stsz_size = NULL; + } } int ixheaacd_read_metadata_info(FILE *g_pf_metadata, metadata_info *meta_info) { char cmd[IA_MAX_CMDLINE_LENGTH]; - WORD32 file_count = 0; WORD32 i, j, k, l; i = j = k = l = 0; + metadata_mp4_stsz_size_free(meta_info); while (fgets((char *)cmd, IA_MAX_CMDLINE_LENGTH, g_pf_metadata)) { - if (!strncmp((pCHAR8)cmd, "-dec_info_init:", 15)) { - pCHAR8 pb_arg_val = (pCHAR8)(cmd + 15); - UWORD32 dec_info_init = atoi(pb_arg_val); - meta_info->dec_info_init = dec_info_init; - file_count++; - } - else if (!strncmp((pCHAR8)cmd, "-g_track_count:", 15)) { - pCHAR8 pb_arg_val = (pCHAR8)(cmd + 15); - UWORD32 g_track_count = atoi(pb_arg_val); - meta_info->g_track_count = g_track_count; - file_count++; - } + if (!strncmp((pCHAR8)cmd, "-dec_info_init:", 15)) { + pCHAR8 pb_arg_val = (pCHAR8)(cmd + 15); + UWORD32 dec_info_init = atoi(pb_arg_val); + meta_info->dec_info_init = dec_info_init; + } else if (!strncmp((pCHAR8)cmd, "-g_track_count:", 15)) { + pCHAR8 pb_arg_val = (pCHAR8)(cmd + 15); + UWORD32 g_track_count = atoi(pb_arg_val); + meta_info->g_track_count = g_track_count; + } - else if (!strncmp((pCHAR8)cmd, "-movie_time_scale:", 18)) { - pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); - UWORD32 movie_time_scale = atoi(pb_arg_val); - meta_info->movie_time_scale = movie_time_scale; - file_count++; - } + else if (!strncmp((pCHAR8)cmd, "-movie_time_scale:", 18)) { + pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); + UWORD32 movie_time_scale = atoi(pb_arg_val); + meta_info->movie_time_scale = movie_time_scale; + } - else if (!strncmp((pCHAR8)cmd, "-media_time_scale:", 18)) { - pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); - UWORD32 media_time_scale = atoi(pb_arg_val); - meta_info->media_time_scale = media_time_scale; - file_count++; - } + else if (!strncmp((pCHAR8)cmd, "-media_time_scale:", 18)) { + pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); + UWORD32 media_time_scale = atoi(pb_arg_val); + meta_info->media_time_scale = media_time_scale; + } - else if (!strncmp((pCHAR8)cmd, "-ia_mp4_stsz_entries:", 21)) { - pCHAR8 pb_arg_val = (pCHAR8)(cmd + 21); - UWORD32 ia_mp4_stsz_entries = atoi(pb_arg_val); - meta_info->ia_mp4_stsz_entries = ia_mp4_stsz_entries; + else if (!strncmp((pCHAR8)cmd, "-ia_mp4_stsz_entries:", 21)) { + pCHAR8 pb_arg_val = (pCHAR8)(cmd + 21); + UWORD32 ia_mp4_stsz_entries = atoi(pb_arg_val); + meta_info->ia_mp4_stsz_entries = ia_mp4_stsz_entries; + metadata_mp4_stsz_size_free(meta_info); + meta_info->ia_mp4_stsz_size = + (UWORD32 *)malloc(sizeof(UWORD32) * ia_mp4_stsz_entries); + memset(meta_info->ia_mp4_stsz_size, 0, + sizeof(UWORD32) * ia_mp4_stsz_entries); + } + /* + else if { + //printf("Wrong file order,Check file order"); + //return -1; + } + */ + else if (!strncmp((pCHAR8)cmd, "-playTimeInSamples:", 19)) { + pCHAR8 pb_arg_val = (pCHAR8)(cmd + 19); + UWORD32 playTimeInSamples = atoi(pb_arg_val); + meta_info->playTimeInSamples[i] = playTimeInSamples; + i++; + } - meta_info->ia_mp4_stsz_size = - (UWORD32 *)malloc(sizeof(int) * ia_mp4_stsz_entries); - file_count++; - } - /* - else if { - //printf("Wrong file order,Check file order"); - //return -1; - } - */ - else if (!strncmp((pCHAR8)cmd, "-playTimeInSamples:", 19)) { - pCHAR8 pb_arg_val = (pCHAR8)(cmd + 19); - UWORD32 playTimeInSamples = atoi(pb_arg_val); - meta_info->playTimeInSamples[i] = playTimeInSamples; - i++; - } + else if (!strncmp((pCHAR8)cmd, "-startOffsetInSamples:", 22)) { + pCHAR8 pb_arg_val = (pCHAR8)(cmd + 22); + UWORD32 startOffsetInSamples = atoi(pb_arg_val); + meta_info->startOffsetInSamples[j] = startOffsetInSamples; + j++; + } - else if (!strncmp((pCHAR8)cmd, "-startOffsetInSamples:", 22)) { - pCHAR8 pb_arg_val = (pCHAR8)(cmd + 22); - UWORD32 startOffsetInSamples = atoi(pb_arg_val); - meta_info->startOffsetInSamples[j] = startOffsetInSamples; - j++; - } + else if (!strncmp((pCHAR8)cmd, "-useEditlist:", 13)) { + pCHAR8 pb_arg_val = (pCHAR8)(cmd + 13); + UWORD32 useEditlist = atoi(pb_arg_val); + meta_info->useEditlist[k] = useEditlist; + k++; + } - else if (!strncmp((pCHAR8)cmd, "-useEditlist:", 13)) { - pCHAR8 pb_arg_val = (pCHAR8)(cmd + 13); - UWORD32 useEditlist = atoi(pb_arg_val); - meta_info->useEditlist[k] = useEditlist; - k++; - } + else if (!strncmp((pCHAR8)cmd, "-ia_mp4_stsz_size:", 18)) { + pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); + UWORD32 ia_mp4_stsz_size = atoi(pb_arg_val); + meta_info->ia_mp4_stsz_size[l] = ia_mp4_stsz_size; + l++; + } - else if (!strncmp((pCHAR8)cmd, "-ia_mp4_stsz_size:", 18)) { - pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); - UWORD32 ia_mp4_stsz_size = atoi(pb_arg_val); - meta_info->ia_mp4_stsz_size[l] = ia_mp4_stsz_size; - l++; - } - - else { - printf("Command not found"); - return -1; - } + else { + printf("Command not found"); + return -1; + } } for (; i < MAX_TRACKS_PER_LAYER; i++) { @@ -137,7 +131,11 @@ int get_metadata_dec_info_init(metadata_info meta_info) { } WORD32 get_metadata_dec_exec(metadata_info meta_info, int frame) { - return meta_info.ia_mp4_stsz_size[frame]; + if (frame < (int)meta_info.ia_mp4_stsz_entries) { + return meta_info.ia_mp4_stsz_size[frame]; + } else { + return 0; + } } int get_movie_time_scale(metadata_info meta_info) { @@ -179,15 +177,3 @@ void update_play_time_in_samples(metadata_info meta_info, int update) } */ - -void memset_metadata(metadata_info meta_info) { - unsigned int i; - - for (i = 0; i < meta_info.g_track_count; i++) { - meta_info.startOffsetInSamples[i] = 0; - meta_info.startOffsetInSamples[i] = 0; - meta_info.playTimeInSamples[i] = 0; - } - - meta_info.g_track_count = 0; -} diff --git a/test/ixheaacd_metadata_read.h b/test/ixheaacd_metadata_read.h index 99d386c..75b2c35 100644 --- a/test/ixheaacd_metadata_read.h +++ b/test/ixheaacd_metadata_read.h @@ -37,8 +37,6 @@ typedef struct { } metadata_info; -void metadata_info_init(metadata_info *meta_info); - int ixheaacd_read_metadata_info(FILE *fp, metadata_info *meta_info); int get_metadata_dec_info_init(metadata_info meta_info); @@ -53,6 +51,4 @@ void update_start_offset_in_samples(metadata_info meta_info, int update); void update_play_time_in_samples(metadata_info meta_info, int update); -void memset_metadata(metadata_info meta_info); - #endif