我有一系列44 kHz 16位双通道无压缩波形文件(从资源中读取),并希望应用淡出和淡入效果来创建所有WAV序列中的流文件。
资源读取,并使16位波流正确发生。目标格式也显示正确,但我在下面的waveformat coversion步骤中将acmnotpossible
作为例外。我做错了什么?
String ResToPlay2 = NameSpaceString + ".Resources." + inWave2 + ".wav";
Stream _audioStream2;
int wavdur2 = 0;
Double fadeDurDbl2 = 0;
int fadeDur2 = 0;
if (!resA.GetManifestResourceStream (ResToPlay2).Equals (Stream.Null))
{
_audioStream2 = resA.GetManifestResourceStream (ResToPlay2);
WaveStream wavePCMStream2 = WaveFormatConversionStream.CreatePcmStream (new WaveFileReader (_audioStream2));
WaveFormat targetFmt2 = new WaveFormat (44100, 32, 2);
WaveStream waveStream2 = new WaveFormatConversionStream(targetFmt2,wavePCMStream2);
using (waveStream2)
{
wavdur2 = (int) waveStream2.TotalTime.Milliseconds;
var fader2 = new FadeInOutSampleProvider(new WaveToSampleProvider(waveStream2));
fadeDurDbl2 = (wavdur2*OverlapPCT) / 100;
fadeDur2 = (int) Math.Round(fadeDurDbl2, 0);
fader2.BeginFadeIn (fadeDur2);
var stwp2 = new NAudio.Wave.SampleProviders.SampleToWaveProvider (fader2);
WaveFileWriter.CreateWaveFile (Application.StartupPath + "\\" + "fadedIn_?.wav", stwp2);
}
}
答案 0 :(得分:0)
我不确定为什么要使用WaveFormatConversionStream
,因为你是从PCM开始的。首先访问示例提供程序,然后您可以使用FadeInOutSampleProvider
var reader = new WaveFileReader (_audioStream2)
var sampleProvider = SampleProviderConverters.ConvertWaveProviderIntoSampleProvider(reader);
var fader = new FadeInOutSampleProvider (sampleProvider);