4

I'm already using the Media Foundation APIs (thanks to MFManagedEncode, http://blogs.msdn.com/b/mf/archive/2010/02/18/mfmanagedencode.aspx) to convert wav to aac. I haven't fully got my head around how this works, but it does work- thankfully.

Now I'm finding it difficult transcoding the other way, even though there is a MF codec for it (AAC Decoder). I can't find examples of how to use this and I'm finding the MSDN documentation for it cryptic to say the least; anyone had an luck with it?

A C# wrapper for would be ideal.

TIA.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
radsdau
  • 495
  • 5
  • 16
  • Found some extra info: http://msdn.microsoft.com/en-us/library/windows/desktop/dd757929(v=vs.85).aspx and also http://www.codeproject.com/Articles/459453/Code-to-stream-or-convert-MP3-WMA-to-PCM-WAV-in-Wi although that pertains specifically to Win8. I'm sure it's got some good stuff in it though. – radsdau Nov 21 '12 at 06:39
  • that decode in Win 8 link is a good one, I've ported it to C# and .NET 4 and hopefully will commit the results into NAudio soon. I haven't tried it with AAC yet, but it works great with MP3. I'm hoping to combine it with some ideas from MFManagedEncode as well. – Mark Heath Nov 23 '12 at 07:34
  • Link: [Link Convert AAC to WAV in c#](http://www.codeproject.com/Articles/501521/How-to-convert-between-most-audio-formats-in-NET) –  Apr 18 '13 at 20:32
  • There are many ways to decode AAC into WAV (actually PCM), and stock [AAC Decoder MFT/DMO](http://msdn.microsoft.com/en-us/library/windows/desktop/dd742784%28v=vs.85%29.aspx) is straightforward way, and also with minimal overhead compared to layered wrappers. MFT interface should be more or less useful (in C++ I would prefer DMO instead). You don't provide your code so it's hard to tell where you are stuck at. – Roman R. Aug 13 '13 at 21:45

2 Answers2

6

I have been succesfuly using NAudio for any audio processing and abstraction. It is available as a NuGet. It has wrapper encoders for Media Foundation (and others).

Here is a sample for encoding to AAC and back to WAV using NAudio:

using System;
using NAudio.Wave;

namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            // convert source audio to AAC
            // create media foundation reader to read the source (can be any supported format, mp3, wav, ...)
            using (MediaFoundationReader reader = new MediaFoundationReader(@"d:\source.mp3"))
            {
                MediaFoundationEncoder.EncodeToAac(reader, @"D:\test.mp4");
            }

            // convert "back" to WAV
            // create media foundation reader to read the AAC encoded file
            using (MediaFoundationReader reader = new MediaFoundationReader(@"D:\test.mp4"))
            // resample the file to PCM with same sample rate, channels and bits per sample
            using (ResamplerDmoStream resampledReader = new ResamplerDmoStream(reader, 
                new WaveFormat(reader.WaveFormat.SampleRate, reader.WaveFormat.BitsPerSample, reader.WaveFormat.Channels)))
            // create WAVe file
            using (WaveFileWriter waveWriter = new WaveFileWriter(@"d:\test.wav", resampledReader.WaveFormat))
            {
                // copy samples
                resampledReader.CopyTo(waveWriter);
            }
        }
    }
}
YourSelf
  • 294
  • 3
  • 6
  • Any way give the MediaFoundationReader / MediaFoundationEncoder a stream for in-memory process? – IlPADlI Oct 29 '16 at 14:54
  • Maybe this helps for streams: [link](https://www.codeproject.com/Articles/501521/How-to-convert-between-most-audio-formats-in-NET) – FaustsErbe Jul 24 '17 at 16:09
0

I wanted to decode AAC to PCM/WAV without depending upon MediaFoundation in order to make the code easily portable to other platforms. So I ported the JAAD from Java to netstandard 2.0. It has no native dependencies and I've also included a sample how to use it to convert from AAC to WAV. You can find it here. It's also available as a nuget.

Jimm98y
  • 81
  • 4