I have been trying to use the new media foundation facilities in NAudio version 1.7 pre release (downloaded 2013-08-05 @ 15:20 UTC) and have come across the following issue. I am writing a program called TelephoneTrack which needs to convert a recorded WAV file into either a M4A or WMA file. In my code when I call my routine ConvertWAVToM4A routine it works but when I call the ConvertWAVToWMA it fails.
I know this is pre-release but I thought you would like to know about this issue. NAudio is an excellent library by the way and I am very impressed with your efforts so far with the media foundation add-on.
```
public static void ConvertWAVToM4A(string outputFile, string inputFile)
{
FileInfo fileInfo = new FileInfo(outputFile);
if (fileInfo.Extension.ToUpper() != ".M4A")
{
fileInfo = new FileInfo(outputFile + ".m4a");
}
if (fileInfo.Exists)
{
fileInfo.Delete();
}
using (var reader = new MediaFoundationReader(inputFile))
{
MediaFoundationEncoder.EncodeToAac(reader, fileInfo.FullName, 192000);
}
}
public static void ConvertWAVToWMA(string outputFile, string inputFile)
{
FileInfo fileInfo = new FileInfo(outputFile);
if (fileInfo.Extension.ToUpper() != ".WMA")
{
fileInfo = new FileInfo(outputFile + ".wma");
}
if (fileInfo.Exists)
{
fileInfo.Delete();
}
using (var reader = new MediaFoundationReader(inputFile))
{
MediaFoundationEncoder.EncodeToWma(reader, fileInfo.FullName, 192000);
}
}
```
It throws an exception:
Exception has been thrown by the target of an invocation.
InnerException
Message:Object reference not set to an instance of an object.
Source:NAudio
StackTrace:
at NAudio.Wave.MediaFoundationEncoder.Dispose(Boolean disposing) in c:\SVN\NAudio\NAudio\Wave\WaveOutputs\MediaFoundationEncoder.cs:line 278
at NAudio.Wave.MediaFoundationEncoder.Dispose() in c:\SVN\NAudio\NAudio\Wave\WaveOutputs\MediaFoundationEncoder.cs:line 289
at NAudio.Wave.MediaFoundationEncoder.EncodeToWma(IWaveProvider inputProvider, String outputFile, Int32 desiredBitRate) in c:\SVN\NAudio\NAudio\Wave\WaveOutputs\MediaFoundationEncoder.cs:line 84
at TelephoneTrack.ApplicationCommon.ConvertWAVToWMA(String outputFile, String inputFile) in c:\SVN\TelephoneTrack\TelephoneTrack\ApplicationCommon.cs:line 755
at TelephoneTrack.View.MainView..ctor() in c:\SVN\TelephoneTrack\TelephoneTrack\View\MainView.xaml.cs:line 47
Comments: When I try using the NAudio WPF Demo app to encode the WAV file to WMA the encoder settings drop down is blank. The only option that works is AAC. As you mention this means I do not have the requisite encoders installed on my machine: Audio Codecs Type Name Format Binary Version ACM Microsoft IMA ADPCM CODEC 0011 imaadp32.acm 6.1.7600.16385 ACM Microsoft CCITT G.711 A-Law and u-Law CODEC 0007 msg711.acm 6.1.7600.16385 ACM Microsoft GSM 6.10 Audio CODEC 0031 msgsm32.acm 6.1.7600.16385 ACM Microsoft ADPCM CODEC 0002 msadp32.acm 6.1.7600.16385 ACM Fraunhofer IIS MPEG Layer-3 Codec (decode only) 0055 l3codeca.acm 1.9.0.401 ACM Microsoft PCM Converter 0001 DMO WMAudio Decoder DMO 0160, 0161, 0162, 0163 WMADMOD.DLL 6.1.7601.17514 DMO WMAPro over S/PDIF DMO 0162 WMADMOD.DLL 6.1.7601.17514 DMO WMSpeech Decoder DMO 000A, 000B WMSPDMOD.DLL 6.1.7601.17514 DMO MP3 Decoder DMO 0055 mp3dmod.dll 6.1.7600.16385
I know this is pre-release but I thought you would like to know about this issue. NAudio is an excellent library by the way and I am very impressed with your efforts so far with the media foundation add-on.
```
public static void ConvertWAVToM4A(string outputFile, string inputFile)
{
FileInfo fileInfo = new FileInfo(outputFile);
if (fileInfo.Extension.ToUpper() != ".M4A")
{
fileInfo = new FileInfo(outputFile + ".m4a");
}
if (fileInfo.Exists)
{
fileInfo.Delete();
}
using (var reader = new MediaFoundationReader(inputFile))
{
MediaFoundationEncoder.EncodeToAac(reader, fileInfo.FullName, 192000);
}
}
public static void ConvertWAVToWMA(string outputFile, string inputFile)
{
FileInfo fileInfo = new FileInfo(outputFile);
if (fileInfo.Extension.ToUpper() != ".WMA")
{
fileInfo = new FileInfo(outputFile + ".wma");
}
if (fileInfo.Exists)
{
fileInfo.Delete();
}
using (var reader = new MediaFoundationReader(inputFile))
{
MediaFoundationEncoder.EncodeToWma(reader, fileInfo.FullName, 192000);
}
}
```
It throws an exception:
Exception has been thrown by the target of an invocation.
InnerException
Message:Object reference not set to an instance of an object.
Source:NAudio
StackTrace:
at NAudio.Wave.MediaFoundationEncoder.Dispose(Boolean disposing) in c:\SVN\NAudio\NAudio\Wave\WaveOutputs\MediaFoundationEncoder.cs:line 278
at NAudio.Wave.MediaFoundationEncoder.Dispose() in c:\SVN\NAudio\NAudio\Wave\WaveOutputs\MediaFoundationEncoder.cs:line 289
at NAudio.Wave.MediaFoundationEncoder.EncodeToWma(IWaveProvider inputProvider, String outputFile, Int32 desiredBitRate) in c:\SVN\NAudio\NAudio\Wave\WaveOutputs\MediaFoundationEncoder.cs:line 84
at TelephoneTrack.ApplicationCommon.ConvertWAVToWMA(String outputFile, String inputFile) in c:\SVN\TelephoneTrack\TelephoneTrack\ApplicationCommon.cs:line 755
at TelephoneTrack.View.MainView..ctor() in c:\SVN\TelephoneTrack\TelephoneTrack\View\MainView.xaml.cs:line 47
Comments: When I try using the NAudio WPF Demo app to encode the WAV file to WMA the encoder settings drop down is blank. The only option that works is AAC. As you mention this means I do not have the requisite encoders installed on my machine: Audio Codecs Type Name Format Binary Version ACM Microsoft IMA ADPCM CODEC 0011 imaadp32.acm 6.1.7600.16385 ACM Microsoft CCITT G.711 A-Law and u-Law CODEC 0007 msg711.acm 6.1.7600.16385 ACM Microsoft GSM 6.10 Audio CODEC 0031 msgsm32.acm 6.1.7600.16385 ACM Microsoft ADPCM CODEC 0002 msadp32.acm 6.1.7600.16385 ACM Fraunhofer IIS MPEG Layer-3 Codec (decode only) 0055 l3codeca.acm 1.9.0.401 ACM Microsoft PCM Converter 0001 DMO WMAudio Decoder DMO 0160, 0161, 0162, 0163 WMADMOD.DLL 6.1.7601.17514 DMO WMAPro over S/PDIF DMO 0162 WMADMOD.DLL 6.1.7601.17514 DMO WMSpeech Decoder DMO 000A, 000B WMSPDMOD.DLL 6.1.7601.17514 DMO MP3 Decoder DMO 0055 mp3dmod.dll 6.1.7600.16385