This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DM365 AAC decode with ADTS headers

Hi All,

Using dm365_aaclcenc_3_5_00 and dm365_aaclcdec_6_1_00 production codecs, I encode the audio using aacenc with ADTS headers just fine.  It plays correctly in VLC and mplayer.  But when I try to decode the file using aacdec, no bytes are consumed nor output, and the Adec1_process call returns no errors.  The Adec1 is configured with ITTIAM_ENHAACPDEC_Params aacParams = ENHAACPDECODER_ITTIAM_PARAMS;

aacParams.i_max_channels = 2
         .i_flag_08khz_out = 0
         .i_flag_16khz_out = 0
         .i_interleave = 1
         .i_disable_sync = 0
         .i_mp4_flag = 0
         .i_sampfreq = 48000
         .i_coupling_channel = 0

I tried i_disable_sync = 1, but that didn't work either.

Here's what I see when I print the results of the Adec1_process call, and the first few bytes sent:

audioPlaybackThrFxn: AAC process consumed 0, size 512, output 0
  ff f9 4c 80  40 1f fc 21  20 03 40 68  1b ff c0 00
audioPlaybackThrFxn: AAC process consumed 0, size 677, output 0
  ff f9 4c 80  54 bf fc 21  4e 6c fe ff  3f ff ff ff
audioPlaybackThrFxn: AAC process consumed 0, size 562, output 0
  ff f9 4c 80  46 5f fc 21  7c 4b bd 7b  ff ff ff fe
audioPlaybackThrFxn: AAC process consumed 0, size 542, output 0
  ff f9 4c 80  43 df fc 21  1c 4f b9 fe  ff ff ff fe

I can encode and decode successfully without ADTS headers, but I need to use ADTS headers for this application.  Any suggestions?

