NAudio icon indicating copy to clipboard operation
NAudio copied to clipboard

DllNotFoundException: Msacm32.dll when I use NAudio in Unity of Mac OS

Open r2123b opened this issue 6 years ago • 10 comments

Hi,

when I want to use NAudio to convert mp3 into wav, the error message jumped out on my Unity log window. The message is in the following lines.

DllNotFoundException: Msacm32.dll
NAudio.Wave.Compression.AcmStream.SuggestPcmFormat (NAudio.Wave.WaveFormat compressedFormat)
NAudio.Wave.AcmMp3FrameDecompressor..ctor (NAudio.Wave.WaveFormat sourceFormat)
NAudio.Wave.Mp3FileReader.CreateAcmFrameDecompressor (NAudio.Wave.WaveFormat mp3Format)
NAudio.Wave.Mp3FileReader..ctor (System.IO.Stream inputStream, NAudio.Wave.FrameDecompressorBuilder

r2123b avatar Feb 19 '19 03:02 r2123b

I found someone had the same problem as mine.

https://answers.unity.com/questions/1224167/dllnotfoundexception-msacm32dll.html

r2123b avatar Feb 19 '19 03:02 r2123b

hi, NAudio contains many wrappers for Windows APIs, and the ACM APIs which are found in msacm32.dll are part of that. It means you can't use them from non-Windows operating systems.

By default the Mp3FileReader tries to use ACM, but you can plug in a fully managed MP3 decoder if you prefer. See my article here

markheath avatar Feb 19 '19 08:02 markheath

I can confirm that the linked work-around works (although the article is from 2017, which does not inspire me with confidence). As of writing, the sample code works with NLayer.NAudioSpport 1.13.0, and looks similar to the article code:

var fileName = @"C:\Users\markh\Desktop\input.mp3";
var builder = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf));
using (var reader = new Mp3FileReader(fileName, builder))
{
    WaveFileWriter.CreateWaveFile(@"C:\Users\markh\Desktop\output.wav",reader);
}

nightblade9 avatar Aug 20 '20 10:08 nightblade9

From the comments above and no mention on the prerequisites page the library is not supported on Mac OSX?

velara3 avatar May 14 '21 07:05 velara3

Any news to be supported on Mac OSX?

homerokzam avatar May 24 '23 00:05 homerokzam

Afraid I have no plans to support Mac OSX. I do not own a Mac computer. Someone else could always make an NAudio extension that implements interfaces like IWavePlayer and make the Mac equivalents of things like MediaFoundationReader.

markheath avatar Jun 23 '23 19:06 markheath

I am also interested in using NAudio in a Mac computer. Can you detail exactly which interfaces should be implemented to get a full mp3/wav decoding and audio playback specific to a target OS? I need to know up to which point NAudio is generic and where we need to create concrete stuff for the target OS.

I imagine we need a replacement of WaveOutEvent (IWavePlayer) and Mp3FileReader (I tried with NLayer Mp3FrameDecompressor solution you proposed in 2019, but it doesn't work anymore with the Mp3FileReader current constructors).

Thank you very much for the great job you did for Audio support in .NET core :) your library is simply amazing

mtmarco87 avatar Jun 25 '23 08:06 mtmarco87

You can read WAV files no problem cross platform as they almost always contain raw PCM. NLayer can still be used for MP3 file reading - just use Mp3FileReaderBase instead as in this example For more comprehensive Mac support I'd implement the equivalent of MediaFoundationReader that uses whatever Mac APIs support reading files of various types

markheath avatar Jul 08 '23 20:07 markheath

I did all the above, also changed to Mp3FileReaderBase but the error still persists. Any idea why? I'm using it in a .NET Core project. The error was "Unable to load shared library 'Msacm32.dll' or one of its dependencies".

caduong97 avatar Jul 15 '23 08:07 caduong97

Are you using WaveFormatConversionStream as well? If so, you don't need to use that

markheath avatar Jul 28 '23 20:07 markheath