diff options
Diffstat (limited to 'libAACenc/src')
-rw-r--r-- | libAACenc/src/aacEnc_rom.cpp | 32 | ||||
-rw-r--r-- | libAACenc/src/aacEnc_rom.h | 14 | ||||
-rw-r--r-- | libAACenc/src/aacenc.cpp | 89 | ||||
-rw-r--r-- | libAACenc/src/aacenc.h | 39 | ||||
-rw-r--r-- | libAACenc/src/aacenc_hcr.cpp | 93 | ||||
-rw-r--r-- | libAACenc/src/aacenc_hcr.h | 96 | ||||
-rw-r--r-- | libAACenc/src/aacenc_lib.cpp | 122 | ||||
-rw-r--r-- | libAACenc/src/aacenc_tns.cpp | 102 | ||||
-rw-r--r-- | libAACenc/src/aacenc_tns.h | 30 | ||||
-rw-r--r-- | libAACenc/src/adj_thr.cpp | 97 | ||||
-rw-r--r-- | libAACenc/src/adj_thr.h | 6 | ||||
-rw-r--r-- | libAACenc/src/adj_thr_data.h | 3 | ||||
-rw-r--r-- | libAACenc/src/bandwidth.cpp | 8 | ||||
-rw-r--r-- | libAACenc/src/intensity.cpp | 3 | ||||
-rw-r--r-- | libAACenc/src/pnsparam.cpp | 47 | ||||
-rw-r--r-- | libAACenc/src/psy_configuration.cpp | 5 | ||||
-rw-r--r-- | libAACenc/src/psy_main.cpp | 29 | ||||
-rw-r--r-- | libAACenc/src/qc_data.h | 4 | ||||
-rw-r--r-- | libAACenc/src/qc_main.cpp | 55 | ||||
-rw-r--r-- | libAACenc/src/quantize.cpp | 24 | ||||
-rw-r--r-- | libAACenc/src/quantize.h | 8 | ||||
-rw-r--r-- | libAACenc/src/sf_estim.cpp | 73 | ||||
-rw-r--r-- | libAACenc/src/sf_estim.h | 3 | ||||
-rw-r--r-- | libAACenc/src/tns_func.h | 3 |
24 files changed, 482 insertions, 503 deletions
diff --git a/libAACenc/src/aacEnc_rom.cpp b/libAACenc/src/aacEnc_rom.cpp index 0cdf5fe..c6477e3 100644 --- a/libAACenc/src/aacEnc_rom.cpp +++ b/libAACenc/src/aacEnc_rom.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -93,7 +93,7 @@ amm-info@iis.fraunhofer.de /* Huffman Tables */ -const INT FDKaacEnc_huff_ltab1_2[3][3][3][3]= +const ULONG FDKaacEnc_huff_ltab1_2[3][3][3][3]= { { { {0x000b0009,0x00090007,0x000b0009}, {0x000a0008,0x00070006,0x000a0008}, {0x000b0009,0x00090008,0x000b0009} }, @@ -113,7 +113,7 @@ const INT FDKaacEnc_huff_ltab1_2[3][3][3][3]= }; -const INT FDKaacEnc_huff_ltab3_4[3][3][3][3]= +const ULONG FDKaacEnc_huff_ltab3_4[3][3][3][3]= { { { {0x00010004,0x00040005,0x00080008}, {0x00040005,0x00050004,0x00080008}, {0x00090009,0x00090008,0x000a000b} }, @@ -132,7 +132,7 @@ const INT FDKaacEnc_huff_ltab3_4[3][3][3][3]= } }; -const INT FDKaacEnc_huff_ltab5_6[9][9]= +const ULONG FDKaacEnc_huff_ltab5_6[9][9]= { {0x000d000b, 0x000c000a, 0x000b0009, 0x000b0009, 0x000a0009, 0x000b0009, 0x000b0009, 0x000c000a, 0x000d000b}, {0x000c000a, 0x000b0009, 0x000a0008, 0x00090007, 0x00080007, 0x00090007, 0x000a0008, 0x000b0009, 0x000c000a}, @@ -145,7 +145,7 @@ const INT FDKaacEnc_huff_ltab5_6[9][9]= {0x000d000b, 0x000c000a, 0x000c0009, 0x000b0009, 0x000a0009, 0x000a0009, 0x000b0009, 0x000c000a, 0x000d000b} }; -const INT FDKaacEnc_huff_ltab7_8[8][8]= +const ULONG FDKaacEnc_huff_ltab7_8[8][8]= { {0x00010005, 0x00030004, 0x00060005, 0x00070006, 0x00080007, 0x00090008, 0x000a0009, 0x000b000a}, {0x00030004, 0x00040003, 0x00060004, 0x00070005, 0x00080006, 0x00080007, 0x00090007, 0x00090008}, @@ -157,7 +157,7 @@ const INT FDKaacEnc_huff_ltab7_8[8][8]= {0x000b000a, 0x000a0008, 0x000a0008, 0x000a0008, 0x000b0009, 0x000b0009, 0x000c0009, 0x000c000a} }; -const INT FDKaacEnc_huff_ltab9_10[13][13]= +const ULONG FDKaacEnc_huff_ltab9_10[13][13]= { {0x00010006, 0x00030005, 0x00060006, 0x00080006, 0x00090007, 0x000a0008, 0x000a0009, 0x000b000a, 0x000b000a, 0x000c000a, 0x000c000b, 0x000d000b, 0x000d000c}, {0x00030005, 0x00040004, 0x00060004, 0x00070005, 0x00080006, 0x00080007, 0x00090007, 0x000a0008, 0x000a0008, 0x000a0009, 0x000b000a, 0x000c000a, 0x000c000b}, @@ -392,7 +392,7 @@ const USHORT FDKaacEnc_huff_ctab11[21][17]= {0x0046, 0x00ea, 0x0034, 0x00ea, 0x0011, 0x001b, 0x00a9, 0x0094, 0x00e2, 0x0031, 0x00d0, 0x00e5, 0x0007, 0x0070, 0x0069, 0x003e, 0x0021} }; -const INT FDKaacEnc_huff_ctabscf[121]= +const ULONG FDKaacEnc_huff_ctabscf[121]= { 0x0003ffe8, 0x0003ffe6, 0x0003ffe7, 0x0003ffe5, 0x0007fff5, 0x0007fff1, 0x0007ffed, 0x0007fff6, 0x0007ffee, 0x0007ffef, 0x0007fff0, 0x0007fffc, 0x0007fffd, 0x0007ffff, 0x0007fffe, 0x0007fff7, @@ -657,11 +657,11 @@ const SFB_PARAM_SHORT p_FDKaacEnc_96000_short_128 = { */ const FIXP_DBL FDKaacEnc_tnsEncCoeff3[8]= { - 0x81f1d201, 0x91261481, 0xadb92301, 0xd438af00, 0x00000000, 0x37898080, 0x64130dff, 0x7cca6fff + (FIXP_DBL)0x81f1d201, (FIXP_DBL)0x91261481, (FIXP_DBL)0xadb92301, (FIXP_DBL)0xd438af00, (FIXP_DBL)0x00000000, (FIXP_DBL)0x37898080, (FIXP_DBL)0x64130dff, (FIXP_DBL)0x7cca6fff }; const FIXP_DBL FDKaacEnc_tnsCoeff3Borders[8]={ - 0x80000001 /*-4*/, 0x87b826df /*-3*/, 0x9df24154 /*-2*/, 0xbfffffe5 /*-1*/, - 0xe9c5e578 /* 0*/, 0x1c7b90f0 /* 1*/, 0x4fce83a9 /* 2*/, 0x7352f2c3 /* 3*/ + (FIXP_DBL)0x80000001 /*-4*/, (FIXP_DBL)0x87b826df /*-3*/, (FIXP_DBL)0x9df24154 /*-2*/, (FIXP_DBL)0xbfffffe5 /*-1*/, + (FIXP_DBL)0xe9c5e578 /* 0*/, (FIXP_DBL)0x1c7b90f0 /* 1*/, (FIXP_DBL)0x4fce83a9 /* 2*/, (FIXP_DBL)0x7352f2c3 /* 3*/ }; /* @@ -669,15 +669,15 @@ const FIXP_DBL FDKaacEnc_tnsCoeff3Borders[8]={ */ const FIXP_DBL FDKaacEnc_tnsEncCoeff4[16]= { - 0x808bc881, 0x84e2e581, 0x8d6b4a01, 0x99da9201, 0xa9c45701, 0xbc9dde81, 0xd1c2d500, 0xe87ae540, - 0x00000000, 0x1a9cd9c0, 0x340ff240, 0x4b3c8bff, 0x5f1f5e7f, 0x6ed9eb7f, 0x79bc387f, 0x7f4c7e7f + (FIXP_DBL)0x808bc881, (FIXP_DBL)0x84e2e581, (FIXP_DBL)0x8d6b4a01, (FIXP_DBL)0x99da9201, (FIXP_DBL)0xa9c45701, (FIXP_DBL)0xbc9dde81, (FIXP_DBL)0xd1c2d500, (FIXP_DBL)0xe87ae540, + (FIXP_DBL)0x00000000, (FIXP_DBL)0x1a9cd9c0, (FIXP_DBL)0x340ff240, (FIXP_DBL)0x4b3c8bff, (FIXP_DBL)0x5f1f5e7f, (FIXP_DBL)0x6ed9eb7f, (FIXP_DBL)0x79bc387f, (FIXP_DBL)0x7f4c7e7f }; const FIXP_DBL FDKaacEnc_tnsCoeff4Borders[16]= { - 0x80000001 /*-8*/, 0x822deff0 /*-7*/, 0x88a4bfe6 /*-6*/, 0x932c159d /*-5*/, - 0xa16827c2 /*-4*/, 0xb2dcde27 /*-3*/, 0xc6f20b91 /*-2*/, 0xdcf89c64 /*-1*/, - 0xf4308ce1 /* 0*/, 0x0d613054 /* 1*/, 0x278dde80 /* 2*/, 0x4000001b /* 3*/, - 0x55a6127b /* 4*/, 0x678dde8f /* 5*/, 0x74ef0ed7 /* 6*/, 0x7d33f0da /* 7*/ + (FIXP_DBL)0x80000001 /*-8*/, (FIXP_DBL)0x822deff0 /*-7*/, (FIXP_DBL)0x88a4bfe6 /*-6*/, (FIXP_DBL)0x932c159d /*-5*/, + (FIXP_DBL)0xa16827c2 /*-4*/, (FIXP_DBL)0xb2dcde27 /*-3*/, (FIXP_DBL)0xc6f20b91 /*-2*/, (FIXP_DBL)0xdcf89c64 /*-1*/, + (FIXP_DBL)0xf4308ce1 /* 0*/, (FIXP_DBL)0x0d613054 /* 1*/, (FIXP_DBL)0x278dde80 /* 2*/, (FIXP_DBL)0x4000001b /* 3*/, + (FIXP_DBL)0x55a6127b /* 4*/, (FIXP_DBL)0x678dde8f /* 5*/, (FIXP_DBL)0x74ef0ed7 /* 6*/, (FIXP_DBL)0x7d33f0da /* 7*/ }; const FIXP_DBL FDKaacEnc_mTab_4_3Elc[512]={ FL2FXCONST_DBL(0.3968502629920499),FL2FXCONST_DBL(0.3978840634868335),FL2FXCONST_DBL(0.3989185359354711),FL2FXCONST_DBL(0.3999536794661432), diff --git a/libAACenc/src/aacEnc_rom.h b/libAACenc/src/aacEnc_rom.h index 37e5012..862417f 100644 --- a/libAACenc/src/aacEnc_rom.h +++ b/libAACenc/src/aacEnc_rom.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -105,11 +105,11 @@ amm-info@iis.fraunhofer.de /* Huffman Tables */ -extern const INT FDKaacEnc_huff_ltab1_2[3][3][3][3]; -extern const INT FDKaacEnc_huff_ltab3_4[3][3][3][3]; -extern const INT FDKaacEnc_huff_ltab5_6[9][9]; -extern const INT FDKaacEnc_huff_ltab7_8[8][8]; -extern const INT FDKaacEnc_huff_ltab9_10[13][13]; +extern const ULONG FDKaacEnc_huff_ltab1_2[3][3][3][3]; +extern const ULONG FDKaacEnc_huff_ltab3_4[3][3][3][3]; +extern const ULONG FDKaacEnc_huff_ltab5_6[9][9]; +extern const ULONG FDKaacEnc_huff_ltab7_8[8][8]; +extern const ULONG FDKaacEnc_huff_ltab9_10[13][13]; extern const UCHAR FDKaacEnc_huff_ltab11[17][17]; extern const UCHAR FDKaacEnc_huff_ltabscf[121]; extern const USHORT FDKaacEnc_huff_ctab1[3][3][3][3]; @@ -123,7 +123,7 @@ extern const USHORT FDKaacEnc_huff_ctab8[8][8]; extern const USHORT FDKaacEnc_huff_ctab9[13][13]; extern const USHORT FDKaacEnc_huff_ctab10[13][13]; extern const USHORT FDKaacEnc_huff_ctab11[21][17]; -extern const INT FDKaacEnc_huff_ctabscf[121]; +extern const ULONG FDKaacEnc_huff_ctabscf[121]; /* quantizer diff --git a/libAACenc/src/aacenc.cpp b/libAACenc/src/aacenc.cpp index 569662b..5e8c08d 100644 --- a/libAACenc/src/aacenc.cpp +++ b/libAACenc/src/aacenc.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -107,6 +107,39 @@ amm-info@iis.fraunhofer.de #define MIN_BUFSIZE_PER_EFF_CHAN 6144 +INT FDKaacEnc_CalcBitsPerFrame( + const INT bitRate, + const INT frameLength, + const INT samplingRate + ) +{ + int shift = 0; + while ((frameLength & ~((1 << (shift + 1)) - 1)) == frameLength + && (samplingRate & ~((1 << (shift + 1)) - 1)) == samplingRate) + { + shift++; + } + + return (bitRate*(frameLength>>shift)) / (samplingRate>>shift); +} + +INT FDKaacEnc_CalcBitrate( + const INT bitsPerFrame, + const INT frameLength, + const INT samplingRate + ) +{ + int shift = 0; + while ((frameLength & ~((1 << (shift + 1)) - 1)) == frameLength + && (samplingRate & ~((1 << (shift + 1)) - 1)) == samplingRate) + { + shift++; + } + + return (bitsPerFrame * (samplingRate>>shift)) / ( frameLength>>shift) ; + +} + static AAC_ENCODER_ERROR FDKaacEnc_InitCheckAncillary(INT bitRate, INT framelength, INT ancillaryRate, @@ -220,21 +253,19 @@ INT FDKaacEnc_GetVBRBitrate(INT bitrateMode, CHANNEL_MODE channelMode) /** * \brief Convert encoder bitreservoir value for transport library. * - * \param bitrateMode Bitratemode used in current encoder instance. Se ::AACENC_BITRATE_MODE - * \param bitresTotal Encoder bitreservoir level in bits. + * \param hAacEnc Encoder handle * * \return Corrected bitreservoir level used in transport library. */ static INT FDKaacEnc_EncBitresToTpBitres( - const AACENC_BITRATE_MODE bitrateMode, - const INT bitresTotal + const HANDLE_AAC_ENC hAacEnc ) { INT transporBitreservoir = 0; - switch (bitrateMode) { + switch (hAacEnc->bitrateMode) { case AACENC_BR_MODE_CBR: - transporBitreservoir = bitresTotal; /* encoder bitreservoir level */ + transporBitreservoir = hAacEnc->qcKernel->bitResTot; /* encoder bitreservoir level */ break; case AACENC_BR_MODE_VBR_1: case AACENC_BR_MODE_VBR_2: @@ -253,6 +284,10 @@ static INT FDKaacEnc_EncBitresToTpBitres( FDK_ASSERT(0); } + if (hAacEnc->config->audioMuxVersion==2) { + transporBitreservoir = MIN_BUFSIZE_PER_EFF_CHAN * hAacEnc->channelMapping.nChannelsEff; + } + return transporBitreservoir; } @@ -289,6 +324,7 @@ void FDKaacEnc_AacInitDefaultConfig(AACENC_CONFIG *config) config->minBitsPerFrame = -1; /* minum number of bits in each AU */ config->maxBitsPerFrame = -1; /* minum number of bits in each AU */ config->bitreservoir = -1; /* default, uninitialized value */ + config->audioMuxVersion = -1; /* audio mux version not configured */ /* init tabs in fixpoint_math */ InitLdInt(); @@ -435,7 +471,9 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, &averageBitsPerFrame, config->bitrateMode, config->nSubFrames - ) != config->bitRate ) + ) != config->bitRate + && !((config->bitrateMode>=1) && (config->bitrateMode<=5)) + ) { return AAC_ENC_UNSUPPORTED_BITRATE; } @@ -562,7 +600,10 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, qcInit.averageBits = (averageBitsPerFrame+7)&~7; qcInit.bitRes = MIN_BUFSIZE_PER_EFF_CHAN*cm->nChannelsEff; qcInit.maxBits = MIN_BUFSIZE_PER_EFF_CHAN*cm->nChannelsEff; - qcInit.minBits = 0; + qcInit.maxBits = (config->maxBitsPerFrame!=-1) ? fixMin(qcInit.maxBits, config->maxBitsPerFrame) : qcInit.maxBits; + qcInit.maxBits = fixMax(qcInit.maxBits, (averageBitsPerFrame+7)&~7); + qcInit.minBits = (config->minBitsPerFrame!=-1) ? config->minBitsPerFrame : 0; + qcInit.minBits = fixMin(qcInit.minBits, averageBitsPerFrame&~7); } else { @@ -573,9 +614,11 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, qcInit.maxBits = fixMin(MIN_BUFSIZE_PER_EFF_CHAN*cm->nChannelsEff, ((averageBitsPerFrame+7)&~7)+qcInit.bitRes); qcInit.maxBits = (config->maxBitsPerFrame!=-1) ? fixMin(qcInit.maxBits, config->maxBitsPerFrame) : qcInit.maxBits; + qcInit.maxBits = fixMin(MIN_BUFSIZE_PER_EFF_CHAN*cm->nChannelsEff, fixMax(qcInit.maxBits, (averageBitsPerFrame+7+8)&~7)); qcInit.minBits = fixMax(0, ((averageBitsPerFrame-1)&~7)-qcInit.bitRes-transportEnc_GetStaticBits(hTpEnc, ((averageBitsPerFrame+7)&~7)+qcInit.bitRes)); qcInit.minBits = (config->minBitsPerFrame!=-1) ? fixMax(qcInit.minBits, config->minBitsPerFrame) : qcInit.minBits; + qcInit.minBits = fixMin(qcInit.minBits, (averageBitsPerFrame - transportEnc_GetStaticBits(hTpEnc, qcInit.maxBits))&~7); } qcInit.sampleRate = config->sampleRate; @@ -583,11 +626,9 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, qcInit.nSubFrames = config->nSubFrames; qcInit.padding.paddingRest = config->sampleRate; - /* Calc meanPe */ - bw_ratio = fDivNorm((FIXP_DBL)hAacEnc->bandwidth90dB, (FIXP_DBL)(config->sampleRate>>1), &qbw); - qbw = DFRACT_BITS-1-qbw; - /* qcInit.meanPe = 10.0f * FRAME_LEN_LONG * hAacEnc->bandwidth90dB/(config->sampleRate/2.0f); */ - qcInit.meanPe = fMult(bw_ratio, (FIXP_DBL)((10*config->framelength)<<16)) >> (qbw-15); + /* Calc meanPe: qcInit.meanPe = 10.0f * FRAME_LEN_LONG * hAacEnc->bandwidth90dB/(config->sampleRate/2.0f); */ + bw_ratio = fDivNorm((FIXP_DBL)(10*config->framelength*hAacEnc->bandwidth90dB), (FIXP_DBL)(config->sampleRate), &qbw); + qcInit.meanPe = FDKmax((INT)scaleValue(bw_ratio, qbw+1-(DFRACT_BITS-1)), 1); /* Calc maxBitFac */ mbfac = fDivNorm((MIN_BUFSIZE_PER_EFF_CHAN-744)*cm->nChannelsEff, qcInit.averageBits/qcInit.nSubFrames, &qmbfac); @@ -649,23 +690,7 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, if (ErrorStatus != AAC_ENC_OK) goto bail; - /* Map virtual aot's to intern aot used in bitstream writer. */ - switch (hAacEnc->config->audioObjectType) { - case AOT_MP2_AAC_LC: - case AOT_DABPLUS_AAC_LC: - hAacEnc->aot = AOT_AAC_LC; - break; - case AOT_MP2_SBR: - case AOT_DABPLUS_SBR: - hAacEnc->aot = AOT_SBR; - break; - case AOT_MP2_PS: - case AOT_DABPLUS_PS: - hAacEnc->aot = AOT_PS; - break; - default: - hAacEnc->aot = hAacEnc->config->audioObjectType; - } + hAacEnc->aot = hAacEnc->config->audioObjectType; /* common things */ @@ -930,7 +955,7 @@ AAC_ENCODER_ERROR FDKaacEnc_EncodeFrame( HANDLE_AAC_ENC hAacEnc, transportEnc_WriteAccessUnit( hTpEnc, totalBits, - FDKaacEnc_EncBitresToTpBitres(hAacEnc->bitrateMode, hAacEnc->qcKernel->bitResTot), + FDKaacEnc_EncBitresToTpBitres(hAacEnc), cm->nChannelsEff); /* write bitstream */ diff --git a/libAACenc/src/aacenc.h b/libAACenc/src/aacenc.h index 87fc3e8..79524b5 100644 --- a/libAACenc/src/aacenc.h +++ b/libAACenc/src/aacenc.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -98,6 +98,11 @@ amm-info@iis.fraunhofer.de #include "sbr_encoder.h" +#define BITRES_MAX_LD 4000 +#define BITRES_MIN_LD 500 +#define BITRATE_MAX_LD 70000 /* Max assumed bitrate for bitres calculation */ +#define BITRATE_MIN_LD 12000 /* Min assumed bitrate for bitres calculation */ + #ifdef __cplusplus extern "C" { #endif @@ -204,6 +209,8 @@ struct AACENC_CONFIG { INT maxBitsPerFrame; /* maximum number of bits in AU */ INT bitreservoir; /* size of bitreservoir */ + INT audioMuxVersion; /* audio mux version in loas/latm transport format */ + UINT sbrRatio; /* sbr sampling rate ratio: dual- or single-rate */ UCHAR useTns; /* flag: use temporal noise shaping */ @@ -223,6 +230,36 @@ typedef struct { typedef struct AAC_ENC *HANDLE_AAC_ENC; /** + * \brief Calculate framesize in bits for given bit rate, frame length and sampling rate. + * + * \param bitRate Ttarget bitrate in bits per second. + * \param frameLength Number of audio samples in one frame. + * \param samplingRate Sampling rate in Hz. + * + * \return Framesize in bits per frame. +*/ +INT FDKaacEnc_CalcBitsPerFrame( + const INT bitRate, + const INT frameLength, + const INT samplingRate + ); + +/** + * \brief Calculate bitrate in bits per second for given framesize, frame length and sampling rate. + * + * \param bitsPerFrame Framesize in bits per frame. + * \param frameLength Number of audio samples in one frame. + * \param samplingRate Sampling rate in Hz. + * + * \return Bitrate in bits per second. +*/ +INT FDKaacEnc_CalcBitrate( + const INT bitsPerFrame, + const INT frameLength, + const INT samplingRate + ); + +/** * \brief Limit given bit rate to a valid value * \param hTpEnc transport encoder handle * \param coreSamplingRate the sample rate to be used for the AAC encoder diff --git a/libAACenc/src/aacenc_hcr.cpp b/libAACenc/src/aacenc_hcr.cpp deleted file mode 100644 index 316623a..0000000 --- a/libAACenc/src/aacenc_hcr.cpp +++ /dev/null @@ -1,93 +0,0 @@ - -/* ----------------------------------------------------------------------------------------------------------- -Software License for The Fraunhofer FDK AAC Codec Library for Android - -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. - All rights reserved. - - 1. INTRODUCTION -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements -the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio. -This FDK AAC Codec software is intended to be used on a wide variety of Android devices. - -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual -audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by -independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part -of the MPEG specifications. - -Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer) -may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners -individually for the purpose of encoding or decoding bit streams in products that are compliant with -the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license -these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec -software may already be covered under those patent licenses when it is used for those licensed purposes only. - -Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality, -are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional -applications information and documentation. - -2. COPYRIGHT LICENSE - -Redistribution and use in source and binary forms, with or without modification, are permitted without -payment of copyright license fees provided that you satisfy the following conditions: - -You must retain the complete text of this software license in redistributions of the FDK AAC Codec or -your modifications thereto in source code form. - -You must retain the complete text of this software license in the documentation and/or other materials -provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form. -You must make available free of charge copies of the complete source code of the FDK AAC Codec and your -modifications thereto to recipients of copies in binary form. - -The name of Fraunhofer may not be used to endorse or promote products derived from this library without -prior written permission. - -You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec -software or your modifications thereto. - -Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software -and the date of any change. For modified versions of the FDK AAC Codec, the term -"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term -"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android." - -3. NO PATENT LICENSE - -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer, -ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with -respect to this software. - -You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized -by appropriate patent licenses. - -4. DISCLAIMER - -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors -"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties -of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages, -including but not limited to procurement of substitute goods or services; loss of use, data, or profits, -or business interruption, however caused and on any theory of liability, whether in contract, strict -liability, or tort (including negligence), arising in any way out of the use of this software, even if -advised of the possibility of such damage. - -5. CONTACT INFORMATION - -Fraunhofer Institute for Integrated Circuits IIS -Attention: Audio and Multimedia Departments - FDK AAC LL -Am Wolfsmantel 33 -91058 Erlangen, Germany - -www.iis.fraunhofer.de/amm -amm-info@iis.fraunhofer.de ------------------------------------------------------------------------------------------------------------ */ - -/*************************** MPEG AAC Audio Encoder ************************* - - Initial author: R. Boehm - contents/description: huffman codeword reordering - based on source from aacErrRobTrans - -******************************************************************************/ - -#include "aacenc_hcr.h" - diff --git a/libAACenc/src/aacenc_hcr.h b/libAACenc/src/aacenc_hcr.h deleted file mode 100644 index 934247a..0000000 --- a/libAACenc/src/aacenc_hcr.h +++ /dev/null @@ -1,96 +0,0 @@ - -/* ----------------------------------------------------------------------------------------------------------- -Software License for The Fraunhofer FDK AAC Codec Library for Android - -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. - All rights reserved. - - 1. INTRODUCTION -The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements -the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio. -This FDK AAC Codec software is intended to be used on a wide variety of Android devices. - -AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual -audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by -independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part -of the MPEG specifications. - -Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer) -may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners -individually for the purpose of encoding or decoding bit streams in products that are compliant with -the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license -these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec -software may already be covered under those patent licenses when it is used for those licensed purposes only. - -Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality, -are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional -applications information and documentation. - -2. COPYRIGHT LICENSE - -Redistribution and use in source and binary forms, with or without modification, are permitted without -payment of copyright license fees provided that you satisfy the following conditions: - -You must retain the complete text of this software license in redistributions of the FDK AAC Codec or -your modifications thereto in source code form. - -You must retain the complete text of this software license in the documentation and/or other materials -provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form. -You must make available free of charge copies of the complete source code of the FDK AAC Codec and your -modifications thereto to recipients of copies in binary form. - -The name of Fraunhofer may not be used to endorse or promote products derived from this library without -prior written permission. - -You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec -software or your modifications thereto. - -Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software -and the date of any change. For modified versions of the FDK AAC Codec, the term -"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term -"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android." - -3. NO PATENT LICENSE - -NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer, -ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with -respect to this software. - -You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized -by appropriate patent licenses. - -4. DISCLAIMER - -This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors -"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties -of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages, -including but not limited to procurement of substitute goods or services; loss of use, data, or profits, -or business interruption, however caused and on any theory of liability, whether in contract, strict -liability, or tort (including negligence), arising in any way out of the use of this software, even if -advised of the possibility of such damage. - -5. CONTACT INFORMATION - -Fraunhofer Institute for Integrated Circuits IIS -Attention: Audio and Multimedia Departments - FDK AAC LL -Am Wolfsmantel 33 -91058 Erlangen, Germany - -www.iis.fraunhofer.de/amm -amm-info@iis.fraunhofer.de ------------------------------------------------------------------------------------------------------------ */ - -/*************************** MPEG AAC Audio Encoder ************************* - - Initial author: R. Boehm - contents/description: huffman codeword reordering - based on source from aacErrRobTrans - -******************************************************************************/ - -#ifndef _AACENC_HCR -#define _AACENC_HCR_H - - -#endif /* ifndef _AACENC_HCR */ diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp index e24df65..64445b9 100644 --- a/libAACenc/src/aacenc_lib.cpp +++ b/libAACenc/src/aacenc_lib.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -98,7 +98,7 @@ amm-info@iis.fraunhofer.de /* Encoder library info */ #define AACENCODER_LIB_VL0 3 #define AACENCODER_LIB_VL1 4 -#define AACENCODER_LIB_VL2 12 +#define AACENCODER_LIB_VL2 22 #define AACENCODER_LIB_TITLE "AAC Encoder" #ifdef __ANDROID__ #define AACENCODER_LIB_BUILD_DATE "" @@ -153,6 +153,7 @@ typedef struct { UINT userAfterburner; UINT userFramelength; UINT userAncDataRate; + UINT userPeakBitrate; UCHAR userTns; /*!< Use TNS coding. */ UCHAR userPns; /*!< Use PNS coding. */ @@ -303,7 +304,7 @@ static AACENC_ERROR eldSbrConfigurator( int i, cfgIdx = -1; const ULONG channelBitrate = totalBitrate / FDKaacEnc_GetChannelModeConfiguration(channelMode)->nChannelsEff; - for (i=0; i<(sizeof(eldSbrAutoConfigTab)/sizeof(ELD_SBR_CONFIGURATOR)); i++) { + for (i=0; i<(int)(sizeof(eldSbrAutoConfigTab)/sizeof(ELD_SBR_CONFIGURATOR)); i++) { if ( (samplingRate <= eldSbrAutoConfigTab[i].samplingRate) && (channelBitrate >= eldSbrAutoConfigTab[i].bitrateRange) ) { @@ -326,10 +327,7 @@ static inline INT isSbrActive(const HANDLE_AACENC_CONFIG hAacConfig) { INT sbrUsed = 0; - if ( (hAacConfig->audioObjectType==AOT_SBR) || (hAacConfig->audioObjectType==AOT_PS) - || (hAacConfig->audioObjectType==AOT_MP2_SBR) || (hAacConfig->audioObjectType==AOT_MP2_PS) - || (hAacConfig->audioObjectType==AOT_DABPLUS_SBR) || (hAacConfig->audioObjectType==AOT_DABPLUS_PS) - || (hAacConfig->audioObjectType==AOT_DRM_SBR) || (hAacConfig->audioObjectType==AOT_DRM_MPEG_PS) ) + if ( (hAacConfig->audioObjectType==AOT_SBR) || (hAacConfig->audioObjectType==AOT_PS) ) { sbrUsed = 1; } @@ -345,10 +343,7 @@ static inline INT isPsActive(const AUDIO_OBJECT_TYPE audioObjectType) { INT psUsed = 0; - if ( (audioObjectType==AOT_PS) - || (audioObjectType==AOT_MP2_PS) - || (audioObjectType==AOT_DABPLUS_PS) - || (audioObjectType==AOT_DRM_MPEG_PS) ) + if ( (audioObjectType==AOT_PS) ) { psUsed = 1; } @@ -373,8 +368,7 @@ static SBR_PS_SIGNALING getSbrSignalingMode( sbrSignaling = SIG_IMPLICIT; /* default: implicit signaling */ } - if ((audioObjectType==AOT_AAC_LC) || (audioObjectType==AOT_SBR) || (audioObjectType==AOT_PS) || - (audioObjectType==AOT_MP2_AAC_LC) || (audioObjectType==AOT_MP2_SBR) || (audioObjectType==AOT_MP2_PS) ) { + if ( (audioObjectType==AOT_AAC_LC) || (audioObjectType==AOT_SBR) || (audioObjectType==AOT_PS) ) { switch (transportType) { case TT_MP4_ADIF: case TT_MP4_ADTS: @@ -430,22 +424,7 @@ static void FDKaacEnc_MapConfig( cc->flags = 0; - /* Map virtual aot to transport aot. */ - switch (hAacConfig->audioObjectType) { - case AOT_MP2_AAC_LC: - transport_AOT = AOT_AAC_LC; - break; - case AOT_MP2_SBR: - transport_AOT = AOT_SBR; - cc->flags |= CC_SBR; - break; - case AOT_MP2_PS: - transport_AOT = AOT_PS; - cc->flags |= CC_SBR; - break; - default: - transport_AOT = hAacConfig->audioObjectType; - } + transport_AOT = hAacConfig->audioObjectType; if (hAacConfig->audioObjectType == AOT_ER_AAC_ELD) { cc->flags |= (hAacConfig->syntaxFlags & AC_SBR_PRESENT) ? CC_SBR : 0; @@ -511,16 +490,7 @@ static void FDKaacEnc_MapConfig( cc->samplingRate = hAacConfig->sampleRate; /* Mpeg-4 signaling for transport library. */ - switch ( hAacConfig->audioObjectType ) { - case AOT_MP2_AAC_LC: - case AOT_MP2_SBR: - case AOT_MP2_PS: - cc->flags &= ~CC_MPEG_ID; /* Required for ADTS. */ - cc->extAOT = AOT_NULL_OBJECT; - break; - default: - cc->flags |= CC_MPEG_ID; - } + cc->flags |= CC_MPEG_ID; /* ER-tools signaling. */ cc->flags |= (hAacConfig->syntaxFlags & AC_ER_VCB11) ? CC_VCB11 : 0; @@ -585,6 +555,7 @@ AAC_ENCODER_ERROR aacEncDefaultConfig(HANDLE_AACENC_CONFIG hAacConfig, config->userChannelMode = hAacConfig->channelMode; config->userBitrate = hAacConfig->bitRate; config->userBitrateMode = hAacConfig->bitrateMode; + config->userPeakBitrate = (UINT)-1; config->userBandwidth = hAacConfig->bandWidth; config->userTns = hAacConfig->useTns; config->userPns = hAacConfig->usePns; @@ -792,12 +763,15 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, hAacConfig->syntaxFlags = 0; hAacConfig->epConfig = -1; + if (config->userTpType==TT_MP4_LATM_MCP1 || config->userTpType==TT_MP4_LATM_MCP0 || config->userTpType==TT_MP4_LOAS) { + hAacConfig->audioMuxVersion = config->userTpAmxv; + } + else { + hAacConfig->audioMuxVersion = -1; + } + /* Adapt internal AOT when necessary. */ switch ( hAacConfig->audioObjectType ) { - case AOT_MP2_AAC_LC: - case AOT_MP2_SBR: - case AOT_MP2_PS: - hAacConfig->usePns = 0; case AOT_AAC_LC: case AOT_SBR: case AOT_PS: @@ -839,11 +813,16 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, switch ( hAacConfig->audioObjectType ) { case AOT_ER_AAC_LD: case AOT_ER_AAC_ELD: - if (config->userBitrateMode==8) { - hAacConfig->bitrateMode = 0; - } if (config->userBitrateMode==0) { - hAacConfig->bitreservoir = 100*config->nChannels; /* default, reduced bitreservoir */ + /* bitreservoir = (maxBitRes-minBitRes)/(maxBitRate-minBitrate)*(bitRate-minBitrate)+minBitRes; */ + if ( isLowDelay(hAacConfig->audioObjectType) ) { + INT bitreservoir; + INT brPerChannel = hAacConfig->bitRate/hAacConfig->nChannels; + brPerChannel = fMin(BITRATE_MAX_LD, fMax(BITRATE_MIN_LD, brPerChannel)); + FIXP_DBL slope = fDivNorm((brPerChannel-BITRATE_MIN_LD), BITRATE_MAX_LD-BITRATE_MIN_LD); /* calc slope for interpolation */ + bitreservoir = fMultI(slope, (INT)(BITRES_MAX_LD-BITRES_MIN_LD)) + BITRES_MIN_LD; /* interpolate */ + hAacConfig->bitreservoir = bitreservoir & ~7; /* align to bytes */ + } } if (hAacConfig->bitrateMode!=0) { return AACENC_INVALID_CONFIG; @@ -884,6 +863,18 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, } } + if ((hAacConfig->bitrateMode >= 0) && (hAacConfig->bitrateMode <= 5)) { + if ((INT)config->userPeakBitrate != -1) { + hAacConfig->maxBitsPerFrame = (FDKaacEnc_CalcBitsPerFrame(fMax(hAacConfig->bitRate, (INT)config->userPeakBitrate), hAacConfig->framelength, hAacConfig->sampleRate) + 7)&~7; + } + else { + hAacConfig->maxBitsPerFrame = -1; + } + if (hAacConfig->audioMuxVersion==2) { + hAacConfig->minBitsPerFrame = fMin(32*8, FDKaacEnc_CalcBitsPerFrame(hAacConfig->bitRate, hAacConfig->framelength, hAacConfig->sampleRate))&~7; + } + } + /* Initialize SBR parameters */ if ( (hAacConfig->audioObjectType==AOT_ER_AAC_ELD) && (config->userSbrEnabled == (UCHAR)-1) && (config->userSbrRatio==0) ) @@ -914,7 +905,7 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, } else { /* SBR ratio has been set by the user, so use it. */ - hAacConfig->sbrRatio = config->userSbrRatio; + hAacConfig->sbrRatio = isSbrActive(hAacConfig) ? config->userSbrRatio : 0; } { @@ -1139,7 +1130,7 @@ static AACENC_ERROR aacEncInit(HANDLE_AACENCODER hAacEncoder, hAacConfig); /* create flags for transport encoder */ - if (config->userTpAmxv == 1) { + if (config->userTpAmxv != 0) { flags |= TP_FLAG_LATM_AMV; } /* Clear output buffer */ @@ -1569,7 +1560,7 @@ AACENC_ERROR aacEncEncode( && ((hAacEncoder->extParam.userChannelMode==MODE_1_2_2)||(hAacEncoder->extParam.userChannelMode==MODE_1_2_2_1)) ) { /* Set matrix mixdown coefficient. */ - UINT pceValue = (UINT)( (1<<3) | ((matrix_mixdown_idx&0x3)<<1) | 1 ); + UINT pceValue = (UINT)( (0<<3) | ((matrix_mixdown_idx&0x3)<<1) | 1 ); if (hAacEncoder->extParam.userPceAdditions != pceValue) { hAacEncoder->extParam.userPceAdditions = pceValue; hAacEncoder->InitFlags |= AACENC_INIT_TRANSPORT; @@ -1785,19 +1776,16 @@ AACENC_ERROR aacEncoder_SetParam( /* check if AOT matches the allocated modules */ switch ( value ) { case AOT_PS: - case AOT_MP2_PS: if (!(hAacEncoder->encoder_modis & (ENC_MODE_FLAG_PS))) { err = AACENC_INVALID_CONFIG; goto bail; } case AOT_SBR: - case AOT_MP2_SBR: if (!(hAacEncoder->encoder_modis & (ENC_MODE_FLAG_SBR))) { err = AACENC_INVALID_CONFIG; goto bail; } case AOT_AAC_LC: - case AOT_MP2_AAC_LC: case AOT_ER_AAC_LD: case AOT_ER_AAC_ELD: if (!(hAacEncoder->encoder_modis & (ENC_MODE_FLAG_AAC))) { @@ -1823,6 +1811,7 @@ AACENC_ERROR aacEncoder_SetParam( if (settings->userBitrateMode != value) { switch ( value ) { case 0: + case 1: case 2: case 3: case 4: case 5: case 8: settings->userBitrateMode = value; hAacEncoder->InitFlags |= AACENC_INIT_CONFIG | AACENC_INIT_TRANSPORT; @@ -1973,6 +1962,16 @@ AACENC_ERROR aacEncoder_SetParam( hAacEncoder->InitFlags |= AACENC_INIT_TRANSPORT; } break; + case AACENC_AUDIOMUXVER: + if (settings->userTpAmxv != value) { + if ( !((value==0) || (value==1) || (value==2)) ) { + err = AACENC_INVALID_CONFIG; + break; + } + settings->userTpAmxv = value; + hAacEncoder->InitFlags |= AACENC_INIT_TRANSPORT; + } + break; case AACENC_TPSUBFRAMES: if (settings->userTpNsubFrames != value) { if (! ( (value>=1) && (value<=4) ) ) { @@ -1998,7 +1997,7 @@ AACENC_ERROR aacEncoder_SetParam( break; case AACENC_METADATA_MODE: if ((UINT)settings->userMetaDataMode != value) { - if ( !((value>=0) && (value<=2)) ) { + if ( !(((INT)value>=0) && ((INT)value<=2)) ) { err = AACENC_INVALID_CONFIG; break; } @@ -2006,6 +2005,12 @@ AACENC_ERROR aacEncoder_SetParam( hAacEncoder->InitFlags |= AACENC_INIT_CONFIG; } break; + case AACENC_PEAK_BITRATE: + if (settings->userPeakBitrate != value) { + settings->userPeakBitrate = value; + hAacEncoder->InitFlags |= AACENC_INIT_CONFIG | AACENC_INIT_TRANSPORT; + } + break; default: err = AACENC_UNSUPPORTED_PARAMETER; break; @@ -2076,6 +2081,9 @@ UINT aacEncoder_GetParam( case AACENC_HEADER_PERIOD: value = (UINT)hAacEncoder->coderConfig.headerPeriod; break; + case AACENC_AUDIOMUXVER: + value = (UINT)hAacEncoder->aacConfig.audioMuxVersion; + break; case AACENC_TPSUBFRAMES: value = (UINT)settings->userTpNsubFrames; break; @@ -2088,6 +2096,12 @@ UINT aacEncoder_GetParam( case AACENC_METADATA_MODE: value = (hAacEncoder->metaDataAllowed==0) ? 0 : (UINT)settings->userMetaDataMode; break; + case AACENC_PEAK_BITRATE: + value = (UINT)-1; /* peak bitrate parameter is meaningless */ + if ( ((INT)hAacEncoder->extParam.userPeakBitrate!=-1) ) { + value = (UINT)(fMax((INT)hAacEncoder->extParam.userPeakBitrate, hAacEncoder->aacConfig.bitRate)); /* peak bitrate parameter is in use */ + } + break; default: //err = MPS_INVALID_PARAMETER; break; diff --git a/libAACenc/src/aacenc_tns.cpp b/libAACenc/src/aacenc_tns.cpp index 85aea65..9a07e8f 100644 --- a/libAACenc/src/aacenc_tns.cpp +++ b/libAACenc/src/aacenc_tns.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -95,13 +95,7 @@ amm-info@iis.fraunhofer.de #include "aacEnc_rom.h" #include "aacenc_tns.h" -enum { - HIFILT = 0, /* index of higher filter */ - LOFILT = 1 /* index of lower filter */ -}; - - -#define FILTER_DIRECTION 0 +#define FILTER_DIRECTION 0 /* 0 = up, 1 = down */ static const FIXP_DBL acfWindowLong[12+3+1] = { 0x7fffffff,0x7fb80000,0x7ee00000,0x7d780000,0x7b800000,0x78f80000,0x75e00000,0x72380000, @@ -112,20 +106,6 @@ static const FIXP_DBL acfWindowShort[4+3+1] = { 0x7fffffff,0x7e000000,0x78000000,0x6e000000,0x60000000,0x4e000000,0x38000000,0x1e000000 }; - -typedef struct { - INT filterEnabled[MAX_NUM_OF_FILTERS]; - INT threshOn[MAX_NUM_OF_FILTERS]; /* min. prediction gain for using tns TABUL*/ - INT filterStartFreq[MAX_NUM_OF_FILTERS]; /* lowest freq for lpc TABUL*/ - INT tnsLimitOrder[MAX_NUM_OF_FILTERS]; /* Limit for TNS order TABUL*/ - INT tnsFilterDirection[MAX_NUM_OF_FILTERS]; /* Filtering direction, 0=up, 1=down TABUL */ - INT acfSplit[MAX_NUM_OF_FILTERS]; - FIXP_DBL tnsTimeResolution[MAX_NUM_OF_FILTERS]; /* TNS max. time resolution TABUL. Should be fract but MSVC won't compile then */ - INT seperateFiltersAllowed; - -} TNS_PARAMETER_TABULATED; - - typedef struct{ INT bitRateFrom[2]; /* noneSbr=0, useSbr=1 */ INT bitRateTo[2]; /* noneSbr=0, useSbr=1 */ @@ -373,6 +353,7 @@ AAC_ENCODER_ERROR FDKaacEnc_InitTnsConfiguration(INT bitRate, INT channels, INT blockType, INT granuleLength, + INT isLowDelay, INT ldSbrPresent, TNS_CONFIG *tC, PSY_CONFIGURATION *pC, @@ -385,6 +366,8 @@ AAC_ENCODER_ERROR FDKaacEnc_InitTnsConfiguration(INT bitRate, if (channels <= 0) return (AAC_ENCODER_ERROR)1; + tC->isLowDelay = isLowDelay; + /* initialize TNS filter flag, order, and coefficient resolution (in bits per coeff) */ tC->tnsActive = (active) ? TRUE : FALSE; tC->maxOrder = (blockType == SHORT_WINDOW) ? 5 : 12; /* maximum: 7, 20 */ @@ -450,27 +433,14 @@ AAC_ENCODER_ERROR FDKaacEnc_InitTnsConfiguration(INT bitRate, const TNS_PARAMETER_TABULATED* pCfg = FDKaacEnc_GetTnsParam(bitRate, channels, ldSbrPresent); if ( pCfg != NULL ) { + + FDKmemcpy(&(tC->confTab), pCfg, sizeof(tC->confTab)); + tC->lpcStartBand[HIFILT] = FDKaacEnc_FreqToBandWithRounding(pCfg->filterStartFreq[HIFILT], sampleRate, pC->sfbCnt, pC->sfbOffset); tC->lpcStartLine[HIFILT] = pC->sfbOffset[tC->lpcStartBand[HIFILT]]; tC->lpcStartBand[LOFILT] = FDKaacEnc_FreqToBandWithRounding(pCfg->filterStartFreq[LOFILT], sampleRate, pC->sfbCnt, pC->sfbOffset); tC->lpcStartLine[LOFILT] = pC->sfbOffset[tC->lpcStartBand[LOFILT]]; - tC->confTab.threshOn[HIFILT] = pCfg->threshOn[HIFILT]; - tC->confTab.threshOn[LOFILT] = pCfg->threshOn[LOFILT]; - - tC->confTab.tnsLimitOrder[HIFILT] = pCfg->tnsLimitOrder[HIFILT]; - tC->confTab.tnsLimitOrder[LOFILT] = pCfg->tnsLimitOrder[LOFILT]; - - tC->confTab.tnsFilterDirection[HIFILT] = pCfg->tnsFilterDirection[HIFILT]; - tC->confTab.tnsFilterDirection[LOFILT] = pCfg->tnsFilterDirection[LOFILT]; - - tC->confTab.acfSplit[HIFILT] = pCfg->acfSplit[HIFILT]; - tC->confTab.acfSplit[LOFILT] = pCfg->acfSplit[LOFILT]; - - tC->confTab.filterEnabled[HIFILT] = pCfg->filterEnabled[HIFILT]; - tC->confTab.filterEnabled[LOFILT] = pCfg->filterEnabled[LOFILT]; - tC->confTab.seperateFiltersAllowed = pCfg->seperateFiltersAllowed; - FDKaacEnc_CalcGaussWindow(tC->acfWindow[HIFILT], tC->maxOrder+1, sampleRate, granuleLength, pCfg->tnsTimeResolution[HIFILT], TNS_TIMERES_SCALE); FDKaacEnc_CalcGaussWindow(tC->acfWindow[LOFILT], tC->maxOrder+1, sampleRate, granuleLength, pCfg->tnsTimeResolution[LOFILT], TNS_TIMERES_SCALE); } @@ -614,6 +584,7 @@ static inline FIXP_DBL FDKaacEnc_AutoCorrNormFac( static void FDKaacEnc_MergedAutoCorrelation( const FIXP_DBL *spectrum, + const INT isLowDelay, const FIXP_DBL acfWindow[MAX_NUM_OF_FILTERS][TNS_MAX_ORDER+3+1], const INT lpcStartLine[MAX_NUM_OF_FILTERS], const INT lpcStopLine, @@ -633,6 +604,8 @@ static void FDKaacEnc_MergedAutoCorrelation( FDKmemclear(&_rxx1[0], sizeof(FIXP_DBL)*(maxOrder+1)); FDKmemclear(&_rxx2[0], sizeof(FIXP_DBL)*(maxOrder+1)); + idx0 = idx1 = idx2 = idx3 = idx4 = 0; + /* MDCT line indices separating the 1st, 2nd, 3rd, and 4th analysis quarters */ if ( (acfSplit[LOFILT]==-1) || (acfSplit[HIFILT]==-1) ) { /* autocorrelation function for 1st, 2nd, 3rd, and 4th quarter of the spectrum */ @@ -676,17 +649,27 @@ static void FDKaacEnc_MergedAutoCorrelation( /* compute energy normalization factors, i. e. 1/energy (saves some divisions) */ if (rxx1_0 != FL2FXCONST_DBL(0.f)) { - INT sc_fac1 = -1; - FIXP_DBL fac1 = FDKaacEnc_AutoCorrNormFac(rxx1_0, ((-2*sc1)+nsc1), &sc_fac1); - _rxx1[0] = scaleValue(fMult(rxx1_0,fac1),sc_fac1); + INT sc_fac1 = -1; + FIXP_DBL fac1 = FDKaacEnc_AutoCorrNormFac(rxx1_0, ((-2*sc1)+nsc1), &sc_fac1); + _rxx1[0] = scaleValue(fMult(rxx1_0,fac1),sc_fac1); + if (isLowDelay) + { for (lag = 1; lag <= maxOrder; lag++) { /* compute energy-normalized and windowed autocorrelation values at this lag */ + FIXP_DBL x1 = FDKaacEnc_CalcAutoCorrValue(pSpectrum, idx0, idx1, lag, nsc1); + _rxx1[lag] = fMult(scaleValue(fMult(x1,fac1),sc_fac1), acfWindow[LOFILT][lag]); + } + } + else + { + for (lag = 1; lag <= maxOrder; lag++) { if ((3 * lag) <= maxOrder + 3) { FIXP_DBL x1 = FDKaacEnc_CalcAutoCorrValue(pSpectrum, idx0, idx1, lag, nsc1); _rxx1[lag] = fMult(scaleValue(fMult(x1,fac1),sc_fac1), acfWindow[LOFILT][3*lag]); } } + } } /* auto corr over upper 3/4 of spectrum */ @@ -762,8 +745,12 @@ INT FDKaacEnc_TnsDetect( : &tnsData->dataRaw.Long.subBlockInfo; tnsData->filtersMerged = FALSE; - tsbi->tnsActive = FALSE; - tsbi->predictionGain = 1000; + + tsbi->tnsActive[HIFILT] = FALSE; + tsbi->predictionGain[HIFILT] = 1000; + tsbi->tnsActive[LOFILT] = FALSE; + tsbi->predictionGain[LOFILT] = 1000; + tnsInfo->numOfFilters[subBlockNumber] = 0; tnsInfo->coefRes[subBlockNumber] = tC->coefRes; for (i = 0; i < tC->maxOrder; i++) { @@ -779,6 +766,7 @@ INT FDKaacEnc_TnsDetect( FDKaacEnc_MergedAutoCorrelation( spectrum, + tC->isLowDelay, tC->acfWindow, tC->lpcStartLine, tC->lpcStopLine, @@ -788,7 +776,7 @@ INT FDKaacEnc_TnsDetect( rxx2); /* compute higher TNS filter in lattice (ParCor) form with LeRoux-Gueguen algorithm */ - tsbi->predictionGain = FDKaacEnc_AutoToParcor(rxx2, parcor_tmp, tC->confTab.tnsLimitOrder[HIFILT]); + tsbi->predictionGain[HIFILT] = FDKaacEnc_AutoToParcor(rxx2, parcor_tmp, tC->confTab.tnsLimitOrder[HIFILT]); /* non-linear quantization of TNS lattice coefficients with given resolution */ FDKaacEnc_Parcor2Index( @@ -815,9 +803,9 @@ INT FDKaacEnc_TnsDetect( tnsInfo->length[subBlockNumber][HIFILT] = sfbCnt - tC->lpcStartBand[HIFILT]; /* disable TNS if predictionGain is less than 3dB or sumSqrCoef is too small */ - if ((tsbi->predictionGain > tC->confTab.threshOn[HIFILT]) || (sumSqrCoef > (tC->confTab.tnsLimitOrder[HIFILT]/2 + 2))) + if ((tsbi->predictionGain[HIFILT] > tC->confTab.threshOn[HIFILT]) || (sumSqrCoef > (tC->confTab.tnsLimitOrder[HIFILT]/2 + 2))) { - tsbi->tnsActive = TRUE; + tsbi->tnsActive[HIFILT] = TRUE; tnsInfo->numOfFilters[subBlockNumber]++; /* compute second filter for lower quarter; only allowed for long windows! */ @@ -857,6 +845,7 @@ INT FDKaacEnc_TnsDetect( || ( (sumSqrCoef > 9) && (sumSqrCoef < 22 * tC->confTab.tnsLimitOrder[LOFILT]) ) ) { /* compare lower to upper filter; if they are very similar, merge them */ + tsbi->tnsActive[LOFILT] = TRUE; sumSqrCoef = 0; for (i = 0; i < tC->confTab.tnsLimitOrder[LOFILT]; i++) { sumSqrCoef += FDKabs(tnsInfo->coef[subBlockNumber][HIFILT][i] - tnsInfo->coef[subBlockNumber][LOFILT][i]); @@ -884,6 +873,8 @@ INT FDKaacEnc_TnsDetect( tnsInfo->numOfFilters[subBlockNumber]++; } } /* filter lower part */ + tsbi->predictionGain[LOFILT]=predGain; + } /* second filter allowed */ } /* if predictionGain > 1437 ... */ } /* maxOrder > 0 && tnsActive */ @@ -944,7 +935,7 @@ void FDKaacEnc_TnsSync( INT doSync = 1, absDiffSum = 0; /* if TNS is active in at least one channel, check if ParCor coefficients of higher filter are similar */ - if (pSbInfoDestW->tnsActive || pSbInfoSrcW->tnsActive) { + if (pSbInfoDestW->tnsActive[HIFILT] || pSbInfoSrcW->tnsActive[HIFILT]) { for (i = 0; i < tC->maxOrder; i++) { absDiff = FDKabs(tnsInfoDest->coef[w][HIFILT][i] - tnsInfoSrc->coef[w][HIFILT][i]); absDiffSum += absDiff; @@ -957,12 +948,12 @@ void FDKaacEnc_TnsSync( if (doSync) { /* if no significant difference was detected, synchronize coefficient sets */ - if (pSbInfoSrcW->tnsActive) { + if (pSbInfoSrcW->tnsActive[HIFILT]) { /* no dest filter, or more dest than source filters: use one dest filter */ - if ((!pSbInfoDestW->tnsActive) || - ((pSbInfoDestW->tnsActive) && (tnsInfoDest->numOfFilters[w] > tnsInfoSrc->numOfFilters[w]))) + if ((!pSbInfoDestW->tnsActive[HIFILT]) || + ((pSbInfoDestW->tnsActive[HIFILT]) && (tnsInfoDest->numOfFilters[w] > tnsInfoSrc->numOfFilters[w]))) { - pSbInfoDestW->tnsActive = tnsInfoDest->numOfFilters[w] = 1; + pSbInfoDestW->tnsActive[HIFILT] = tnsInfoDest->numOfFilters[w] = 1; } tnsDataDest->filtersMerged = tnsDataSrc->filtersMerged; tnsInfoDest->order [w][HIFILT] = tnsInfoSrc->order [w][HIFILT]; @@ -975,7 +966,7 @@ void FDKaacEnc_TnsSync( } } else - pSbInfoDestW->tnsActive = tnsInfoDest->numOfFilters[w] = 0; + pSbInfoDestW->tnsActive[HIFILT] = tnsInfoDest->numOfFilters[w] = 0; } } @@ -1012,8 +1003,8 @@ INT FDKaacEnc_TnsEncode( { INT i, startLine, stopLine; - if ( ( (blockType == SHORT_WINDOW) && (!tnsData->dataRaw.Short.subBlockInfo[subBlockNumber].tnsActive) ) - || ( (blockType != SHORT_WINDOW) && (!tnsData->dataRaw.Long.subBlockInfo.tnsActive) ) ) + if ( ( (blockType == SHORT_WINDOW) && (!tnsData->dataRaw.Short.subBlockInfo[subBlockNumber].tnsActive[HIFILT]) ) + || ( (blockType != SHORT_WINDOW) && (!tnsData->dataRaw.Long.subBlockInfo.tnsActive[HIFILT]) ) ) { return 1; } @@ -1129,8 +1120,9 @@ static INT FDKaacEnc_AutoToParcor( FIXP_DBL *RESTRICT workBuffer = parcorWorkBuffer; const FIXP_DBL autoCorr_0 = input[0]; + FDKmemclear(reflCoeff,numOfCoeff*sizeof(FIXP_DBL)); + if((FIXP_DBL)input[0] == FL2FXCONST_DBL(0.0)) { - FDKmemclear(reflCoeff,numOfCoeff*sizeof(FIXP_DBL)); return(predictionGain); } diff --git a/libAACenc/src/aacenc_tns.h b/libAACenc/src/aacenc_tns.h index f2b731f..2824cbc 100644 --- a/libAACenc/src/aacenc_tns.h +++ b/libAACenc/src/aacenc_tns.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -117,21 +117,25 @@ amm-info@iis.fraunhofer.de #define MAX_NUM_OF_FILTERS 2 +#define HIFILT 0 /* index of higher filter */ +#define LOFILT 1 /* index of lower filter */ -typedef struct{ /*stuff that is tabulated dependent on bitrate etc. */ - INT filterEnabled[MAX_NUM_OF_FILTERS]; - INT threshOn[MAX_NUM_OF_FILTERS]; /* min. prediction gain for using tns TABUL*/ - INT tnsLimitOrder[MAX_NUM_OF_FILTERS]; /* Limit for TNS order TABUL*/ - INT tnsFilterDirection[MAX_NUM_OF_FILTERS]; /* Filtering direction, 0=up, 1=down TABUL */ - INT acfSplit[MAX_NUM_OF_FILTERS]; - INT seperateFiltersAllowed; - -}TNS_CONFIG_TABULATED; +typedef struct{ /* stuff that is tabulated dependent on bitrate etc. */ + INT filterEnabled[MAX_NUM_OF_FILTERS]; + INT threshOn[MAX_NUM_OF_FILTERS]; /* min. prediction gain for using tns TABUL*/ + INT filterStartFreq[MAX_NUM_OF_FILTERS]; /* lowest freq for lpc TABUL*/ + INT tnsLimitOrder[MAX_NUM_OF_FILTERS]; /* Limit for TNS order TABUL*/ + INT tnsFilterDirection[MAX_NUM_OF_FILTERS]; /* Filtering direction, 0=up, 1=down TABUL */ + INT acfSplit[MAX_NUM_OF_FILTERS]; + FIXP_DBL tnsTimeResolution[MAX_NUM_OF_FILTERS]; /* TNS max. time resolution TABUL. Should be fract but MSVC won't compile then */ + INT seperateFiltersAllowed; +} TNS_PARAMETER_TABULATED; typedef struct { /*assigned at InitTime*/ - TNS_CONFIG_TABULATED confTab; + TNS_PARAMETER_TABULATED confTab; + INT isLowDelay; INT tnsActive; INT maxOrder; /* max. order of tns filter */ INT coefRes; @@ -148,8 +152,8 @@ typedef struct { /*assigned at InitTime*/ typedef struct { - INT tnsActive; - INT predictionGain; + INT tnsActive[MAX_NUM_OF_FILTERS]; + INT predictionGain[MAX_NUM_OF_FILTERS]; } TNS_SUBBLOCK_INFO; typedef struct{ /*changed at runTime*/ diff --git a/libAACenc/src/adj_thr.cpp b/libAACenc/src/adj_thr.cpp index 6433633..a79a9ae 100644 --- a/libAACenc/src/adj_thr.cpp +++ b/libAACenc/src/adj_thr.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -130,14 +130,14 @@ the crash recovery strategy will be activated once. typedef struct { INT bitrate; - LONG bits2PeFactor_mono; - LONG bits2PeFactor_mono_slope; - LONG bits2PeFactor_stereo; - LONG bits2PeFactor_stereo_slope; - LONG bits2PeFactor_mono_scfOpt; - LONG bits2PeFactor_mono_scfOpt_slope; - LONG bits2PeFactor_stereo_scfOpt; - LONG bits2PeFactor_stereo_scfOpt_slope; + ULONG bits2PeFactor_mono; + ULONG bits2PeFactor_mono_slope; + ULONG bits2PeFactor_stereo; + ULONG bits2PeFactor_stereo_slope; + ULONG bits2PeFactor_mono_scfOpt; + ULONG bits2PeFactor_mono_scfOpt_slope; + ULONG bits2PeFactor_stereo_scfOpt; + ULONG bits2PeFactor_stereo_scfOpt_slope; } BIT_PE_SFAC; @@ -153,10 +153,10 @@ static const BIT_PE_SFAC S_Bits2PeTab16000[] = { { 24000, 0x23D70A3D, 0x029F16B1, 0x2199999A, 0x07DD4413, 0x23D70A3D, 0x029F16B1, 0x2199999A, 0x07DD4413}, { 32000, 0x247AE148, 0x11B1D92B, 0x23851EB8, 0x01F75105, 0x247AE148, 0x110A137F, 0x23851EB8, 0x01F75105}, { 48000, 0x2D1EB852, 0x6833C600, 0x247AE148, 0x014F8B59, 0x2CCCCCCD, 0x68DB8BAC, 0x247AE148, 0x01F75105}, - { 64000, 0x60000000, 0x00000000, 0x251EB852, 0x154C985F, 0x60000000, 0x00000000, 0x2570A3D7, 0x154C985F}, - { 96000, 0x60000000, 0x00000000, 0x39EB851F, 0x088509C0, 0x60000000, 0x00000000, 0x3A3D70A4, 0x088509C0}, - {128000, 0x60000000, 0x00000000, 0x423D70A4, 0x18A43BB4, 0x60000000, 0x00000000, 0x428F5C29, 0x181E03F7}, - {148000, 0x60000000, 0x00000000, 0x5147AE14, 0x00000000, 0x60000000, 0x00000000, 0x5147AE14, 0x00000000} + { 64000, 0x25c28f40, 0x00000000, 0x251EB852, 0x01480000, 0x25c28f40, 0x00000000, 0x2570A3D7, 0x01480000}, + { 96000, 0x25c28f40, 0x00000000, 0x26000000, 0x01000000, 0x25c28f40, 0x00000000, 0x26000000, 0x01000000}, + {128000, 0x25c28f40, 0x00000000, 0x270a3d80, 0x01000000, 0x25c28f40, 0x00000000, 0x270a3d80, 0x01000000}, + {148000, 0x25c28f40, 0x00000000, 0x28000000, 0x00000000, 0x25c28f40, 0x00000000, 0x28000000, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab22050[] = { @@ -166,8 +166,8 @@ static const BIT_PE_SFAC S_Bits2PeTab22050[] = { { 48000, 0x23d70a3d, 0x014f8b59, 0x2199999a, 0x03eea20a, 0x23d70a3d, 0x14f8b59, 0x2199999a, 0x03eea20a}, { 64000, 0x247ae148, 0x08d8ec96, 0x23851eb8, 0x00fba882, 0x247ae148, 0x88509c0, 0x23851eb8, 0x00fba882}, { 96000, 0x2d1eb852, 0x3419e300, 0x247ae148, 0x00a7c5ac, 0x2ccccccd, 0x346dc5d6, 0x247ae148, 0x00fba882}, - {128000, 0x60000000, 0x00000000, 0x251eb852, 0x029f16b1, 0x60000000, 0x00000000, 0x2570a3d7, 0x009f16b1}, - {148000, 0x60000000, 0x00000000, 0x26b851ec, 0x00000000, 0x60000000, 0x00000000, 0x270a3d71, 0x00000000} + {128000, 0x25c28f40, 0x00000000, 0x251eb852, 0x029f16b1, 0x60000000, 0x25c28f40, 0x2570a3d7, 0x009f16b1}, + {148000, 0x25c28f40, 0x00000000, 0x26b851ec, 0x00000000, 0x60000000, 0x25c28f40, 0x270a3d71, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab24000[] = { @@ -178,21 +178,21 @@ static const BIT_PE_SFAC S_Bits2PeTab24000[] = { { 64000, 0x24cccccd, 0x05e5f30e, 0x22e147ae, 0x01a36e2f, 0x24cccccd, 0x05e5f30e, 0x23333333, 0x014f8b59}, { 96000, 0x2a8f5c29, 0x24b33db0, 0x247ae148, 0x00fba882, 0x2a8f5c29, 0x26fe718b, 0x247ae148, 0x00fba882}, {128000, 0x4e666666, 0x1cd5f99c, 0x2570a3d7, 0x010c6f7a, 0x50a3d70a, 0x192a7371, 0x2570a3d7, 0x010c6f7a}, - {148000, 0x60000000, 0x00000000, 0x26147ae1, 0x00000000, 0x60000000, 0x00000000, 0x26147ae1, 0x00000000} + {148000, 0x25c28f40, 0x00000000, 0x26147ae1, 0x00000000, 0x25c28f40, 0x00000000, 0x26147ae1, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab32000[] = { - { 16000, 0x1199999a, 0x20c49ba6, 0x00000000, 0x4577d955, 0x00000000, 0x60fe4799, 0x00000000, 0x00000000}, - { 24000, 0x1999999a, 0x0fba8827, 0x10f5c28f, 0x1b866e44, 0x17ae147b, 0x0fba8827, 0x00000000, 0x4d551d69}, + { 16000, 0x247ae140, 0xFFFFAC1E, 0x270a3d80, 0xFFFE9B7C, 0x14ccccc0, 0x000110A1, 0x15c28f60, 0xFFFEEF5F}, + { 24000, 0x23333340, 0x0fba8827, 0x21999980, 0x1b866e44, 0x18f5c280, 0x0fba8827, 0x119999a0, 0x4d551d69}, { 32000, 0x1d70a3d7, 0x07357e67, 0x17ae147b, 0x09d49518, 0x1b851eb8, 0x0a7c5ac4, 0x12e147ae, 0x110a137f}, { 48000, 0x20f5c28f, 0x049667b6, 0x1c7ae148, 0x053e2d62, 0x20a3d70a, 0x053e2d62, 0x1b333333, 0x05e5f30e}, { 64000, 0x23333333, 0x029f16b1, 0x1f0a3d71, 0x02f2f987, 0x23333333, 0x029f16b1, 0x1e147ae1, 0x03eea20a}, { 96000, 0x25c28f5c, 0x2c3c9eed, 0x21eb851f, 0x01f75105, 0x25c28f5c, 0x0a7c5ac4, 0x21eb851f, 0x01a36e2f}, {128000, 0x50f5c28f, 0x18a43bb4, 0x23d70a3d, 0x010c6f7a, 0x30000000, 0x168b5cc0, 0x23851eb8, 0x0192a737}, - {148000, 0x60000000, 0x00000000, 0x247ae148, 0x00dfb23b, 0x3dc28f5c, 0x300f4aaf, 0x247ae148, 0x01bf6476}, - {160000, 0x60000000, 0xb15b5740, 0x24cccccd, 0x053e2d62, 0x4f5c28f6, 0xbefd0072, 0x251eb852, 0x04fb1184}, - {200000, 0x00000000, 0x00000000, 0x2b333333, 0x0836be91, 0x00000000, 0x00000000, 0x2b333333, 0x0890390f}, - {320000, 0x00000000, 0x00000000, 0x4947ae14, 0x00000000, 0x00000000, 0x00000000, 0x4a8f5c29, 0x00000000} + {148000, 0x25c28f40, 0x00000000, 0x247ae148, 0x00dfb23b, 0x3dc28f5c, 0x300f4aaf, 0x247ae148, 0x01bf6476}, + {160000, 0x25c28f40, 0xb15b5740, 0x24cccccd, 0x053e2d62, 0x4f5c28f6, 0xbefd0072, 0x251eb852, 0x04fb1184}, + {200000, 0x25c28f40, 0x00000000, 0x2b333333, 0x0836be91, 0x25c28f40, 0x00000000, 0x2b333333, 0x0890390f}, + {320000, 0x25c28f40, 0x00000000, 0x4947ae14, 0x00000000, 0x25c28f40, 0x00000000, 0x4a8f5c29, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab44100[] = { @@ -205,8 +205,8 @@ static const BIT_PE_SFAC S_Bits2PeTab44100[] = { {128000, 0x2ae147ae, 0x1b435265, 0x223d70a4, 0x0192a737, 0x2a3d70a4, 0x1040bfe4, 0x21eb851f, 0x0192a737}, {148000, 0x3b851eb8, 0x2832069c, 0x23333333, 0x00dfb23b, 0x3428f5c3, 0x2054c288, 0x22e147ae, 0x00dfb23b}, {160000, 0x4a3d70a4, 0xc32ebe5a, 0x23851eb8, 0x01d5c316, 0x40000000, 0xcb923a2b, 0x23333333, 0x01d5c316}, - {200000, 0x00000000, 0x00000000, 0x25c28f5c, 0x0713f078, 0x00000000, 0x00000000, 0x2570a3d7, 0x072a4f17}, - {320000, 0x00000000, 0x00000000, 0x3fae147b, 0x00000000, 0x00000000, 0x00000000, 0x3fae147b, 0x00000000} + {200000, 0x25c28f40, 0x00000000, 0x25c28f5c, 0x0713f078, 0x25c28f40, 0x00000000, 0x2570a3d7, 0x072a4f17}, + {320000, 0x25c28f40, 0x00000000, 0x3fae147b, 0x00000000, 0x25c28f40, 0x00000000, 0x3fae147b, 0x00000000} }; static const BIT_PE_SFAC S_Bits2PeTab48000[] = { @@ -219,8 +219,8 @@ static const BIT_PE_SFAC S_Bits2PeTab48000[] = { {128000, 0x28f5c28f, 0x14727dcc, 0x2147ae14, 0x0218def4, 0x2851eb85, 0x0e27e0f0, 0x20f5c28f, 0x0218def4}, {148000, 0x3570a3d7, 0x1cd5f99c, 0x228f5c29, 0x01bf6476, 0x30f5c28f, 0x18777e75, 0x223d70a4, 0x01bf6476}, {160000, 0x40000000, 0xcb923a2b, 0x23333333, 0x0192a737, 0x39eb851f, 0xd08d4bae, 0x22e147ae, 0x0192a737}, - {200000, 0x00000000, 0x00000000, 0x251eb852, 0x06775a1b, 0x00000000, 0x00000000, 0x24cccccd, 0x06a4175a}, - {320000, 0x00000000, 0x00000000, 0x3ccccccd, 0x00000000, 0x00000000, 0x00000000, 0x3d1eb852, 0x00000000} + {200000, 0x25c28f40, 0x00000000, 0x251eb852, 0x06775a1b, 0x25c28f40, 0x00000000, 0x24cccccd, 0x06a4175a}, + {320000, 0x25c28f40, 0x00000000, 0x3ccccccd, 0x00000000, 0x25c28f40, 0x00000000, 0x3d1eb852, 0x00000000} }; static const BITS2PE_CFG_TAB bits2PeConfigTab[] = { @@ -258,6 +258,7 @@ static void FDKaacEnc_InitBits2PeFactor( const INT nChannels, const INT sampleRate, const INT advancedBitsToPe, + const INT dZoneQuantEnable, const INT invQuant ) { @@ -329,7 +330,32 @@ static void FDKaacEnc_InitBits2PeFactor( } /* advancedBitsToPe */ - /* return bits2pe factor */ + if (dZoneQuantEnable) + { + if(bit2PE_m >= (FL2FXCONST_DBL(0.6f))>>bit2PE_e) + { + /* Additional headroom for addition */ + bit2PE_m >>= 1; + bit2PE_e += 1; + } + + /* the quantTendencyCompensator compensates a lower bit consumption due to increasing the tendency to quantize low spectral values to the lower quantizer border for bitrates below a certain bitrate threshold --> see also function calcSfbDistLD in quantize.c */ + if ((bitRate/nChannels > 32000) && (bitRate/nChannels <= 40000)) { + bit2PE_m += (FL2FXCONST_DBL(0.4f))>>bit2PE_e; + } + else if (bitRate/nChannels > 20000) { + bit2PE_m += (FL2FXCONST_DBL(0.3f))>>bit2PE_e; + } + else if (bitRate/nChannels >= 16000) { + bit2PE_m += (FL2FXCONST_DBL(0.3f))>>bit2PE_e; + } + else { + bit2PE_m += (FL2FXCONST_DBL(0.0f))>>bit2PE_e; + } + } + + + /***** 3.) Return bits2pe factor *****/ *bits2PeFactor_m = bit2PE_m; *bits2PeFactor_e = bit2PE_e; } @@ -1649,6 +1675,7 @@ static void FDKaacEnc_adaptThresholdsToPe(CHANNEL_MAPPING* cm, QC_OUT_ELEMENT* qcElement[(8)], PSY_OUT_ELEMENT* psyOutElement[(8)], const INT desiredPe, + const INT maxIter2ndGuess, const INT processElements, const INT elementOffset) { @@ -1733,7 +1760,7 @@ static void FDKaacEnc_adaptThresholdsToPe(CHANNEL_MAPPING* cm, /* Part III: Iterate until bit constraints are met */ /* -------------------------------------------------- */ iter = 0; - while ((fixp_abs(redPeGlobal - desiredPe) > fMultI(FL2FXCONST_DBL(0.05f),desiredPe)) && (iter < 1)) { + while ((fixp_abs(redPeGlobal - desiredPe) > fMultI(FL2FXCONST_DBL(0.05f),desiredPe)) && (iter < maxIter2ndGuess)) { INT desiredPeNoAHGlobal; INT redPeNoAHGlobal = 0; @@ -2138,7 +2165,7 @@ static FIXP_DBL FDKaacEnc_bitresCalcBitFac(const INT bitresBits, bresParam->clipSpendLow, bresParam->clipSpendHigh, bresParam->minBitSpend, bresParam->maxBitSpend, bitspend_slope); - pe_pers = fDivNorm(pex - adjThrChan->peMin, adjThrChan->peMax - adjThrChan->peMin); + pe_pers = (pex > adjThrChan->peMin) ? fDivNorm(pex - adjThrChan->peMin, adjThrChan->peMax - adjThrChan->peMin) : 0; tmp_fix = fMult(((FIXP_DBL)bitSpend + (FIXP_DBL)bitSave), pe_pers); bitresFac_fix = (UNITY>>1) - ((FIXP_DBL)bitSave>>1) + (tmp_fix>>1); qbres = (DFRACT_BITS-2); @@ -2225,7 +2252,8 @@ void FDKaacEnc_AdjThrInit( INT nChannelsEff, INT sampleRate, INT advancedBitsToPe, - FIXP_DBL vbrQualFactor + FIXP_DBL vbrQualFactor, + const INT dZoneQuantEnable ) { INT i; @@ -2233,6 +2261,10 @@ void FDKaacEnc_AdjThrInit( FIXP_DBL POINT8 = FL2FXCONST_DBL(0.8f); FIXP_DBL POINT6 = FL2FXCONST_DBL(0.6f); + /* Max number of iterations in second guess is 3 for lowdelay aot and for configurations with + multiple audio elements in general, otherwise iteration value is always 1. */ + hAdjThr->maxIter2ndGuess = (advancedBitsToPe!=0 || nElements>1) ? 3 : 1; + /* common for all elements: */ /* parameters for bitres control */ hAdjThr->bresParamLong.clipSaveLow = (FIXP_DBL)0x1999999a; /* FL2FXCONST_DBL(0.2f); */ @@ -2313,10 +2345,11 @@ void FDKaacEnc_AdjThrInit( FDKaacEnc_InitBits2PeFactor( &atsElem->bits2PeFactor_m, &atsElem->bits2PeFactor_e, - chBitrate, /* bitrate/channel*/ + chBitrate*nChannelsEff, /* overall bitrate */ nChannelsEff, /* number of channels */ sampleRate, advancedBitsToPe, + dZoneQuantEnable, invQuant ); @@ -2545,6 +2578,7 @@ void FDKaacEnc_AdjustThresholds(ATS_ELEMENT* AdjThrStateElement[(8)], QC_OUT* qcOut, PSY_OUT_ELEMENT* psyOutElement[(8)], INT CBRbitrateMode, + INT maxIter2ndGuess, CHANNEL_MAPPING* cm) { int i; @@ -2570,6 +2604,7 @@ void FDKaacEnc_AdjustThresholds(ATS_ELEMENT* AdjThrStateElement[(8)], qcElement, psyOutElement, qcElement[i]->grantedPeCorr, + maxIter2ndGuess, 1, /* Process only 1 element */ i); /* Process exactly THIS element */ diff --git a/libAACenc/src/adj_thr.h b/libAACenc/src/adj_thr.h index 69b1dcc..be68c6e 100644 --- a/libAACenc/src/adj_thr.h +++ b/libAACenc/src/adj_thr.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -118,7 +118,8 @@ void FDKaacEnc_AdjThrInit(ADJ_THR_STATE *hAdjThr, INT nChannelsEff, INT sampleRate, INT advancedBitsToPe, - FIXP_DBL vbrQualFactor); + FIXP_DBL vbrQualFactor, + const INT dZoneQuantEnable); void FDKaacEnc_DistributeBits(ADJ_THR_STATE *adjThrState, @@ -140,6 +141,7 @@ void FDKaacEnc_AdjustThresholds(ATS_ELEMENT* AdjThrStateElement[(8)], QC_OUT* qcOut, PSY_OUT_ELEMENT* psyOutElement[(8)], INT CBRbitrateMode, + INT maxIter2ndGuess, CHANNEL_MAPPING* cm); void FDKaacEnc_AdjThrClose(ADJ_THR_STATE** hAdjThr); diff --git a/libAACenc/src/adj_thr_data.h b/libAACenc/src/adj_thr_data.h index 3eb7678..7c3a191 100644 --- a/libAACenc/src/adj_thr_data.h +++ b/libAACenc/src/adj_thr_data.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -145,6 +145,7 @@ typedef struct { typedef struct { BRES_PARAM bresParamLong, bresParamShort; ATS_ELEMENT* adjThrStateElem[(8)]; + INT maxIter2ndGuess; } ADJ_THR_STATE; #endif diff --git a/libAACenc/src/bandwidth.cpp b/libAACenc/src/bandwidth.cpp index 6fc7d87..6937362 100644 --- a/libAACenc/src/bandwidth.cpp +++ b/libAACenc/src/bandwidth.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -127,7 +127,7 @@ static const BANDWIDTH_TAB bandWidthTable_LD_24000[] = { { 8000, 2000, 2000}, {12000, 2000, 2300}, {16000, 2200, 2500}, - {24000, 5650, 6400}, + {24000, 5650, 7200}, {32000, 11600, 12000}, {40000, 12000, 16000}, {48000, 16000, 16000}, @@ -138,10 +138,10 @@ static const BANDWIDTH_TAB bandWidthTable_LD_24000[] = { static const BANDWIDTH_TAB bandWidthTable_LD_32000[] = { { 8000, 2000, 2000}, {12000, 2000, 2000}, - {24000, 4250, 5200}, + {24000, 4250, 7200}, {32000, 8400, 9000}, {40000, 9400, 11300}, - {48000, 11900, 13700}, + {48000, 11900, 14700}, {64000, 14800, 16000}, {76000, 16000, 16000}, {360001, 16000, 16000} diff --git a/libAACenc/src/intensity.cpp b/libAACenc/src/intensity.cpp index 6d807f7..b45b27b 100644 --- a/libAACenc/src/intensity.cpp +++ b/libAACenc/src/intensity.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -325,7 +325,6 @@ FDKaacEnc_prepareIntensityDecision(const FIXP_DBL *sfbEnergyLeft, channelCorr[sfb + sfboffs] = FL2FXCONST_DBL(0.0f); - FDK_ASSERT(50 >= 49); /* max width of scalefactorband is 96; width's are always even */ /* inv_n is scaled with factor 2 to compensate fMultDiv2() in subsequent loops */ inv_n = GetInvInt((sfbOffset[sfb + sfboffs + 1] - sfbOffset[sfb + sfboffs])>>1); diff --git a/libAACenc/src/pnsparam.cpp b/libAACenc/src/pnsparam.cpp index afc5bdd..9d59ddc 100644 --- a/libAACenc/src/pnsparam.cpp +++ b/libAACenc/src/pnsparam.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -107,6 +107,7 @@ typedef struct { typedef struct { ULONG brFrom; ULONG brTo; + UCHAR S16000; UCHAR S22050; UCHAR S24000; UCHAR S32000; @@ -115,25 +116,26 @@ typedef struct { } AUTO_PNS_TAB; static const AUTO_PNS_TAB levelTable_mono[]= { - {0, 11999, 1, 1, 1, 1, 1,}, - {12000, 19999, 1, 1, 1, 1, 1,}, - {20000, 28999, 2, 1, 1, 1, 1,}, - {29000, 40999, 4, 4, 4, 2, 2,}, - {41000, 55999, 9, 9, 7, 7, 7,}, - {56000, 79999, 0, 0, 0, 9, 9,}, - {80000, 99999, 0, 0, 0, 0, 0,}, - {100000,999999, 0, 0, 0, 0, 0,}, + {0, 11999, 0, 1, 1, 1, 1, 1,}, + {12000, 19999, 0, 1, 1, 1, 1, 1,}, + {20000, 28999, 0, 2, 1, 1, 1, 1,}, + {29000, 40999, 0, 4, 4, 4, 2, 2,}, + {41000, 55999, 0, 9, 9, 7, 7, 7,}, + {56000, 61999, 0, 0, 0, 0, 9, 9,}, + {62000, 75999, 0, 0, 0, 0, 0, 0,}, + {76000, 92999, 0, 0, 0, 0, 0, 0,}, + {93000, 999999, 0, 0, 0, 0, 0, 0,}, }; static const AUTO_PNS_TAB levelTable_stereo[]= { - {0, 11999, 1, 1, 1, 1, 1,}, - {12000, 19999, 3, 1, 1, 1, 1,}, - {20000, 28999, 3, 3, 3, 2, 2,}, - {29000, 40999, 7, 6, 6, 5, 5,}, - {41000, 55999, 9, 9, 7, 7, 7,}, - {56000, 79999, 0, 0, 0, 0, 0,}, - {80000, 99999, 0, 0, 0, 0, 0,}, - {100000,999999, 0, 0, 0, 0, 0,}, + {0, 11999, 0, 1, 1, 1, 1, 1,}, + {12000, 19999, 0, 3, 1, 1, 1, 1,}, + {20000, 28999, 0, 3, 3, 3, 2, 2,}, + {29000, 40999, 0, 7, 6, 6, 5, 5,}, + {41000, 55999, 0, 9, 9, 7, 7, 7,}, + {56000, 79999, 0, 0, 0, 0, 0, 0,}, + {80000, 99999, 0, 0, 0, 0, 0, 0,}, + {100000,999999, 0, 0, 0, 0, 0, 0,}, }; @@ -160,11 +162,11 @@ static const PNS_INFO_TAB pnsInfoTab[] = { }; static const AUTO_PNS_TAB levelTable_lowComplexity[]= { - {0, 27999, 0, 0, 0, 0, 0,}, - {28000, 31999, 2, 2, 2, 2, 2,}, - {32000, 47999, 3, 3, 3, 3, 3,}, - {48000, 48000, 4, 4, 4, 4, 4,}, - {48001, 999999, 0, 0, 0, 0, 0,}, + {0, 27999, 0, 0, 0, 0, 0, 0,}, + {28000, 31999, 0, 2, 2, 2, 2, 2,}, + {32000, 47999, 0, 3, 3, 3, 3, 3,}, + {48000, 48000, 0, 4, 4, 4, 4, 4,}, + {48001, 999999, 0, 0, 0, 0, 0, 0,}, }; /* conversion of old LC tuning tables to new (LD enc) structure (only entries which are actually used were converted) */ @@ -211,6 +213,7 @@ int FDKaacEnc_lookUpPnsUse (int bitRate, int sampleRate, int numChan, const int } switch (sampleRate) { + case 16000: hUsePns = levelTable[i].S16000; break; case 22050: hUsePns = levelTable[i].S22050; break; case 24000: hUsePns = levelTable[i].S24000; break; case 32000: hUsePns = levelTable[i].S32000; break; diff --git a/libAACenc/src/psy_configuration.cpp b/libAACenc/src/psy_configuration.cpp index 4393fa1..9a72c68 100644 --- a/libAACenc/src/psy_configuration.cpp +++ b/libAACenc/src/psy_configuration.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -634,13 +634,14 @@ AAC_ENCODER_ERROR FDKaacEnc_InitPsyConfiguration(INT bitrate, if (psyConf->sfbOffset[sfb] >= psyConf->lowpassLine) break; } - psyConf->sfbActive = sfb; + psyConf->sfbActive = FDKmax(sfb, 1); for (sfb = 0; sfb < psyConf->sfbCnt; sfb++){ if (psyConf->sfbOffset[sfb] >= psyConf->lowpassLineLFE) break; } psyConf->sfbActiveLFE = sfb; + psyConf->sfbActive = FDKmax(psyConf->sfbActive, psyConf->sfbActiveLFE); /* calculate minSnr */ FDKaacEnc_initMinSnr(bitrate, diff --git a/libAACenc/src/psy_main.cpp b/libAACenc/src/psy_main.cpp index 59193c7..446c894 100644 --- a/libAACenc/src/psy_main.cpp +++ b/libAACenc/src/psy_main.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -342,6 +342,7 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMainInit(PSY_INTERNAL *hPsy, tnsChannels, LONG_WINDOW, hPsy->granuleLength, + isLowDelay(audioObjectType), (syntaxFlags&AC_SBR_PRESENT)?1:0, &(hPsy->psyConf[0].tnsConf), &hPsy->psyConf[0], @@ -362,6 +363,7 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMainInit(PSY_INTERNAL *hPsy, tnsChannels, SHORT_WINDOW, hPsy->granuleLength, + isLowDelay(audioObjectType), (syntaxFlags&AC_SBR_PRESENT)?1:0, &hPsy->psyConf[1].tnsConf, &hPsy->psyConf[1], @@ -447,7 +449,7 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, INT totalChannels ) { - INT commonWindow = 1; + const INT commonWindow = 1; INT maxSfbPerGroup[(2)]; INT mdctSpectrum_e; INT ch; /* counts through channels */ @@ -621,7 +623,7 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, FDKmemclear(&psyData[ch]->mdctSpectrum[psyData[ch]->lowpassLine+wOffset], (windowLength[ch]-psyData[ch]->lowpassLine)*sizeof(FIXP_DBL)); - if (hPsyConfLong->filterbank != FB_LC) { + if ( (hPsyConfLong->filterbank != FB_LC) && (psyData[ch]->lowpassLine >= FADE_OUT_LEN) ) { /* Do blending to reduce gibbs artifacts */ for (int i=0; i<FADE_OUT_LEN; i++) { psyData[ch]->mdctSpectrum[psyData[ch]->lowpassLine+wOffset - FADE_OUT_LEN + i] = fMult(psyData[ch]->mdctSpectrum[psyData[ch]->lowpassLine+wOffset - FADE_OUT_LEN + i], fadeOutFactor[i]); @@ -763,7 +765,8 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, /* Advance psychoacoustics: Tonality and TNS */ if (psyStatic[0]->isLFE) { - tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive = 0; + tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT] = 0; + tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[LOFILT] = 0; } else { @@ -815,15 +818,19 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, &hThisPsyConf[1]->tnsConf); } - FDK_ASSERT(commonWindow=1); /* all checks for TNS do only work for common windows (which is always set)*/ + FDK_ASSERT(1==commonWindow); /* all checks for TNS do only work for common windows (which is always set)*/ for(w = 0; w < nWindows[0]; w++) { if (isShortWindow[0]) - tnsActive[w] = tnsData[0]->dataRaw.Short.subBlockInfo[w].tnsActive || - ((channels == 2) ? tnsData[1]->dataRaw.Short.subBlockInfo[w].tnsActive : 0); + tnsActive[w] = tnsData[0]->dataRaw.Short.subBlockInfo[w].tnsActive[HIFILT] || + tnsData[0]->dataRaw.Short.subBlockInfo[w].tnsActive[LOFILT] || + tnsData[channels-1]->dataRaw.Short.subBlockInfo[w].tnsActive[HIFILT] || + tnsData[channels-1]->dataRaw.Short.subBlockInfo[w].tnsActive[LOFILT]; else - tnsActive[w] = tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive || - ((channels == 2) ? tnsData[1]->dataRaw.Long.subBlockInfo.tnsActive : 0); + tnsActive[w] = tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT] || + tnsData[0]->dataRaw.Long.subBlockInfo.tnsActive[LOFILT] || + tnsData[channels-1]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT] || + tnsData[channels-1]->dataRaw.Long.subBlockInfo.tnsActive[LOFILT]; } for(ch = 0; ch < channels; ch++) { @@ -1150,8 +1157,8 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, psyData[ch]->sfbMaxScaleSpec.Long, sfbTonality[ch], psyOutChannel[ch]->tnsInfo.order[0][0], - tnsData[ch]->dataRaw.Long.subBlockInfo.predictionGain, - tnsData[ch]->dataRaw.Long.subBlockInfo.tnsActive, + tnsData[ch]->dataRaw.Long.subBlockInfo.predictionGain[HIFILT], + tnsData[ch]->dataRaw.Long.subBlockInfo.tnsActive[HIFILT], psyOutChannel[ch]->sfbEnergyLdData, psyOutChannel[ch]->noiseNrg ); } /* !isLFE */ diff --git a/libAACenc/src/qc_data.h b/libAACenc/src/qc_data.h index a9309c8..00d6090 100644 --- a/libAACenc/src/qc_data.h +++ b/libAACenc/src/qc_data.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -269,6 +269,8 @@ typedef struct BITCNTR_STATE *hBitCounter; ADJ_THR_STATE *hAdjThr; + INT dZoneQuantEnable; /* enable dead zone quantizer */ + } QC_STATE; #endif /* _QC_DATA_H */ diff --git a/libAACenc/src/qc_main.cpp b/libAACenc/src/qc_main.cpp index b74510a..9cd73f6 100644 --- a/libAACenc/src/qc_main.cpp +++ b/libAACenc/src/qc_main.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -107,14 +107,11 @@ typedef struct { } TAB_VBR_QUAL_FACTOR; static const TAB_VBR_QUAL_FACTOR tableVbrQualFactor[] = { - {QCDATA_BR_MODE_CBR, FL2FXCONST_DBL(0.00f)}, {QCDATA_BR_MODE_VBR_1, FL2FXCONST_DBL(0.160f)}, /* 32 kbps mono AAC-LC + SBR + PS */ {QCDATA_BR_MODE_VBR_2, FL2FXCONST_DBL(0.148f)}, /* 64 kbps stereo AAC-LC + SBR */ {QCDATA_BR_MODE_VBR_3, FL2FXCONST_DBL(0.135f)}, /* 80 - 96 kbps stereo AAC-LC */ {QCDATA_BR_MODE_VBR_4, FL2FXCONST_DBL(0.111f)}, /* 128 kbps stereo AAC-LC */ - {QCDATA_BR_MODE_VBR_5, FL2FXCONST_DBL(0.070f)}, /* 192 kbps stereo AAC-LC */ - {QCDATA_BR_MODE_SFR, FL2FXCONST_DBL(0.00f)}, - {QCDATA_BR_MODE_FF, FL2FXCONST_DBL(0.00f)} + {QCDATA_BR_MODE_VBR_5, FL2FXCONST_DBL(0.070f)} /* 192 kbps stereo AAC-LC */ }; static INT isConstantBitrateMode( @@ -369,6 +366,7 @@ QCNew_bail: AAC_ENCODER_ERROR FDKaacEnc_QCInit(QC_STATE *hQC, struct QC_INIT *init) { + int i; hQC->maxBitsPerFrame = init->maxBits; hQC->minBitsPerFrame = init->minBits; hQC->nElements = init->channelMapping->nElements; @@ -382,7 +380,7 @@ AAC_ENCODER_ERROR FDKaacEnc_QCInit(QC_STATE *hQC, if ( isConstantBitrateMode(hQC->bitrateMode) ) { INT bitresPerChannel = (hQC->bitResTotMax / init->channelMapping->nChannelsEff); /* 0: full bitreservoir, 1: reduced bitreservoir, 2: disabled bitreservoir */ - hQC->bitDistributionMode = (bitresPerChannel>100) ? 0 : (bitresPerChannel>0) ? 1 : 2; + hQC->bitDistributionMode = (bitresPerChannel>BITRES_MIN_LD) ? 0 : (bitresPerChannel>0) ? 1 : 2; } else { hQC->bitDistributionMode = 0; /* full bitreservoir */ @@ -399,25 +397,22 @@ AAC_ENCODER_ERROR FDKaacEnc_QCInit(QC_STATE *hQC, (init->averageBits/init->nSubFrames) - hQC->globHdrBits, hQC->maxBitsPerFrame/init->channelMapping->nChannelsEff); - switch(hQC->bitrateMode){ - case QCDATA_BR_MODE_CBR: - case QCDATA_BR_MODE_VBR_1: - case QCDATA_BR_MODE_VBR_2: - case QCDATA_BR_MODE_VBR_3: - case QCDATA_BR_MODE_VBR_4: - case QCDATA_BR_MODE_VBR_5: - case QCDATA_BR_MODE_SFR: - case QCDATA_BR_MODE_FF: - if((int)hQC->bitrateMode < (int)(sizeof(tableVbrQualFactor)/sizeof(TAB_VBR_QUAL_FACTOR))){ - hQC->vbrQualFactor = (FIXP_DBL)tableVbrQualFactor[hQC->bitrateMode].vbrQualFactor; - } else { - hQC->vbrQualFactor = FL2FXCONST_DBL(0.f); /* default setting */ - } - break; - case QCDATA_BR_MODE_INVALID: - default: - hQC->vbrQualFactor = FL2FXCONST_DBL(0.f); + hQC->vbrQualFactor = FL2FXCONST_DBL(0.f); + for (i=0; i<(int)(sizeof(tableVbrQualFactor)/sizeof(TAB_VBR_QUAL_FACTOR)); i++) { + if (hQC->bitrateMode==tableVbrQualFactor[i].bitrateMode) { + hQC->vbrQualFactor = (FIXP_DBL)tableVbrQualFactor[i].vbrQualFactor; break; + } + } + + if (init->channelMapping->nChannelsEff == 1 && + (init->bitrate / init->channelMapping->nChannelsEff) < 32000 && + init->advancedBitsToPe != 0 + ) + { + hQC->dZoneQuantEnable = 1; + } else { + hQC->dZoneQuantEnable = 0; } FDKaacEnc_AdjThrInit( @@ -429,7 +424,8 @@ AAC_ENCODER_ERROR FDKaacEnc_QCInit(QC_STATE *hQC, init->channelMapping->nChannelsEff, init->sampleRate, /* output sample rate */ init->advancedBitsToPe, /* if set, calc bits2PE factor depending on samplerate */ - hQC->vbrQualFactor + hQC->vbrQualFactor, + hQC->dZoneQuantEnable ); return AAC_ENC_OK; @@ -892,6 +888,7 @@ AAC_ENCODER_ERROR FDKaacEnc_QCMain(QC_STATE* RESTRICT hQC, qcOut[c], psyOut[c]->psyOutElement, isConstantBitrateMode(hQC->bitrateMode), + hQC->hAdjThr->maxIter2ndGuess, cm); } /* -end- sub frame counter */ @@ -919,6 +916,7 @@ AAC_ENCODER_ERROR FDKaacEnc_QCMain(QC_STATE* RESTRICT hQC, FDKaacEnc_EstimateScaleFactors(psyOut[c]->psyOutElement[i]->psyOutChannel, qcElement[c][i]->qcOutChannel, hQC->invQuant, + hQC->dZoneQuantEnable, cm->elInfo[i].nChannelsInEl); @@ -1013,7 +1011,8 @@ AAC_ENCODER_ERROR FDKaacEnc_QCMain(QC_STATE* RESTRICT hQC, qcOutCh->mdctSpectrum, qcOutCh->globalGain, qcOutCh->scf, - qcOutCh->quantSpec) ; + qcOutCh->quantSpec, + hQC->dZoneQuantEnable); /*-------------------------------------------- */ if (FDKaacEnc_calcMaxValueInSfb(psyOutCh->sfbCnt, @@ -1263,6 +1262,8 @@ AAC_ENCODER_ERROR FDKaacEnc_updateFillBits(CHANNEL_MAPPING* cm, case QCDATA_BR_MODE_VBR_4: case QCDATA_BR_MODE_VBR_5: qcOut[0]->totFillBits = (qcOut[0]->grantedDynBits - qcOut[0]->usedDynBits)&7; /* precalculate alignment bits */ + qcOut[0]->totalBits = qcOut[0]->staticBits + qcOut[0]->usedDynBits + qcOut[0]->totFillBits + qcOut[0]->elementExtBits + qcOut[0]->globalExtBits; + qcOut[0]->totFillBits += ( fixMax(0, qcKernel->minBitsPerFrame - qcOut[0]->totalBits) + 7) & ~7; break; case QCDATA_BR_MODE_CBR: @@ -1272,6 +1273,8 @@ AAC_ENCODER_ERROR FDKaacEnc_updateFillBits(CHANNEL_MAPPING* cm, /* processing fill-bits */ INT deltaBitRes = qcOut[0]->grantedDynBits - qcOut[0]->usedDynBits ; qcOut[0]->totFillBits = fixMax((deltaBitRes&7), (deltaBitRes - (fixMax(0,bitResSpace-7)&~7))); + qcOut[0]->totalBits = qcOut[0]->staticBits + qcOut[0]->usedDynBits + qcOut[0]->totFillBits + qcOut[0]->elementExtBits + qcOut[0]->globalExtBits; + qcOut[0]->totFillBits += ( fixMax(0, qcKernel->minBitsPerFrame - qcOut[0]->totalBits) + 7) & ~7; break; } /* switch (qcKernel->bitrateMode) */ diff --git a/libAACenc/src/quantize.cpp b/libAACenc/src/quantize.cpp index 5380e35..a74da0e 100644 --- a/libAACenc/src/quantize.cpp +++ b/libAACenc/src/quantize.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -104,13 +104,19 @@ amm-info@iis.fraunhofer.de static void FDKaacEnc_quantizeLines(INT gain, INT noOfLines, FIXP_DBL *mdctSpectrum, - SHORT *quaSpectrum) + SHORT *quaSpectrum, + INT dZoneQuantEnable) { int line; - FIXP_DBL k = FL2FXCONST_DBL(-0.0946f + 0.5f)>>16; + FIXP_DBL k = FL2FXCONST_DBL(0.0f); FIXP_QTD quantizer = FDKaacEnc_quantTableQ[(-gain)&3]; INT quantizershift = ((-gain)>>2)+1; + const INT kShift=16; + if (dZoneQuantEnable) + k = FL2FXCONST_DBL(0.23f)>>kShift; + else + k = FL2FXCONST_DBL(-0.0946f + 0.5f)>>kShift; for (line = 0; line < noOfLines; line++) { @@ -263,7 +269,8 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt, FIXP_DBL *mdctSpectrum, INT globalGain, INT *scalefactors, - SHORT *quantizedSpectrum) + SHORT *quantizedSpectrum, + INT dZoneQuantEnable) { INT sfbOffs,sfb; @@ -280,7 +287,8 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt, FDKaacEnc_quantizeLines(globalGain - scalefactor, /* QSS */ sfbOffset[sfbOffs+sfb+1] - sfbOffset[sfbOffs+sfb], mdctSpectrum + sfbOffset[sfbOffs+sfb], - quantizedSpectrum + sfbOffset[sfbOffs+sfb]); + quantizedSpectrum + sfbOffset[sfbOffs+sfb], + dZoneQuantEnable); } } @@ -296,7 +304,8 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt, FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum, SHORT *quantSpectrum, INT noOfLines, - INT gain + INT gain, + INT dZoneQuantEnable ) { INT i,scale; @@ -311,7 +320,8 @@ FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum, FDKaacEnc_quantizeLines(gain, 1, &mdctSpectrum[i], - &quantSpectrum[i]); + &quantSpectrum[i], + dZoneQuantEnable); if (fAbs(quantSpectrum[i])>MAX_QUANT) { return FL2FXCONST_DBL(0.0f); diff --git a/libAACenc/src/quantize.h b/libAACenc/src/quantize.h index 975b98e..16d3d4e 100644 --- a/libAACenc/src/quantize.h +++ b/libAACenc/src/quantize.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -102,12 +102,14 @@ void FDKaacEnc_QuantizeSpectrum(INT sfbCnt, INT sfbPerGroup, INT *sfbOffset, FIXP_DBL *mdctSpectrum, INT globalGain, INT *scalefactors, - SHORT *quantizedSpectrum); + SHORT *quantizedSpectrum, + INT dZoneQuantEnable); FIXP_DBL FDKaacEnc_calcSfbDist(FIXP_DBL *mdctSpectrum, SHORT *quantSpectrum, INT noOfLines, - INT gain); + INT gain, + INT dZoneQuantEnable); void FDKaacEnc_calcSfbQuantEnergyAndDist(FIXP_DBL *mdctSpectrum, SHORT *quantSpectrum, diff --git a/libAACenc/src/sf_estim.cpp b/libAACenc/src/sf_estim.cpp index 72b75a6..1cb243b 100644 --- a/libAACenc/src/sf_estim.cpp +++ b/libAACenc/src/sf_estim.cpp @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -363,7 +363,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, INT scf, INT minScf, FIXP_DBL *distLdData, - INT *minScfCalculated + INT *minScfCalculated, + INT dZoneQuantEnable ) { FIXP_DBL sfbDistLdData; @@ -375,7 +376,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpec, sfbWidth, - scf); + scf, + dZoneQuantEnable); *minScfCalculated = scf; /* nmr > 1.25 -> try to improve nmr */ if (sfbDistLdData > (threshLdData-distFactorLdData)) { @@ -390,7 +392,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpecTmp, sfbWidth, - scf); + scf, + dZoneQuantEnable); if (sfbDistLdData < sfbDistBestLdData) { scfBest = scf; @@ -408,7 +411,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpecTmp, sfbWidth, - scf); + scf, + dZoneQuantEnable); if (sfbDistLdData < sfbDistBestLdData) { scfBest = scf; @@ -429,7 +433,8 @@ static INT FDKaacEnc_improveScf(FIXP_DBL *spec, sfbDistLdData = FDKaacEnc_calcSfbDist(spec, quantSpecTmp, sfbWidth, - scf); + scf, + dZoneQuantEnable); if (sfbDistLdData < sfbDistAllowedLdData) { *minScfCalculated = scfBest+1; @@ -454,6 +459,7 @@ static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, QC_OUT_CHANNEL *qcOutChannel, SHORT *quantSpec, SHORT *quantSpecTmp, + INT dZoneQuantEnable, INT *scf, INT *minScf, FIXP_DBL *sfbDist, @@ -570,7 +576,8 @@ static void FDKaacEnc_assimilateSingleScf(PSY_OUT_CHANNEL *psyOutChan, sfbDistNew = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs, quantSpecTmp+sfbOffs, sfbWidth, - scfAct); + scfAct, + dZoneQuantEnable); if (sfbDistNew < sfbDist[sfbAct]) { /* success, replace scf by new one */ @@ -629,6 +636,7 @@ static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, QC_OUT_CHANNEL *qcOutChannel, SHORT *quantSpec, SHORT *quantSpecTmp, + INT dZoneQuantEnable, INT *scf, INT *minScf, FIXP_DBL *sfbDist, @@ -724,7 +732,8 @@ static void FDKaacEnc_assimilateMultipleScf(PSY_OUT_CHANNEL *psyOutChan, sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs, quantSpecTmp+sfbOffs, sfbWidth, - scfAct); + scfAct, + dZoneQuantEnable); if (sfbDistNew[sfb] >qcOutChannel->sfbThresholdLdData[sfb]) { /* no improvement, skip further dist. calculations */ @@ -768,6 +777,7 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh QC_OUT_CHANNEL *qcOutChannel, SHORT *quantSpec, SHORT *quantSpecTmp, + INT dZoneQuantEnable, INT *scf, INT *minScf, FIXP_DBL *sfbDist, @@ -883,7 +893,8 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs[sfb], quantSpecTmp+sfbOffs[sfb], sfbOffs[sfb+1]-sfbOffs[sfb], - scfNew); + scfNew, + dZoneQuantEnable); if (sfbDistNew[sfb] > sfbDistMax[sfb]) { /* no improvement, skip further dist. calculations */ @@ -963,7 +974,8 @@ static void FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(PSY_OUT_CHANNEL *psyOutCh sfbDistNew[sfb] = FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+sfbOffs[sfb], quantSpecTmp+sfbOffs[sfb], sfbOffs[sfb+1]-sfbOffs[sfb], - scfNew); + scfNew, + dZoneQuantEnable); if (sfbDistNew[sfb] > qcOutChannel->sfbThresholdLdData[sfb]) { /* no improvement, skip further dist. calculations */ @@ -1058,7 +1070,8 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, INT *RESTRICT globalGain, FIXP_DBL *RESTRICT sfbFormFactorLdData ,const INT invQuant, - SHORT *RESTRICT quantSpec + SHORT *RESTRICT quantSpec, + const INT dZoneQuantEnable ) { INT i, j, sfb, sfbOffs; @@ -1160,7 +1173,8 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, quantSpecTmp+psyOutChannel->sfbOffsets[sfbOffs+sfb], psyOutChannel->sfbOffsets[sfbOffs+sfb+1]-psyOutChannel->sfbOffsets[sfbOffs+sfb], threshLdData, scfInt, minSfMaxQuant[sfbOffs+sfb], - &sfbDistLdData[sfbOffs+sfb], &minScfCalculated[sfbOffs+sfb] + &sfbDistLdData[sfbOffs+sfb], &minScfCalculated[sfbOffs+sfb], + dZoneQuantEnable ); } scf[sfbOffs+sfb] = scfInt; @@ -1187,20 +1201,32 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, sfbNRelevantLines); - FDKaacEnc_assimilateSingleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, scf, + FDKaacEnc_assimilateSingleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, + scf, minSfMaxQuant, sfbDistLdData, sfbConstPePart, sfbFormFactorLdData, sfbNRelevantLines, minScfCalculated, 1); + if(invQuant > 1) { + FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, + scf, + minSfMaxQuant, sfbDistLdData, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines); - FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, scf, - minSfMaxQuant, sfbDistLdData, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines); - + FDKaacEnc_assimilateMultipleScf(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, + scf, + minSfMaxQuant, sfbDistLdData, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines); - FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, scf, - minSfMaxQuant, sfbDistLdData, sfbConstPePart, - sfbFormFactorLdData, sfbNRelevantLines); + FDKaacEnc_FDKaacEnc_assimilateMultipleScf2(psyOutChannel, qcOutChannel, quantSpec, quantSpecTmp, + dZoneQuantEnable, + scf, + minSfMaxQuant, sfbDistLdData, sfbConstPePart, + sfbFormFactorLdData, sfbNRelevantLines); + } } @@ -1223,7 +1249,8 @@ FDKaacEnc_FDKaacEnc_EstimateScaleFactorsChannel(QC_OUT_CHANNEL *qcOutChannel, FDKaacEnc_calcSfbDist(qcOutChannel->mdctSpectrum+psyOutChannel->sfbOffsets[sfbOffs+sfb], quantSpec+psyOutChannel->sfbOffsets[sfbOffs+sfb], psyOutChannel->sfbOffsets[sfbOffs+sfb+1]-psyOutChannel->sfbOffsets[sfbOffs+sfb], - scf[sfbOffs+sfb] + scf[sfbOffs+sfb], + dZoneQuantEnable ); } } @@ -1281,6 +1308,7 @@ void FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[], QC_OUT_CHANNEL* qcOutChannel[], const int invQuant, + const INT dZoneQuantEnable, const int nChannels) { int ch; @@ -1293,7 +1321,8 @@ FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[], &qcOutChannel[ch]->globalGain, qcOutChannel[ch]->sfbFormFactorLdData ,invQuant, - qcOutChannel[ch]->quantSpec + qcOutChannel[ch]->quantSpec, + dZoneQuantEnable ); } diff --git a/libAACenc/src/sf_estim.h b/libAACenc/src/sf_estim.h index b5ac000..ef8d366 100644 --- a/libAACenc/src/sf_estim.h +++ b/libAACenc/src/sf_estim.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -110,6 +110,7 @@ void FDKaacEnc_EstimateScaleFactors(PSY_OUT_CHANNEL *psyOutChannel[], QC_OUT_CHANNEL* qcOutChannel[], const int invQuant, + const INT dZoneQuantEnable, const int nChannels); diff --git a/libAACenc/src/tns_func.h b/libAACenc/src/tns_func.h index 6ee0edb..5e5265d 100644 --- a/libAACenc/src/tns_func.h +++ b/libAACenc/src/tns_func.h @@ -2,7 +2,7 @@ /* ----------------------------------------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. +© Copyright 1995 - 2015 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -100,6 +100,7 @@ AAC_ENCODER_ERROR FDKaacEnc_InitTnsConfiguration(INT bitrate, INT channels, INT blocktype, INT granuleLength, + INT isLowDelay, INT ldSbrPresent, TNS_CONFIG *tnsConfig, PSY_CONFIGURATION *psyConfig, |