Skip to content

Commit

Permalink
improved support for mono AAC, fixes #223
Browse files Browse the repository at this point in the history
  • Loading branch information
markheath committed Sep 4, 2017
1 parent edaa825 commit 8226aa3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions NAudio/Wave/WaveStreams/MediaFoundationReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ protected virtual IMFSourceReader CreateReader(MediaFoundationReaderSettings set
partialMediaType.SubType = settings.RequestFloatOutput ? AudioSubtypes.MFAudioFormat_Float : AudioSubtypes.MFAudioFormat_PCM;

var currentMediaType = GetCurrentMediaType(reader);

// HE-AAC (and v2) seems to halve the samplerate
if (currentMediaType.SubType == AudioSubtypes.MFAudioFormat_AAC && currentMediaType.ChannelCount == 1)
{
currentMediaType.SampleRate *= 2;
currentMediaType.ChannelCount *= 2;
}
// mono, low sample rate files can go wrong on Windows 10 unless we specify here
partialMediaType.ChannelCount = currentMediaType.ChannelCount;
partialMediaType.SampleRate = currentMediaType.SampleRate;
Expand Down

1 comment on commit 8226aa3

@Ahmed-Abdelhameed
Copy link
Contributor

@Ahmed-Abdelhameed Ahmed-Abdelhameed commented on 8226aa3 Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markheath Thank you for the quick response.
This doesn't take into account the aac_lc mono though. I created a PR #233 with the solution suggested by @tfwio. It's a quick/dirty fix, so I'll try to help finding a better solution, but this does work.

Also, would be great if you can update the NuGet package.
Many thanks to you really :)

Please sign in to comment.