Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

AAC SBR Problem

ksubox
Beginner
525 Views
Hi,
I tried to test AAC SBR encoding in IPP, but finally got failed.
Here is what I did:
1. I have raw input audio file with 44100kHz/stereo samples.
2. I encode & decode this file and put decoded audiosamples in other file
3. If I don't specify SBR everything is OK. If I specify I get strange artifacts. I checked with VLC encoded ADTS stream - also bad results.
4. What's wrong with this source code and how to make it works ???:

#include "stdafx.h"

#include "umc_aac_encoder_params.h"
#include "umc_audio_codec.h"

#include "umc_aac_encoder.h"
#include "umc_aac_decoder.h"
#include "umc_aac_decoder_params.h"

using namespace UMC;

class MyMediaData : public UMC::MediaData {
DYNAMIC_CAST_DECL_BASE(MyMediaData)
public:
MyMediaData(size_t length = 0):MediaData(length) {}

void Pack() {
if (m_pBufferPointer != NULL && m_nBufferSize > 0 && m_pDataPointer > m_pBufferPointer) {
if (m_nDataSize > 0) {
ippsCopy_8u(m_pDataPointer, m_pBufferPointer, m_nDataSize);
}
m_pDataPointer = m_pBufferPointer;
}
}

UMC::Status AddData(Ipp8u *ptr, size_t size) {
if (!m_pBufferPointer)
return UMC::UMC_ERR_NULL_PTR;

if (size > (m_nBufferSize - (m_pDataPointer - m_pBufferPointer) - m_nDataSize))
return UMC::UMC_ERR_FAILED;

ippsCopy_8u(ptr, m_pDataPointer, size);
m_nDataSize += size;
return UMC::UMC_OK;
}
};

short int readbuf[16384], compbuf[4096], writebuf[16384];

int
main(int argc, char* argv[]) {
if (argc < 3)
return 0;

Status istat;
{
UMC::AACEncoder *encoder = new UMC::AACEncoder();
UMC::AACEncoderParams iparams;
iparams.m_info_in.sample_frequency = 44100;
iparams.m_info_in.channels = 2;
iparams.m_info_out.bitrate = 24000;
iparams.audioObjectType = AOT_AAC_LC;
//iparams.auxAudioObjectType = AOT_UNDEF; // works fine
iparams.auxAudioObjectType = AOT_SBR; // DOESN'T WORK :(
iparams.stereo_mode = UMC_AAC_JOINT_STEREO;
iparams.ns_mode = 1;
iparams.outputFormat = UMC_AAC_ADTS;
iparams.m_info_out.sample_frequency = 44100; // not important
istat = encoder->Init(&iparams);

UMC::AACDecoder *decoder = new UMC::AACDecoder();
//UMC::AudioCodecParams oparams;
UMC::AACDecoderParams oparams;
oparams.m_info_in.stream_type = UNDEF_AUDIO;
oparams.m_pData = NULL;
oparams.ModeDecodeHEAACprofile = HEAAC_LP_MODE; // try to specify - not important
oparams.ModeDwnsmplHEAACprofile = HEAAC_DWNSMPL_ON; //try to specify - not important
oparams.flag_SBR_support_lev = SBR_ENABLE; // try to specify - not important
Status istat = decoder->Init(&oparams);

MyMediaData *indata = new MyMediaData();
MyMediaData *compdata = new MyMediaData(4096);
MyMediaData *outdata = new MyMediaData();

UMC::BaseCodecParams audio_codec_params;
encoder->GetInfo(&audio_codec_params);
Ipp32s needSize = audio_codec_params.m_SuggestedInputSize;

FILE *fin = NULL, *fout = NULL, *fcomp = NULL;
fin = fopen(argv[1],"r+b");
fout = fopen(argv[2],"w+b");
fcomp = fopen("d:\\_comp.aac","w+b");
if (fin != NULL && fout != NULL) {
do {
int got = fread(readbuf,1,needSize,fin);
if (got != needSize)
break;
indata->SetBufferPointer((Ipp8u*)readbuf,sizeof(readbuf));
indata->SetDataSize(got);
compdata->SetBufferPointer((Ipp8u*)compbuf,sizeof(compbuf));
istat = encoder->GetFrame(indata,compdata);
if (istat == UMC_OK) {
fwrite(compdata->GetDataPointer(),1,compdata->GetDataSize(),fcomp);
outdata->SetBufferPointer((Ipp8u*)writebuf,sizeof(writebuf));
istat = decoder->GetFrame(compdata,outdata);
if (istat == UMC_OK) {
UMC::BaseCodecParams audio_codec_params1;
decoder->GetInfo(&audio_codec_params1);
int written = fwrite(outdata->GetDataPointer(),1,outdata->GetDataSize(),fout);
if (written <= 0 || written != outdata->GetDataSize())
break;
}
}
} while (true);
}
if (fin)
fclose(fin);
if (fout)
fclose(fout);
if (fcomp)
fclose(fcomp);

delete indata;
delete compdata;
delete outdata;

delete encoder;
delete decoder;
}
return 0;
}

0 Kudos
3 Replies
Chao_Y_Intel
Moderator
525 Views

You can try audio_codec_con application in the UMC sample code? If the result are the same as yours, it is possiblly because UMC AAC SBR encoder not as good as AAC LC and MP3 encoders. If the result are different, could you also provided the bistream? so we can have further check on the problem.

Regards,
Chao

0 Kudos
ksubox
Beginner
525 Views
Actually I found strange behavior: SBR decoder doesn't upsample. I encode 44100 with SBR ADTS stream and get 22050 samplerate after encoding. I guess SBR decoder should upsample back to 44100. Do I need special initialization for this ?
0 Kudos
Chao_Y_Intel
Moderator
525 Views

Hello,

See the comments from our AAC expert:

You can check explaination in the document:

Flags

The following members of UMC::AACDecoderParams affect on AAC decoder behavior:
ModeDecodeHEAACprofile (HEAAC_HQ_MODE | HEAAC_LP_MODE) SBR part of AAC decoders work either high quality or low process mode
ModeDwnmxHEAACprofile (HEAAC_DWNSMPL_ON | HEAAC_DWNSMPL_OFF) downsampling mode enable (disable)
flag_SBR_support_lev (SBR_ENABLE | SBR_DISABLE) SBR support enable (disable) (if SBR support desable AAC decoder will ingnore all SBR extensions)
Default parameters HEAAC_HQ_MODE, HEAAC_DWNSMPL_ON, SBR_ENABLE.

HEAAC_DWNSMPL_ON | HEAAC_DWNSMPL_OFF flags affects upsampling.

Thanks,
Chao
0 Kudos
Reply