Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Artem_O_
Beginner
60 Views

Distorted sound in AAC encoder output

Hello,

I try to encode PCM mu-law audio (8000Hz, 16 bits per sample, 1 channel) from IP-camera with UMC AACEncoder (ipp-samples.8.0.0.005). The output audio is very distorted (see in attachment). I guess I use wrong parameters while encoder initialising. Please check my code and tell me where I am wrong?

#include "AACEncoder.h"

#include <ipps.h>
#include <umc_linear_buffer.h>

using namespace NVeedo;

CAACEncoder::CAACEncoder(void)
    :   m_pMediaBuffer(0)
{
}


CAACEncoder::~CAACEncoder(void)
{
    m_Encoder.Close();

    UMC_DELETE(m_pMediaBuffer);
}


bool CAACEncoder::Init()
{
    m_pMediaBuffer = (UMC::MediaBuffer*) new UMC::LinearBuffer();

    // Input data parameters
    m_AACEncParams.m_info.streamType                    = UMC::MULAW_AUDIO;
//    m_AACEncParams.m_info.audioInfo.m_iChannelMask      = 0;
    m_AACEncParams.m_info.audioInfo.m_iChannels         = 1;
    m_AACEncParams.m_info.audioInfo.m_iBitPerSample     = 16;
    m_AACEncParams.m_info.audioInfo.m_iSampleFrequency  = 8000;

    m_AACEncParams.m_info.iBitrate                      = 32000; //48000;

    // Output stream parameters
    m_AACEncParams.audioObjectType                      = AOT_AAC_LC;
    m_AACEncParams.auxAudioObjectType                   = AOT_UNDEF;
    m_AACEncParams.outputFormat                         = UMC_AAC_ADTS;
    m_AACEncParams.stereo_mode                          = UMC_AAC_MONO;
    m_AACEncParams.ns_mode                              = 0;

    m_AACEncParams.m_pData                              = 0;

    if(UMC::UMC_OK != m_Encoder.Init(&m_AACEncParams))
    {
        std::cerr << "Audio codec init failed" << std::endl;
        return false;
    }

    UMC::Status             nStatus = UMC::UMC_OK;
    UMC::AACEncoderParams   CodecParams;

    nStatus = m_Encoder.GetInfo(&CodecParams);
    if(nStatus < 0)
    {
        std::cerr << "Audio codec GetInfo() failed" << std::endl;
        return false;
    }

    m_OutData.Alloc(CodecParams.m_iSuggestedOutputSize);

    m_MediaBufferParams.m_numberOfFrames        = 10;
    m_MediaBufferParams.m_prefInputBufferSize   = CodecParams.m_iSuggestedInputSize  * m_MediaBufferParams.m_numberOfFrames;
    m_MediaBufferParams.m_prefOutputBufferSize  = CodecParams.m_iSuggestedOutputSize * m_MediaBufferParams.m_numberOfFrames;

    if (UMC::UMC_OK != m_pMediaBuffer->Init(&m_MediaBufferParams))
    {
        std::cerr << "Media buffer init failed" << std::endl;
        return false;
    }

    std::cout << "AAC codec initialized successfully" << std::endl;

    m_AACEncParams.m_info.streamType                    = UMC::AAC_AUDIO;

    return true;
}

bool CAACEncoder::Encode(void* pBuffer, int nLength)
{
    UMC::Status nStatus = m_pMediaBuffer->LockInputBuffer(&m_InMediaBuffer);
    if(UMC::UMC_OK != nStatus)
        return false;

    int nMediaBufferSize = m_InMediaBuffer.GetBufferSize();
    if (nMediaBufferSize < nLength)
    {
        int nBreak = 1;
    }

    // Copy audio data
    ippsCopy_8u((Ipp8u*) pBuffer, (Ipp8u*) m_InMediaBuffer.GetBufferPointer(), nLength);
    m_InMediaBuffer.SetDataSize(nLength);

    m_pMediaBuffer->UnLockInputBuffer(&m_InMediaBuffer);

    nStatus = m_pMediaBuffer->LockOutputBuffer(&m_OutMediaBuffer);
    if(UMC::UMC_OK != nStatus)
        return false;

    nStatus = m_Encoder.GetFrame(&m_OutMediaBuffer, &m_OutData);
    m_pMediaBuffer->UnLockOutputBuffer(&m_OutMediaBuffer);

    if(UMC::UMC_OK != nStatus)
    {
        return false;
    }

    return true;
}

UMC::MediaData* CAACEncoder::GetFrame()
{
    return &m_OutData;
}

 

0 Kudos
1 Reply
Chao_Y_Intel
Employee
60 Views

Hello,

Thanks for submitting this questions.  As you may you know, the sample code in the IPP is  the legacy one, and users are suggested to move to the Intel® Media SDK  product for some Codec related code.
Do you have a check to the Intel® Media SDK for the AAC encoder?

Thanks,
Chao

Reply