最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Changing WaveFormat of MP3 Audio with NAudio - Stack Overflow

programmeradmin9浏览0评论

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}

发布评论

评论列表(0)

  1. 暂无评论