Here's the file: 2055.output.aac

  • The issue here is that the params are set for "raw" aac file.

    If you are trying to use a ADTS file, then in the params structure .i_sampfreq should be set to 0.

     

    Regards,

    Sonal

  • Hi Pete,

    I also using dm365_aaclcdec_6_1_00 production codecs to decode the AAC file, but i use the demo "audio.c(dec)" in the folder "dvsdk_2_10_01_18_demos_update" ,  and i cannot decode successfully without /with ADTS headers. The aac file is single channel with 16000 samplerate,  here are my configurations:

    AUDDEC1_Params          defaultParams       = Adec1_Params_DEFAULT;
    AUDDEC1_DynamicParams   defaultDynParams    = Adec1_DynamicParams_DEFAULT;

    const AUDDEC1_Params Adec1_Params_DEFAULT = {
        sizeof(AUDDEC1_Params),
        16,
        IAUDIO_INTERLEAVED,
        XDM_LE_16,
    };

    const AUDDEC1_DynamicParams Adec1_DynamicParams_DEFAULT = {
        sizeof(AUDDEC1_DynamicParams),
        XDAS_FALSE,
    };

    Sound_Attrs  sAttrs = Sound_Attrs_STEREO_DEFAULT;

    sAttrs.sampleRate  = 16000;
    sAttrs.channels  = 1;      
    sAttrs.bufSize     = 4096;
    sAttrs.mode   = Sound_Mode_OUTPUT; 
    sAttrs.soundStd  = Sound_Std_ALSA;

    And the Adec1.c file:

    /******************************************************************************
     * Adec1_create
     ******************************************************************************/
    Adec1_Handle Adec1_create(Engine_Handle hEngine, Char *codecName,
                            AUDDEC1_Params *params,
                            AUDDEC1_DynamicParams *dynParams)
    {
        Adec1_Handle        hAd1;
        AUDDEC1_Handle      hDecode;
        AUDDEC1_Status      decStatus;
        XDAS_Int32          status;

        if (hEngine == NULL || codecName == NULL ||
            params == NULL || dynParams == NULL) {
            Dmai_err0("Cannot pass null for engine, codec name, params or "
                      "dynamic params\n");
            return NULL;
        }

        /* Allocate space for the object */
        hAd1 = (Adec1_Handle)calloc(1, sizeof(Adec1_Object));

        if (hAd1 == NULL) {
            Dmai_err0("Failed to allocate space for Adec1 Object\n");
            return NULL;
        }

        /* Create audio decoder */
        hDecode = AUDDEC1_create(hEngine, codecName, params);

        if (hDecode == NULL) {
            Dmai_err1("Failed to open audio decode algorithm: %s\n", codecName);
            cleanup(hAd1);
            return NULL;
        }

        /* Set dynamic parameters */
        decStatus.data.buf = NULL;
        decStatus.size = sizeof(AUDDEC1_Status);
        status = AUDDEC1_control(hDecode, XDM_SETPARAMS, dynParams, &decStatus);

        if (status != AUDDEC1_EOK) {
            Dmai_err1("XDM_SETPARAMS failed, status=%d\n", status);
            cleanup(hAd1);
            return NULL;
        }

        /* Get buffer information from audio decoder */
        status = AUDDEC1_control(hDecode, XDM_GETBUFINFO, dynParams, &decStatus);

        if (status != AUDDEC1_EOK) {
            Dmai_err0("XDM_GETBUFINFO control failed\n");
            cleanup(hAd1);
            return NULL;
        }

        Dmai_dbg2("Codec requires buffer sizes in %u and out %u\n",
                  decStatus.bufInfo.minInBufSize[0],
                  decStatus.bufInfo.minOutBufSize[0]);

        memcpy(hAd1->minInBufSize,
               decStatus.bufInfo.minInBufSize, sizeof(hAd1->minInBufSize));
        hAd1->minNumInBufs = decStatus.bufInfo.minNumInBufs;
        memcpy(hAd1->minOutBufSize,
               decStatus.bufInfo.minOutBufSize, sizeof(hAd1->minOutBufSize));
        hAd1->minNumOutBufs = decStatus.bufInfo.minNumOutBufs;

        hAd1->hDecode = hDecode;
        hAd1->sampleRate = 0;     //    Do i need to change this to 16000?

        return hAd1;
    }

    Int Adec1_process(Adec1_Handle hAd1, Buffer_Handle hInBuf, Buffer_Handle hOutBuf)
    {
        XDM1_BufDesc            inBufDesc;
        XDM1_BufDesc            outBufDesc;
        XDAS_Int32              status;
        AUDDEC1_InArgs          inArgs;
        AUDDEC1_OutArgs         outArgs;
        Int                     channels;

        assert(hAd1);
        assert(hInBuf);
        assert(hOutBuf);
        assert(Buffer_getUserPtr(hInBuf));
        assert(Buffer_getUserPtr(hOutBuf));
        assert(Buffer_getNumBytesUsed(hInBuf));
        assert(Buffer_getSize(hOutBuf));

        inBufDesc.numBufs           = 1;
        inBufDesc.descs[0].buf      = Buffer_getUserPtr(hInBuf);
        inBufDesc.descs[0].bufSize  = Buffer_getNumBytesUsed(hInBuf);

        outBufDesc.numBufs          = 1;
        outBufDesc.descs[0].buf     = Buffer_getUserPtr(hOutBuf);
        outBufDesc.descs[0].bufSize = Buffer_getSize(hOutBuf);

        inArgs.size                 = sizeof(AUDDEC1_InArgs);
        inArgs.numBytes             = Buffer_getNumBytesUsed(hInBuf);
        inArgs.desiredChannelMode   = IAUDIO_1_0;   // the default value is IAUDIO_2_0, i modify it to IAUDIO_1_0, am i right?
        inArgs.lfeFlag              = XDAS_FALSE;

        outArgs.size                = sizeof(AUDDEC1_OutArgs);

        /* Decode the audio buffer */
        status = AUDDEC1_process(hAd1->hDecode, &inBufDesc, &outBufDesc, &inArgs,
                                 &outArgs);

        Dmai_dbg3("AUDDEC1_process() ret %d, consumed %d, created %d samples\n",
                  (Int) status, (Int) outArgs.bytesConsumed,
                  (Int) outArgs.numSamples);


        if (status != AUDDEC1_EOK) {
            if (XDM_ISFATALERROR(outArgs.extendedError)) {
                Dmai_err2("AUDDEC1_process() failed with error (%d ext: 0x%x)\n",
                          (Int)status, (Uns) outArgs.extendedError);
                return Dmai_EFAIL;
            }
            else {
                Dmai_dbg1("AUDDEC1_process() non-fatal error 0x%x\n",
                          (Uns) outArgs.extendedError);
                return Dmai_EBITERROR;
            }
        }

        Buffer_setNumBytesUsed(hInBuf, outArgs.bytesConsumed);
        channels = numChans[outArgs.channelMode];

        Buffer_setNumBytesUsed(hOutBuf, outArgs.numSamples * 1 * channels); // // the default value is *2, i modify it to *1, am i right?

        hAd1->sampleRate = outArgs.sampleRate;

        return Dmai_EOK;
    }

    The Adec1_process call returns no errors, but the decoded sound is very noisy.  Can you point out which parts is wrong?  Since you can decode successfully without ADTS headers using  ITTIAM_ENHAACPDEC_Params aacParams , can you please provide me a demo using this? 

    I really need your help, any advices will be appreciated. Thanks.

     

  • Hi Jing,

    Here is what I use:

        AUDDEC1_DynamicParams   defaultDynParams    = Adec1_DynamicParams_DEFAULT;
        ITTIAM_ENHAACPDEC_Params aacParams          = ENHAACPDECODER_ITTIAM_PARAMS;

        int  sampleRate = 48000;

                aacParams.s_iauddec_params.size = sizeof (aacParams);
                aacParams.i_sampfreq = sampleRate;
                aacParams.i_disable_sync = 1;
                aacParams.i_mp4_flag = 0;

                hAd1 = Adec1_create(hEngine, "aacdec", &aacParams.s_iauddec_params, &defaultDynParams);

    I didn't need to modify Adec1_create nor Adec1_process, though my recordings are stereo 48kHz.

  • Hi Pete,

    Thank you very much for your help. I will try this.  But for "aacParams.i_disable_sync = 1" , i really don't know what is used for, could you explain this for me?  Thanks.

    Also, i remember that your initial problem is to decode AAC file with ADTS headers,  can you decode successfully now?  Which parts need to be modified? 

  • From the AACDEC manual:

    i_disable_sync
    To indicate if ADIF/ADTS synchronization is to be
    disabled. In which case the header is expected to be
    at the beginning of the input buffer. Valid values are
    0 or 1. If any other value is sent an
    IAUDDEC1_EFAIL error is returned.

    So, this tells the decoder not to expect ADTS headers.  I then scan for an ADTS header and skip over it before sending data to be decoded, using this code:

                        if (p[0] == 0xff && (p[1]&0xf0) == 0xf0) {
                            header_len = (p[1] & 0x1) ? 7 : 9;
                            len = ((p[3]&0x3)<<11) + (p[4]<<3) + ((p[5]&0xe0)>>5) - header_len;
                        }

    The format of the AAC ADTS header: http://wiki.multimedia.cx/index.php?title=ADTS

  • Hi Pete,

    Follow what you said, I have been able to successfully decode the AAC audio. Thank you very much.

    But i have another issue here,  AAC as encoder, as long as the audio compression rate below 48kbps(16, 24, 32, 40) in source side, i can decoing in very good shape on far side. Other audio compression rate like 48, 56, 64, 72, 80, 88, 86kbps, it's not working.  And that's really confuse me. Did you have this issue before?  Is there any parameter for audio compression rate in ITTIAM_ENHAACPDEC_Params? 

  • Hi Pete,

    I have already fixed the audio compression rate issue, my audio data buffer size is not large enough for decode.  Anyway, thank you very much for your reply. You really help me a lot.