diff options
Diffstat (limited to 'libAACenc')
-rw-r--r-- | libAACenc/include/aacenc_lib.h | 6 | ||||
-rw-r--r-- | libAACenc/src/aacenc.cpp | 44 | ||||
-rw-r--r-- | libAACenc/src/aacenc_lib.cpp | 100 | ||||
-rw-r--r-- | libAACenc/src/aacenc_tns.cpp | 21 | ||||
-rw-r--r-- | libAACenc/src/bandwidth.cpp | 2 | ||||
-rw-r--r-- | libAACenc/src/bitenc.cpp | 64 | ||||
-rw-r--r-- | libAACenc/src/dyn_bits.cpp | 2 | ||||
-rw-r--r-- | libAACenc/src/psy_configuration.cpp | 174 | ||||
-rw-r--r-- | libAACenc/src/psy_const.h | 1 | ||||
-rw-r--r-- | libAACenc/src/psy_main.cpp | 2 | ||||
-rw-r--r-- | libAACenc/src/qc_main.cpp | 14 |
11 files changed, 398 insertions, 32 deletions
diff --git a/libAACenc/include/aacenc_lib.h b/libAACenc/include/aacenc_lib.h index 63c3697..de60a7a 100644 --- a/libAACenc/include/aacenc_lib.h +++ b/libAACenc/include/aacenc_lib.h @@ -90,7 +90,7 @@ amm-info@iis.fraunhofer.de * \file aacenc_lib.h * \brief FDK AAC Encoder library interface header file. * -\mainpage Introduction +\page FDK AAC Encoder Library Introduction \section Scope @@ -923,6 +923,7 @@ typedef enum AACENC_GRANULE_LENGTH = 0x0105, /*!< Core encoder (AAC) audio frame length in samples: - 1024: Default configuration. + - 960: DRM/DAB+. - 512: Default LD/ELD configuration. - 480: Optional length in LD/ELD configuration. */ @@ -1028,8 +1029,9 @@ typedef enum For AAC-ELD, the SBR information is transmitted in the ELDSpecific Config, which is part of the AudioSpecificConfig. Therefore, the settings here will have no effect on AAC-ELD.*/ - AACENC_TPSUBFRAMES = 0x0303, /*!< Number of sub frames in a transport frame for LOAS/LATM or ADTS (default 1). + AACENC_TPSUBFRAMES = 0x0303, /*!< Number of sub frames in a transport frame for LOAS/LATM, DAB+ or ADTS (default 1). - ADTS: Maximum number of sub frames restricted to 4. + - DAB+: Maximum number of sub frames restricted to 6. - LOAS/LATM: Maximum number of sub frames restricted to 2.*/ AACENC_AUDIOMUXVER = 0x0304, /*!< AudioMuxVersion to be used for LATM. (AudioMuxVersionA, currently not implemented): diff --git a/libAACenc/src/aacenc.cpp b/libAACenc/src/aacenc.cpp index 5e8c08d..d7b06d0 100644 --- a/libAACenc/src/aacenc.cpp +++ b/libAACenc/src/aacenc.cpp @@ -87,7 +87,7 @@ amm-info@iis.fraunhofer.de contents/description: fast aac coder functions ******************************************************************************/ - +#include <stdio.h> #include "aacenc.h" #include "bitenc.h" @@ -170,6 +170,7 @@ INT FDKaacEnc_LimitBitrate( do { prevBitRate = bitRate; averageBitsPerFrame = (bitRate*(frameLength>>shift)) / (coreSamplingRate>>shift) / nSubFrames; + //fprintf(stderr, "FDKaacEnc_LimitBitrate(): averageBitsPerFrame=%d, prevBitRate=%d, nSubFrames=%d\n", averageBitsPerFrame, prevBitRate, bitRate); if (pAverageBitsPerFrame != NULL) { *pAverageBitsPerFrame = averageBitsPerFrame; @@ -182,14 +183,18 @@ INT FDKaacEnc_LimitBitrate( transportBits = 208; } + //fprintf(stderr, "FDKaacEnc_LimitBitrate(): transportBits=%d, FDKmax(%d, %d)\n", transportBits, bitRate, + // ((((40 * nChannels) + transportBits) * (coreSamplingRate)) / frameLength)); bitRate = FDKmax(bitRate, ((((40 * nChannels) + transportBits) * (coreSamplingRate)) / frameLength) ); FDK_ASSERT(bitRate >= 0); + //fprintf(stderr, "FDKaacEnc_LimitBitrate(): FDKmin(%d, %d)\n", bitRate, ((nChannelsEff * MIN_BUFSIZE_PER_EFF_CHAN)*(coreSamplingRate>>shift)) / (frameLength>>shift)); bitRate = FDKmin(bitRate, ((nChannelsEff * MIN_BUFSIZE_PER_EFF_CHAN)*(coreSamplingRate>>shift)) / (frameLength>>shift)) ; FDK_ASSERT(bitRate >= 0); } while (prevBitRate != bitRate && iter++ < 3) ; + //fprintf(stderr, "FDKaacEnc_LimitBitrate(): bitRate=%d\n", bitRate); return bitRate; } @@ -458,6 +463,36 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, return AAC_ENC_UNSUPPORTED_BITRATE; } + INT superframe_size = 110*8*(config->bitRate/8000); + INT frames_per_superframe = 6; + INT staticBits = 0; + if((config->syntaxFlags & AC_DAB) && hTpEnc) { + staticBits = transportEnc_GetStaticBits(hTpEnc, 0); + switch(config->sampleRate) { + case 48000: + frames_per_superframe=6; + break; + case 32000: + frames_per_superframe=4; + break; + case 24000: + frames_per_superframe=3; + break; + case 16000: + frames_per_superframe=2; + break; + } + + //config->nSubFrames = frames_per_superframe; + //fprintf(stderr, "DAB+ superframe size=%d\n", superframe_size); + config->bitRate = (superframe_size - 16*(frames_per_superframe-1) - staticBits) * 1000/120; + //fprintf(stderr, "DAB+ tuned bitrate=%d\n", config->bitRate); + config->maxBitsPerFrame = (superframe_size - 16*(frames_per_superframe-1) - staticBits) / frames_per_superframe; + config->maxBitsPerFrame += 7; /*padding*/ + //config->bitreservoir=(superframe_size - 16*(frames_per_superframe-1) - staticBits - 2*8)/frames_per_superframe; + //fprintf(stderr, "DAB+ tuned maxBitsPerFrame=%d\n", (superframe_size - 16*(frames_per_superframe-1) - staticBits)/frames_per_superframe); + } + /* check bit rate */ if (FDKaacEnc_LimitBitrate( @@ -489,6 +524,7 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, switch (config->framelength) { case 1024: + case 960: //TODO: DRM if ( config->audioObjectType == AOT_ER_AAC_LD || config->audioObjectType == AOT_ER_AAC_ELD ) { @@ -611,6 +647,7 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize(HANDLE_AAC_ENC hAacEnc, qcInit.averageBits = (averageBitsPerFrame+7)&~7; maxBitres = (MIN_BUFSIZE_PER_EFF_CHAN*cm->nChannelsEff) - qcInit.averageBits; qcInit.bitRes = (config->bitreservoir!=-1) ? FDKmin(config->bitreservoir, maxBitres) : maxBitres; + //fprintf(stderr, "qcInit.bitRes=%d\n", qcInit.bitRes); 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; @@ -736,6 +773,7 @@ AAC_ENCODER_ERROR FDKaacEnc_EncodeFrame( HANDLE_AAC_ENC hAacEnc, /* advance psychoacoustics */ for (el=0; el<cm->nElements; el++) { ELEMENT_INFO elInfo = cm->elInfo[el]; + //fprintf(stderr, "elInfo.elType=%d\n", elInfo.elType); if ( (elInfo.elType == ID_SCE) || (elInfo.elType == ID_CPE) @@ -896,10 +934,13 @@ AAC_ENCODER_ERROR FDKaacEnc_EncodeFrame( HANDLE_AAC_ENC hAacEnc, /* adjust super frame bitrate */ avgTotalBits *= hAacEnc->config->nSubFrames; + //fprintf(stderr, "avgTotalBits=%d x %d\n", avgTotalBits, hAacEnc->config->nSubFrames); } /* Make first estimate of transport header overhead. Take maximum possible frame size into account to prevent bitreservoir underrun. */ + + //fprintf(stderr, "avgTotalBits=%d, bitResTot=%d\n", avgTotalBits, hAacEnc->qcKernel->bitResTot); hAacEnc->qcKernel->globHdrBits = transportEnc_GetStaticBits(hTpEnc, avgTotalBits + hAacEnc->qcKernel->bitResTot); @@ -951,6 +992,7 @@ AAC_ENCODER_ERROR FDKaacEnc_EncodeFrame( HANDLE_AAC_ENC hAacEnc, /*-------------------------------------------- */ /* for ( all sub frames ) ... */ + //fprintf(stderr, "totalBits=%d, qcOut->totalBits=%d, qcOut->totFillBits=%d\n", totalBits, qcOut->totalBits, qcOut->totFillBits); /* write bitstream header */ transportEnc_WriteAccessUnit( hTpEnc, diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp index fc58d6d..fe03f63 100644 --- a/libAACenc/src/aacenc_lib.cpp +++ b/libAACenc/src/aacenc_lib.cpp @@ -87,7 +87,7 @@ amm-info@iis.fraunhofer.de contents/description: FDK HE-AAC Encoder interface library functions ****************************************************************************/ - +#include <stdio.h> #include "aacenc_lib.h" #include "FDK_audio.h" #include "aacenc.h" @@ -368,7 +368,9 @@ static SBR_PS_SIGNALING getSbrSignalingMode( sbrSignaling = SIG_IMPLICIT; /* default: implicit signaling */ } - if ( (audioObjectType==AOT_AAC_LC) || (audioObjectType==AOT_SBR) || (audioObjectType==AOT_PS) ) { + if ((audioObjectType==AOT_AAC_LC) || (audioObjectType==AOT_SBR) || (audioObjectType==AOT_PS) || + (audioObjectType==AOT_MP2_AAC_LC) || (audioObjectType==AOT_MP2_SBR) || (audioObjectType==AOT_MP2_PS) || + (audioObjectType==AOT_DABPLUS_SBR) || (audioObjectType==AOT_DABPLUS_PS) ) { switch (transportType) { case TT_MP4_ADIF: case TT_MP4_ADTS: @@ -424,7 +426,25 @@ static void FDKaacEnc_MapConfig( cc->flags = 0; - transport_AOT = hAacConfig->audioObjectType; + /* Map virtual aot to transport aot. */ + switch (hAacConfig->audioObjectType) { + case AOT_DABPLUS_AAC_LC: + case AOT_MP2_AAC_LC: + transport_AOT = AOT_AAC_LC; + break; + case AOT_DABPLUS_SBR: + case AOT_MP2_SBR: + transport_AOT = AOT_SBR; + cc->flags |= CC_SBR; + break; + case AOT_DABPLUS_PS: + case AOT_MP2_PS: + transport_AOT = AOT_PS; + cc->flags |= CC_SBR; + break; + default: + transport_AOT = hAacConfig->audioObjectType; + } if (hAacConfig->audioObjectType == AOT_ER_AAC_ELD) { cc->flags |= (hAacConfig->syntaxFlags & AC_SBR_PRESENT) ? CC_SBR : 0; @@ -465,9 +485,27 @@ static void FDKaacEnc_MapConfig( cc->flags |= CC_IS_BASELAYER; cc->channelMode = hAacConfig->channelMode; - cc->nSubFrames = (hAacConfig->nSubFrames > 1 && extCfg->userTpNsubFrames == 1) + if(extCfg->userTpType == TT_DABPLUS && hAacConfig->nSubFrames==1) { + switch(hAacConfig->sampleRate) { + case 48000: + cc->nSubFrames=6; + break; + case 32000: + cc->nSubFrames=4; + break; + case 24000: + cc->nSubFrames=3; + break; + case 16000: + cc->nSubFrames=2; + break; + } + //fprintf(stderr, "hAacConfig->nSubFrames=%d hAacConfig->sampleRate=%d\n", hAacConfig->nSubFrames, hAacConfig->sampleRate); + } else { + cc->nSubFrames = (hAacConfig->nSubFrames > 1 && extCfg->userTpNsubFrames == 1) ? hAacConfig->nSubFrames : extCfg->userTpNsubFrames; + } cc->flags |= (extCfg->userTpProtection) ? CC_PROTECTION : 0; @@ -724,6 +762,7 @@ INT aacEncoder_LimitBitrate( FDK_ASSERT(bitRate > 0); + //fprintf(stderr, "aacEncoder_LimitBitrate(): bitRate=%d\n", bitRate); return bitRate; } @@ -734,7 +773,7 @@ INT aacEncoder_LimitBitrate( * * \hAacEncoder Internal encoder config which is to be updated * \param config User provided config (public struct) - * \return ´returns always AAC_ENC_OK + * \return �returns always AAC_ENC_OK */ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, @@ -777,10 +816,36 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, case AOT_PS: config->userTpType = (config->userTpType!=TT_UNKNOWN) ? config->userTpType : TT_MP4_ADTS; hAacConfig->framelength = (config->userFramelength!=(UINT)-1) ? config->userFramelength : 1024; - if (hAacConfig->framelength != 1024) { + if (hAacConfig->framelength != 1024 && hAacConfig->framelength != 960) { return AACENC_INVALID_CONFIG; } break; + case AOT_DABPLUS_SBR: + case AOT_DABPLUS_PS: + hAacConfig->syntaxFlags |= ((config->userSbrEnabled) ? AC_SBR_PRESENT : 0); + case AOT_DABPLUS_AAC_LC: + config->userTpType = (config->userTpType!=TT_UNKNOWN) ? config->userTpType : TT_DABPLUS; + hAacConfig->framelength = (config->userFramelength!=(UINT)-1) ? config->userFramelength : 960; + if (hAacConfig->framelength != 960) { + return AACENC_INVALID_CONFIG; + } + config->userTpSignaling=2; + if(config->userTpType == TT_DABPLUS) + hAacConfig->syntaxFlags |= AC_DAB; + break; +#if 0 + case AOT_ER_AAC_LC: + hAacConfig->epConfig = 0; + hAacConfig->syntaxFlags |= AC_ER; + hAacConfig->syntaxFlags |= ((config->userErTools & 0x1) ? AC_ER_VCB11 : 0); + hAacConfig->syntaxFlags |= ((config->userErTools & 0x2) ? AC_ER_HCR : 0); + config->userTpType = (config->userTpType!=TT_UNKNOWN) ? config->userTpType : TT_MP4_LOAS; + hAacConfig->framelength = (config->userFramelength!=(UINT)-1) ? config->userFramelength : 1024; + if (hAacConfig->framelength != 1024 && hAacConfig->framelength != 960) { + return AACENC_INVALID_CONFIG; + } + break; +#endif case AOT_ER_AAC_LD: hAacConfig->epConfig = 0; hAacConfig->syntaxFlags |= AC_ER|AC_LD; @@ -810,6 +875,7 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, break; } + switch ( hAacConfig->audioObjectType ) { case AOT_ER_AAC_LD: case AOT_ER_AAC_ELD: @@ -927,6 +993,7 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, + //fprintf(stderr, "config->userBitrate=%d\n", config->userBitrate); /* We need the frame length to call aacEncoder_LimitBitrate() */ hAacConfig->bitRate = aacEncoder_LimitBitrate( NULL, @@ -940,6 +1007,7 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, hAacConfig->sbrRatio, hAacConfig->audioObjectType ); + //fprintf(stderr, "hAacConfig->bitRate=%d\n", hAacConfig->bitRate); /* Configure PNS */ if ( ((hAacConfig->bitrateMode>=1) && (hAacConfig->bitrateMode<=5)) /* VBR without PNS. */ @@ -984,6 +1052,7 @@ AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, hAacEncoder->metaDataAllowed = 0; } + //fprintf(stderr, "hAacEncoder->metaDataAllowed=%d\n", hAacEncoder->metaDataAllowed); return err; } @@ -1744,6 +1813,7 @@ AACENC_ERROR aacEncGetLibInfo(LIB_INFO *info) /* Capability flags */ info[i].flags = 0 | CAPF_AAC_1024 | CAPF_AAC_LC + | CAPF_AAC_960 | CAPF_AAC_512 | CAPF_AAC_480 | CAPF_AAC_DRC @@ -1776,16 +1846,23 @@ AACENC_ERROR aacEncoder_SetParam( /* check if AOT matches the allocated modules */ switch ( value ) { case AOT_PS: + case AOT_DRM_SBR: // Added mfeilen + case AOT_DABPLUS_PS: + case AOT_MP2_PS: if (!(hAacEncoder->encoder_modis & (ENC_MODE_FLAG_PS))) { err = AACENC_INVALID_CONFIG; goto bail; } case AOT_SBR: + case AOT_DABPLUS_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_DABPLUS_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))) { @@ -1811,7 +1888,12 @@ AACENC_ERROR aacEncoder_SetParam( if (settings->userBitrateMode != value) { switch ( value ) { case 0: - case 1: case 2: case 3: case 4: case 5: + case 1: + case 2: + case 3: + case 4: + case 5: + case 7: case 8: settings->userBitrateMode = value; hAacEncoder->InitFlags |= AACENC_INIT_CONFIG | AACENC_INIT_TRANSPORT; @@ -1888,6 +1970,7 @@ AACENC_ERROR aacEncoder_SetParam( if (settings->userFramelength != value) { switch (value) { case 1024: + case 960: case 512: case 480: settings->userFramelength = value; @@ -1927,6 +2010,7 @@ AACENC_ERROR aacEncoder_SetParam( || ((type==TT_MP4_LATM_MCP1) && ((flags&CAPF_LATM) && (flags&CAPF_RAWPACKETS))) || ((type==TT_MP4_LOAS) && (flags&CAPF_LOAS)) || ((type==TT_MP4_RAW) && (flags&CAPF_RAWPACKETS)) + || ((type==TT_DABPLUS) && ((flags&CAPF_DAB_AAC) && (flags&CAPF_RAWPACKETS))) ) ) { err = AACENC_INVALID_CONFIG; @@ -1974,7 +2058,7 @@ AACENC_ERROR aacEncoder_SetParam( break; case AACENC_TPSUBFRAMES: if (settings->userTpNsubFrames != value) { - if (! ( (value>=1) && (value<=4) ) ) { + if (! ( (value>=1) && (value<=6) ) ) { err = AACENC_INVALID_CONFIG; break; } diff --git a/libAACenc/src/aacenc_tns.cpp b/libAACenc/src/aacenc_tns.cpp index 9a07e8f..d0ff6ac 100644 --- a/libAACenc/src/aacenc_tns.cpp +++ b/libAACenc/src/aacenc_tns.cpp @@ -166,6 +166,22 @@ static const TNS_MAX_TAB_ENTRY tnsMaxBandsTab1024[] = { 8000, { 39, 14}} }; +static const TNS_MAX_TAB_ENTRY tnsMaxBandsTab960[] = +{ + { 96000, { 31, 9}}, + { 88200, { 31, 9}}, + { 64000, { 34, 10}}, + { 48000, { 49, 14}}, + { 44100, { 49, 14}}, + { 32000, { 49, 14}}, + { 24000, { 46, 15}}, + { 22050, { 46, 14}}, + { 16000, { 46, 15}}, + { 12000, { 42, 15}}, + { 11025, { 42, 15}}, + { 8000, { 40, 15}} +}; + static const TNS_MAX_TAB_ENTRY tnsMaxBandsTab480[] = { { 48000, { 31, -1}}, @@ -261,6 +277,10 @@ static INT getTnsMaxBands( int maxBandsTabSize = 0; switch (granuleLength) { + case 960: + pMaxBandsTab = tnsMaxBandsTab960; + maxBandsTabSize = sizeof(tnsMaxBandsTab960)/sizeof(TNS_MAX_TAB_ENTRY); + break; case 1024: pMaxBandsTab = tnsMaxBandsTab1024; maxBandsTabSize = sizeof(tnsMaxBandsTab1024)/sizeof(TNS_MAX_TAB_ENTRY); @@ -386,6 +406,7 @@ AAC_ENCODER_ERROR FDKaacEnc_InitTnsConfiguration(INT bitRate, tC->lpcStopLine = pC->sfbOffset[tC->lpcStopBand]; switch (granuleLength) { + case 960: case 1024: /* TNS start line: skip lower MDCT lines to prevent artifacts due to filter mismatch */ tC->lpcStartBand[LOFILT] = (blockType == SHORT_WINDOW) ? 0 : ((sampleRate < 18783) ? 4 : 8); diff --git a/libAACenc/src/bandwidth.cpp b/libAACenc/src/bandwidth.cpp index 6937362..af2a2cf 100644 --- a/libAACenc/src/bandwidth.cpp +++ b/libAACenc/src/bandwidth.cpp @@ -204,6 +204,7 @@ static INT GetBandwidthEntry( INT bwTabSize = 0; switch (frameLength) { + case 960: case 1024: pBwTab = bandWidthTable; bwTabSize = sizeof(bandWidthTable)/sizeof(BANDWIDTH_TAB); @@ -252,6 +253,7 @@ static INT GetBandwidthEntry( chanBitRate < pBwTab[i+1].chanBitRate) { switch (frameLength) { + case 960: case 1024: bandwidth = (entryNo==0) ? pBwTab[i].bandWidthMono diff --git a/libAACenc/src/bitenc.cpp b/libAACenc/src/bitenc.cpp index 8e477aa..4552457 100644 --- a/libAACenc/src/bitenc.cpp +++ b/libAACenc/src/bitenc.cpp @@ -87,7 +87,7 @@ amm-info@iis.fraunhofer.de contents/description: Bitstream encoder ******************************************************************************/ - +#include <stdio.h> #include "bitenc.h" #include "bit_cnt.h" #include "dyn_bits.h" @@ -645,7 +645,7 @@ static INT FDKaacEnc_writeExtensionPayload( HANDLE_FDK_BITSTREAM hBitStream, #define FILL_NIBBLE_BITS ( 4 ) INT extBitsUsed = 0; - + //fprintf(stderr, "FDKaacEnc_writeExtensionPayload() extPayloadType=%d\n", extPayloadType); if (extPayloadBits >= EXT_TYPE_BITS) { UCHAR fillByte = 0x00; /* for EXT_FIL and EXT_FILL_DATA */ @@ -749,7 +749,7 @@ static INT FDKaacEnc_writeDataStreamElement( HANDLE_TRANSPORTENC hTpEnc, #define MAX_DSE_DATA_BYTES ( 510 ) INT dseBitsUsed = 0; - + //fprintf(stderr, "FDKaacEnc_writeDataStreamElement() dataPayloadBytes=%d\n", dataPayloadBytes); while (dataPayloadBytes > 0) { int esc_count = -1; @@ -840,6 +840,7 @@ INT FDKaacEnc_writeExtensionData( HANDLE_TRANSPORTENC hTpEnc, hBitStream = transportEnc_GetBitstream(hTpEnc); } + //fprintf(stderr, "FDKaacEnc_writeExtensionData() pExtension->type=%d\n", pExtension->type); if (syntaxFlags & (AC_SCALABLE|AC_ER)) { if ( syntaxFlags & AC_DRM ) @@ -1196,6 +1197,7 @@ AAC_ENCODER_ERROR FDKaacEnc_ChannelElementWrite( HANDLE_TRANSPORTENC hTpEnc, case esc1_hcr: + //TODO: DRM! if (syntaxFlags & AC_ER_HCR) { error = AAC_ENC_UNKNOWN; @@ -1301,6 +1303,23 @@ AAC_ENCODER_ERROR FDKaacEnc_WriteBitstream(HANDLE_TRANSPORTENC hTpEnc, frameBits = bitMarkUp = alignAnchor; + /* Write DSEs first in case of DAB */ + for (n = 0; (n < qcOut->nExtensions) && (n < (2+2)); n++) + { + if ( (syntaxFlags & AC_DAB) && + (qcOut->extension[n].type == EXT_DATA_ELEMENT) ) { + FDKaacEnc_writeExtensionData( hTpEnc, + &qcOut->extension[n], + 0, + alignAnchor, + syntaxFlags, + aot, + epConfig ); + } + + /* For EXT_FIL or EXT_FILL_DATA we could do an additional sanity check here */ + } + /* Channel element loop */ for (i=0; i<channelMapping->nElements; i++) { @@ -1392,7 +1411,7 @@ AAC_ENCODER_ERROR FDKaacEnc_WriteBitstream(HANDLE_TRANSPORTENC hTpEnc, if (channelElementExtensionWritten[i][n]==0) { - /* Write all ramaining extension payloads in element */ + /* Write all remaining extension payloads in element */ FDKaacEnc_writeExtensionData( hTpEnc, &qcOut->qcElement[i]->extension[n], 0, @@ -1429,25 +1448,38 @@ AAC_ENCODER_ERROR FDKaacEnc_WriteBitstream(HANDLE_TRANSPORTENC hTpEnc, /* Add fill data / stuffing bits */ n = qcOut->nExtensions; - qcOut->extension[n].type = EXT_FILL_DATA; - qcOut->extension[n].nPayloadBits = qcOut->totFillBits; - qcOut->nExtensions++; + +// if (!(syntaxFlags & AC_DAB)) { + qcOut->extension[n].type = EXT_FILL_DATA; + qcOut->extension[n].nPayloadBits = qcOut->totFillBits; + qcOut->nExtensions++; +// } else { +// doByteAlign = 0; +// } + if (syntaxFlags & AC_DAB) + doByteAlign = 0; /* Write global extension payload and fill data */ for (n = 0; (n < qcOut->nExtensions) && (n < (2+2)); n++) { - FDKaacEnc_writeExtensionData( hTpEnc, - &qcOut->extension[n], - 0, - alignAnchor, - syntaxFlags, - aot, - epConfig ); + if ( !(syntaxFlags & AC_DAB) || + ( (syntaxFlags & AC_DAB) && + (qcOut->extension[n].type != EXT_DATA_ELEMENT) + ) + ) { + FDKaacEnc_writeExtensionData( hTpEnc, + &qcOut->extension[n], + 0, + alignAnchor, + syntaxFlags, + aot, + epConfig ); + } /* For EXT_FIL or EXT_FILL_DATA we could do an additional sanity check here */ } - if (!(syntaxFlags & (AC_SCALABLE|AC_ER))) { + if (!(syntaxFlags & (AC_SCALABLE|AC_ER|AC_DAB))) { FDKwriteBits(hBs, ID_END, EL_ID_BITS); } @@ -1466,9 +1498,11 @@ AAC_ENCODER_ERROR FDKaacEnc_WriteBitstream(HANDLE_TRANSPORTENC hTpEnc, transportEnc_EndAccessUnit(hTpEnc, &frameBits); if (frameBits != qcOut->totalBits + qcKernel->globHdrBits){ + fprintf(stderr, "frameBits != qcOut->totalBits + qcKernel->globHdrBits: %d != %d + %d", frameBits, qcOut->totalBits, qcKernel->globHdrBits); return AAC_ENC_WRITTEN_BITS_ERROR; } + //fprintf(stderr, "ErrorStatus=%d", ErrorStatus); return ErrorStatus; } diff --git a/libAACenc/src/dyn_bits.cpp b/libAACenc/src/dyn_bits.cpp index 0c07109..3105fb4 100644 --- a/libAACenc/src/dyn_bits.cpp +++ b/libAACenc/src/dyn_bits.cpp @@ -416,6 +416,8 @@ static void FDKaacEnc_noiselessCounter( break; } + FDK_ASSERT(sideInfoTab != NULL); + sectionData->noOfSections = 0; sectionData->huffmanBits = 0; sectionData->sideInfoBits = 0; diff --git a/libAACenc/src/psy_configuration.cpp b/libAACenc/src/psy_configuration.cpp index 9a72c68..45b7d13 100644 --- a/libAACenc/src/psy_configuration.cpp +++ b/libAACenc/src/psy_configuration.cpp @@ -119,6 +119,161 @@ static const SFB_INFO_TAB sfbInfoTab[] = { }; + + +const SFB_PARAM_LONG p_FDKaacEnc_8000_long_960 = { + 40, + { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 16, + 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28, + 28, 32, 36, 36, 40, 44, 48, 52, 56, 60, 64, 16 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_8000_short_120 = { + 15, + { 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 12 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_11025_long_960 = { + 42, + { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, + 24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_11025_short_120 = { + 15, + { 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 12 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_12000_long_960 = { + 42, + { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, + 24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_12000_short_120 = { + 15, + { 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 12 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_16000_long_960 = { + 42, + { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, + 24, 28, 28, 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_16000_short_120 = { + 15, + { 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 12 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_22050_long_960 = { + 46, + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 12, 16, 16, 16, + 20, 20, 24, 24, 28, 28, 32, 36, 36, 40, 44, 48, 52, 52, + 64, 64, 64, 64 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_22050_short_120 = { + 15, + { 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 12 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_24000_long_960 = { + 46, + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 12, 16, 16, 16, + 20, 20, 24, 24, 28, 28, 32, 36, 36, 40, 44, 48, 52, 52, + 64, 64, 64, 64 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_24000_short_120 = { + 15, + { 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 12 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_32000_long_960 = { + 49, + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, + 12, 16, 16, 20, 20, 24, 24, 28, 28, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32 } +}; + +const SFB_PARAM_SHORT p_FDKaacEnc_32000_short_120 = { + 14, + { 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 8 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_44100_long_960 = { + 49, + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, + 8, 8, 8, 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, + 28, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32 } +}; + +const SFB_PARAM_SHORT p_FDKaacEnc_44100_short_120 = { + 14, + { 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 8 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_48000_long_960 = { + 49, + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, + 8, 8, 8, 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, + 28, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_48000_short_120 = { + 14, + { 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 8 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_64000_long_960 = { + 46, + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 12, + 12, 16, 16, 16, 20, 24, 24, 28, 36, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, + 40, 40, 40, 40, 40, 16 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_64000_short_120 = { + 12, + { 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 28 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_88200_long_960 = { + 40, + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 12, + 12, 12, 12, 12, 16, 16, 24, 28, 36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_88200_short_120 = { + 12, + { 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 28 } +}; + +const SFB_PARAM_LONG p_FDKaacEnc_96000_long_960 = { + 40, + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 12, + 12, 12, 12, 12, 16, 16, 24, 28, 36, 44, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 } +}; +const SFB_PARAM_SHORT p_FDKaacEnc_96000_short_120 = { + 12, + { 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 28 } +}; + + +static const SFB_INFO_TAB sfbInfoTab960[] = { + { 8000, &p_FDKaacEnc_8000_long_960, &p_FDKaacEnc_8000_short_120}, + {11025, &p_FDKaacEnc_11025_long_960, &p_FDKaacEnc_11025_short_120}, + {12000, &p_FDKaacEnc_12000_long_960, &p_FDKaacEnc_12000_short_120}, + {16000, &p_FDKaacEnc_16000_long_960, &p_FDKaacEnc_16000_short_120}, + {22050, &p_FDKaacEnc_22050_long_960, &p_FDKaacEnc_22050_short_120}, + {24000, &p_FDKaacEnc_24000_long_960, &p_FDKaacEnc_24000_short_120}, + {32000, &p_FDKaacEnc_32000_long_960, &p_FDKaacEnc_32000_short_120}, + {44100, &p_FDKaacEnc_44100_long_960, &p_FDKaacEnc_44100_short_120}, + {48000, &p_FDKaacEnc_48000_long_960, &p_FDKaacEnc_48000_short_120}, + {64000, &p_FDKaacEnc_64000_long_960, &p_FDKaacEnc_64000_short_120}, + {88200, &p_FDKaacEnc_88200_long_960, &p_FDKaacEnc_88200_short_120}, + {96000, &p_FDKaacEnc_96000_long_960, &p_FDKaacEnc_96000_short_120}, +}; + + /* 22050 and 24000 Hz */ static const SFB_PARAM_LONG p_22050_long_512 = { 31, @@ -220,10 +375,13 @@ static AAC_ENCODER_ERROR FDKaacEnc_initSfbTable(LONG sampleRate, INT blockType, */ switch(granuleLength) { case 1024: - case 960: sfbInfo = sfbInfoTab; size = (INT)(sizeof(sfbInfoTab)/sizeof(SFB_INFO_TAB)); break; + case 960: + sfbInfo = sfbInfoTab960; + size = (INT)(sizeof(sfbInfoTab960)/sizeof(SFB_INFO_TAB)); + break; case 512: sfbInfo = sfbInfoTabLD512; size = sizeof(sfbInfoTabLD512); @@ -307,9 +465,15 @@ static FIXP_DBL FDKaacEnc_BarcLineValue(INT noOfLines, INT fftLine, LONG samplin case 1024: center_freq = center_freq << 2; /* q13 */ break; + case 960: + center_freq = fMult(center_freq, INV480) << 3; + break; case 128: center_freq = center_freq << 5; /* q13 */ break; + case 120: + center_freq = fMult(center_freq, INV480) << 6; + break; case 512: center_freq = (fftLine * samplingFreq) << 3; // q13 break; @@ -505,6 +669,14 @@ static void FDKaacEnc_initMinSnr(const LONG bitrate, qperwin = qperwin - 9; pePerWindow = fMult(pePerWindow, FL2FXCONST_DBL(480.f/512.f)); break; + case 960: + pePerWindow = fMult(pePerWindow, FL2FXCONST_DBL(960.f/1024.f)); + qperwin = qperwin - 10; + break; + case 120: + pePerWindow = fMult(pePerWindow, FL2FXCONST_DBL(120.f/128.f)); + qperwin = qperwin - 7; + break; } /* for short blocks it is assumed that more bits are available */ diff --git a/libAACenc/src/psy_const.h b/libAACenc/src/psy_const.h index d9c9f43..15a69c9 100644 --- a/libAACenc/src/psy_const.h +++ b/libAACenc/src/psy_const.h @@ -96,6 +96,7 @@ amm-info@iis.fraunhofer.de #define TRANS_FAC 8 /* encoder short long ratio */ +#define FRAME_LEN_LONG_960 (960) #define FRAME_MAXLEN_SHORT ((1024)/TRANS_FAC) #define FRAME_LEN_SHORT_128 ((1024)/TRANS_FAC) diff --git a/libAACenc/src/psy_main.cpp b/libAACenc/src/psy_main.cpp index 446c894..eeb0fa2 100644 --- a/libAACenc/src/psy_main.cpp +++ b/libAACenc/src/psy_main.cpp @@ -818,7 +818,7 @@ AAC_ENCODER_ERROR FDKaacEnc_psyMain(INT channels, &hThisPsyConf[1]->tnsConf); } - FDK_ASSERT(1==commonWindow); /* all checks for TNS do only work for common windows (which is always set)*/ + FDK_ASSERT(commonWindow==1); /* all checks for TNS do only work for common windows (which is always set)*/ for(w = 0; w < nWindows[0]; w++) { if (isShortWindow[0]) diff --git a/libAACenc/src/qc_main.cpp b/libAACenc/src/qc_main.cpp index 9cd73f6..1025894 100644 --- a/libAACenc/src/qc_main.cpp +++ b/libAACenc/src/qc_main.cpp @@ -87,7 +87,7 @@ amm-info@iis.fraunhofer.de contents/description: Quantizing & coding ******************************************************************************/ - +#include <stdio.h> #include "qc_main.h" #include "quantize.h" #include "interface.h" @@ -487,20 +487,24 @@ AAC_ENCODER_ERROR FDKaacEnc_AdjustBitrate(QC_STATE *RESTRICT hQC, INT sampleRate, /* output sampling rate */ INT granuleLength) /* frame length */ { - INT paddingOn; + INT paddingOn=0; INT frameLen; + //fprintf(stderr, "hQC->padding.paddingRest=%d bytes! (before)\n", hQC->padding.paddingRest); /* Do we need an extra padding byte? */ paddingOn = FDKaacEnc_framePadding(bitRate, sampleRate, granuleLength, &hQC->padding.paddingRest); + //fprintf(stderr, "hQC->padding.paddingRest=%d bytes! (after)\n", hQC->padding.paddingRest); frameLen = paddingOn + FDKaacEnc_calcFrameLen(bitRate, sampleRate, granuleLength, FRAME_LEN_BYTES_INT); + //fprintf(stderr, "frameLen=%d bytes!\n", frameLen); + *avgTotalBits = frameLen<<3; return AAC_ENC_OK; @@ -1377,7 +1381,7 @@ AAC_ENCODER_ERROR FDKaacEnc_FinalizeBitConsumption(CHANNEL_MAPPING *cm, /* Get total consumed bits in AU */ qcOut->totalBits = qcOut->staticBits + qcOut->usedDynBits + qcOut->totFillBits + qcOut->elementExtBits + qcOut->globalExtBits; - +#if 1 if (qcKernel->bitrateMode==QCDATA_BR_MODE_CBR) { /* Now we can get the exact transport bit amount, and hopefully it is equal to the estimated value */ @@ -1419,7 +1423,7 @@ AAC_ENCODER_ERROR FDKaacEnc_FinalizeBitConsumption(CHANNEL_MAPPING *cm, } } /* MODE_CBR */ - +#endif /* Update exact number of consumed header bits. */ qcKernel->globHdrBits = transportEnc_GetStaticBits(hTpEnc, qcOut->totalBits); @@ -1440,6 +1444,8 @@ AAC_ENCODER_ERROR FDKaacEnc_FinalizeBitConsumption(CHANNEL_MAPPING *cm, aot, epConfig ); + //fprintf(stderr, "FinalizeBitConsumption(): totFillBits=%d, qcOut->totFillBits=%d \n", totFillBits, qcOut->totFillBits); + /* now distribute extra fillbits and alignbits */ alignBits = 7 - (qcOut->staticBits + qcOut->usedDynBits + qcOut->elementExtBits + qcOut->totFillBits + qcOut->globalExtBits -1)%8; |