与n音讯

我一直在使用n音讯过去数天混合两种波形文件用这种格式混合的WaveStream第二:8000与n音讯

我发现从https://naudio.codeplex.com/discussions/251475,首先我应该将它们转换成32位ieeefloatingpoint编码,然后将转换后的流添加到WaveMixerStream32。之后,我应该使用Wave32To16Stream将混合数据转换为16位/采样流,将获得的流转换为单声道并最终将单声道16位/采样转换为单声道8位/采样。

我按照我解释写这些代码行:

WaveFileReader r1 = new WaveFileReader(...); 

WaveFileReader r2 = new WaveFileReader(...);

WaveFormat OutputWaveFormat = WaveFormat.CreateCustomFormat(WaveFormatEncoding.Pcm, 8000, 1, 16000, 2, 16);

WaveFormat InputWaveFormat = WaveFormat.CreateALawFormat(8000, 1);

WaveFormatConversionStream ConversionStream1 = new WaveFormatConversionStream(OutputWaveFormat, r1);

WaveFormatConversionStream ConversionStream2 = new WaveFormatConversionStream(OutputWaveFormat, r2);

WaveChannel32 WaveChannel32_1 = new WaveChannel32(ConversionStream1);

WaveChannel32 WaveChannel32_2 = new WaveChannel32(ConversionStream2);

WaveMixerStream32 mixer32 = new WaveMixerStream32();

mixer32.AddInputStream(WaveChannel32_1);

mixer32.AddInputStream(WaveChannel32_2);//(*)

Wave32To16Stream stereo16 = new Wave32To16Stream(mixer32);

StereoToMonoProvider16 mono16 = new StereoToMonoProvider16(m_Wave32To16Stream);

线(*)后我有一个流,例如:0 0 32 60 0 0 32 60 0 0 59 126 0 0 59 126 ... 但应用Wave32To16Stream后,我有一个在立体声16只有一个序列,因此在mono16! 这一步应该怎么做?

回答:

答案是非常简单的比我想象的。我只需要将ALaw转换为PCM,然后添加两个波形流,我使用G711 codeproject文章中的ALawDecoder完成。

r1 = new WaveFileReader(...); 

r2 = new WaveFileReader(...);

r1.Read(arr1, 0, arr1.Length);

r2.Read(arr2, 0, arr2.Length);

short[] firstPCM16 = ALawDecoder.ALawDecode(arr1);

short[] secondPCM16 = ALawDecoder.ALawDecode(arr2);

byte[] result1 = new byte[firstPCM16.Length * sizeof(short)];

byte[] result1 = new byte[secondPCM16.Length * sizeof(short)];

Buffer.BlockCopy(firstPCM16, 0, result1, 0, result1.Length);

Buffer.BlockCopy(secondPCM16, 0, result2, 0, result2.Length);

for (...)

{

mixed[i] = (byte)(result1[i] + result2[i]);//No need to dividing by 2 because r1 and r2 are 8 bit ALaw and return value of ALawDecoder is 16 bit pcm

}

以上是 与n音讯 的全部内容, 来源链接: utcz.com/qa/259869.html

回到顶部