I am using NAudio in a C# .NET 8 project to concatenate multiple mp3 files using MixingSampleProvider and OffsetSampleProvider. Unfortunately these mp3 files don't have the same WaveFormat, so I am trying to convert all subsequent mp3s to the WaveFormat of the first one, as I need them to have the same WaveFormat to be used together in the MixingSampleProvider like this:
private static OffsetSampleProvider? GetSample(string fullFilename, WaveFormat? targetWaveFormat)
{
try
{
Mp3FileReader reader = new Mp3FileReader(fullFilename);
OffsetSampleProvider? sampleProvider = null;
if (targetWaveFormat != null)
{
WaveFormatConversionStream waveFormatConversionStream = new WaveFormatConversionStream(targetWaveFormat, reader);
sampleProvider = new OffsetSampleProvider(waveFormatConversionStream.ToSampleProvider());
}
else
sampleProvider = new OffsetSampleProvider(reader.ToSampleProvider());
return sampleProvider;
}
catch (Exception ex) ...
}
This code unfortunately raises a "AcmNotPossible calling acmStreamOpen" exception. I can open the file without caring about the WaveFormat, but then obviously the addition to the MixingSampleProvider failes, if it was created for an mp3 with a different WaveFormat.
Any idea, what might be the problem?
Edit: The formats present seem to be
{32 bit IEEFloat: 32000Hz 1 channels}
{32 bit IEEFloat: 48000Hz 1 channels}