Mono Mp3s

Nov 3, 2009 at 5:01 PM

I was trying out this library, and I ran into a problem with mono mp3s.  An exception is thrown when playing them: NAudio.MmException: AcmNotPossible calling acmStreamConvert.

The code I was using is:

WaveChannel32 waveChannel32 = new WaveChannel32(new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(new Mp3FileReader(fileName))));
IWavePlayer player = new WaveOut();

The stack trace:
 NAudio.MmException: AcmNotPossible calling acmStreamConvert
   at NAudio.MmException.Try(MmResult result, String function)
   at NAudio.Wave.Compression.AcmStreamHeader.Convert(Int32 bytesToConvert, Int32& sourceBytesConverted)
   at NAudio.Wave.Compression.AcmStream.Convert(Int32 bytesToConvert, Int32& sourceBytesConverted)
   at NAudio.Wave.WaveFormatConversionStream.Read(Byte[] array, Int32 offset, Int32 count)
   at NAudio.Wave.BlockAlignReductionStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at NAudio.Wave.WaveChannel32.Read(Byte[] destBuffer, Int32 offset, Int32 numBytes)
   at NAudio.Wave.WaveOutBuffer.OnDone()
   at NAudio.Wave.WaveOut.Play()

I noticed Mp3FileReader hardcodes the number of channels to 2, even though Mp3Frame correctly identifies the mp3 as mono.  Changing Mp3FileReader line 65 as follows allows mono mp3s to play without a problem.

waveFormat = new Mp3WaveFormat(sampleRate, mp3Frame.ChannelMode == ChannelMode.Mono ? 1 : 2, frameLengthInBytes, bitRate);

- Scott Fleischman

Nov 3, 2009 at 8:31 PM

thanks for reporting this. I have a bit of a backlog of NAudio stuff to deal with, but I will try to get round to adding your fix asap


Mar 11, 2010 at 3:25 PM

checked in (finally!)

thanks again