One of the more common support requests with NAudio is how to convert MP3 files to WAV. Here’s a simple function that will do just that:

public static void Mp3ToWav(string mp3File, string outputFile)
{
    using (Mp3FileReader reader = new Mp3FileReader(mp3File))
    {
        using (WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader))
        {
            WaveFileWriter.CreateWaveFile(outputFile, pcmStream);
        }
    }
}

… and that’s all there is to it.

Notes:

  1. There is no need to wrap pcmStream with a BlockAlignReductionStream since we are not repositioning the MP3 file, just reading it from start to finish.
  2. It uses the ACM MP3 decoder that comes with Windows to decompress the MP3 data.
  3. To be able to pass the MP3 data to the ACM converter we need to do some parsing of the MP3 file itself (specifically the MP3 frames and ID3 tags). Unfortunately, there are some MP3 files that NAudio cannot parse (notably the sample ones that come with Windows 7). My attempts at tracking down the cause of this problem have so far failed. (the basic issue is that after reading the ID3v2 tag, we don’t end up in the right place in the MP3 file to read a valid MP3Frame – see MP3FileReader.cs). Please let me know if you think you have a solution to this.


First, make sure that you are on the server computer. You can check by searching for "SQL server management studio" in windows. If it show's up then you're on the server.

How to find internal IP address (local network connection).

1. Hold the windows key on your keyboard and then press the "R" key to open up the "Run" box.

2. Type "cmd" into the text box and then click "OK".

3. In the black box that comes up type "ipconfig".

4. Look for the title "Ethernet adapter" and look for "IPV4 address", this is your local IP address. (The title may be "Wireless adapter" if you are on a wireless internet connection).

How to find external IP address (Internet connection).

1. Open up your internet browser of choice (Example: Internet explorer, Mozilla Firefox, Google Chrome) and go to www.canyouseeme.org.

2. This will display your external IP address. It will also allow you to check whether your port is open. Your SQL port must be open to be able to connect over the internet (Usually port 1444).

How to check which port SQL is using and whether it is open.

1. Go into windows file explorer and right-click "This PC" then click "Manage".

2. Navigate to "Protocols for MSSQLSERVER" by expanding "Services and Applications", "SQL server Configuration Manager", "SQL Server Network Configuration" and select "Protocols for MSSQLSERVER".

3. Right-click "TCP/IP" and select "Properties".

4. Go to the "IP Addresses" tab and scroll to the bottom until you see "TCP port". This is what port SQL is using.

5. In your internet browser go to www.canyouseeme.org. Put the port that you saw in the last step into the port field and click "Check Port".

If your port is closed it will look like this:                                                                         If your port is open it will look like this:

If your port is closed you will need to contact AmberPOS support to open it up for you.

Where to put the IP address into AmberPOS

When launching AmberPOS after a database connection failure it will launch into this screen:

Just populate the "Server IP, Port" field with the server IP address and the port separated by a comma.

Note: Only use the external IP address when connecting to a remote server that is at another location.


One question that commonly gets asked with NAudio is, “Why do I get a NoDriver calling acmFormatSuggest error when playing MP3s?” The answer is that you don’t have the ACM MP3 decoder installed. If you’re running a regular desktop version of windows from XP all the way up to 8.1, then the Fraunhofer MP3 ACM decoder is installed as standard and everything should just work.

But if you’re running a server version of Windows (or maybe one of the “N” versions of Windows sold in Europe), then you might be missing the codecs you need. There are various workarounds to this:

Option 1: Install Desktop Experience

If you are running Windows Server, make sure you install the “Desktop Experience” component of Windows. This will install all the standard codecs, for audio playback (including Media Foundation support as well). To install on Azure, this script may be helpful.

Option 2: Use the DMO MP3 Frame Decompressor

The NAudio Mp3FileReader class allows you to inject an alternative MP3 frame decompressor, so you don’t need to use ACM if you don’t want to. To use the DMO MP3 frame decompressor for example, use the following code:

new Mp3FileReader(stream,wave=> new DmoMp3FrameDecompressor(wave));

Option 3: Use MediaFoundationReader Instead

With NAudio 1.7, the MediaFoundationReader class was introduced, which can not only play MP3 files, but lots of other formats too. In many ways, this should now be the preferred way of playing MP3s with NAudio. You will still need the Desktop Experience installed if you’re on Windows Server though.

Option 4: Use a fully managed MP3 Decoder

Another option is to switch to fully managed MP3 decoder such as NLayer. This has the benefit of working on all platforms and requiring no codecs.

Option 5: Find and install another ACM MP3 Codec

Finally, you may be here not because you’re playing MP3, but because you tried to play a WAV file containing some codec that your system cannot find an ACM driver for. This also results in the “NoDriver calling acmFormatSuggest error”. What you need to do is search the web for an ACM codec that can decode the format you are using. Unfortunately this is not always a simple process, but unless you have a codec installed that matches the compression type of the file you’re trying to play, you won’t be able to play it.


+ Recent posts