Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: Playback plays at 50% speed with AAC files

$
0
0
I found out why that halfspeed.aac file was playing at half speed in NAudio, it is because the AAC file uses SBR (spectral band replication) for low quality AAC files which halves the sample rate of a 44100 to the 22050 samples as reported in the ADTS header, the encoder decodes the 22050 samples, processes the SBR and outputs at 44100hz.

Since we are reading 22050 at the start, we are setting the wave out device to 22050 which is wrong, we need to set it to 44100 if SBR is detected, the AacFrame.cs class will contain an SBR flag and the AacWaveFormat samplerate will be adjusted. I figured out how to detect SBR (and Panoramic Stereo) by calculating various values in the ADTS header and doubling the WaveFormat sample rate to 44100. I have confirmed it works using the ACM decoder, but we need to make adjustments to the MediaFoundation side. Initially parsing all AAC files through the AacADTSParser.cs class instead of MF should do the trick. The AacFileReader class defaults to ACM as like Mp3FileReader but parsing an MF decompressor should work fine in theory. I'll do some testing to be sure.

The ADIF AAC format is half done (The ADIF header is a complicated beast btw), the SBR information is in the ADIF header.

LATM and LAOS streaming formats seem a little trickier, I haven't gotten to those yet.

Viewing all articles
Browse latest Browse all 5831

Trending Articles