Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Sample rate problem of SBR decoding (Read 5604 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Sample rate problem of SBR decoding

This article talks about faad library and faad element of GStreamer.
Correct me if i'm wrong about anything, or add your valuable opinions

When decoding a SBR presented file, a.k.a HE-AAC file, sample rate got from the ADTS header is only half of the resulted pcm data. If you use ITunes to open a HE-AAC file, you will sample rate of 22055, not 44100.
What happened, let’s look the code of Faad, and the code of gstfaad which uses faad library.

First thing to know: whether SBR is presented is not known when parsing header. It is only known after decoding several frames when using faad.

Look at decoder.c function aac_frame_decode, line 1011
Code: [Select]
if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
{
    uint8_t ele;
    /* this data is different when SBR is used or when the data is upsampled */
    if (!hDecoder->downSampledSBR)
    {
         frame_len *= 2;
         hInfo->samples *= 2;
         hInfo->samplerate *= 2;
     }

We can see after decoding, if sbr_present_flag is set, the samples, samplerate are doubled.
Sbr_present_flag is got when decoding, so it’s implicit, but forceUpSampling can be affected by user code.

See decoder.c, function NeAACDecInit, line 284
Code: [Select]
if (*samplerate <= 24000 && !(hDecoder->config.dontUpSampleImplicitSBR))
{
    *samplerate *= 2;
    hDecoder->forceUpSampling = 1;
} else if (*samplerate > 24000 && !(hDecoder->config.dontUpSampleImplicitSBR)) {
    hDecoder->downSampledSBR = 1;
}


See Gstfaad.c, function gst_faad_open_decoder, line 1476
Code: [Select]
conf = faacDecGetCurrentConfiguration (faad->handle);
conf->defObjectType = LC;
conf->dontUpSampleImplicitSBR = 1;
conf->outputFormat = FAAD_FMT_16BIT;

if (faacDecSetConfiguration (faad->handle, conf) == 0) {
    GST_WARNING_OBJECT (faad, "faacDecSetConfiguration() failed");
    return FALSE;
}

We can see, this code will let hDecoder->forceUpSamping become 0 inside faad library, and up sampling will depend on whether sbr_present_flag is set or not, which depends on decode result.

Finally, whether the sample rate will be doubled totally depends on the AAC file being decoding. This is really good, because user don’t have any idea about the format of the AAC file.

Sample rate problem of SBR decoding

Reply #1
HI All,
I am working on AAC decoding interface.
The input AAC file contains - Multilingual data - Japanese and English..

The decoded output contains:
Num Of Chnls: 1
Sampling Rate: 48000
SBR Flag : ON (Enabled)
SBR Up Flag: 2

I want to extract Only one language data from the decoded PCM. Please let me know, how can i do that.

Thanks and Regards,
Medha