NAudio - 如何仅将正弦波发送到插孔上的一个音频通道
我从以下位置获取了 Visual Studio 2010 的现有单声道(非立体声)NAudio 示例:
http://mark-dot-net.blogspot.com/2009/10/playback-of-sine-wave-in-naudio.html
并将其更改为具有两声道立体声音频如下所示:
public abstract class WaveProvider32 : IWaveProvider
{
public WaveProvider32() : this(44100, 2) // Was 44100, 1
{
}
.
.
.
}
当我尝试将正确的样本值放入缓冲区中的第一个浮点中时 缓冲区中的第二个浮点数为零,我希望在 右声道,左声道无音频。
我看到频率相同但幅度低 10 倍的异相正弦波 左声道与右声道。
这是由于某种信号渗透还是我不理解代码应该如何工作?
以下是我如何更改 WaveProvider32 的示例:
public class SineWaveProvider32 : WaveProvider32
{
.
.
.
public override int Read(float[] buffer, int offset, int sampleCount)
{
int sampleRate = WaveFormat.SampleRate;
for (int n = 0; n < sampleCount; n += 1)
{
buffer[n+offset] = (float)(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate));
buffer[n+offset+1] = (float)(0);
sample++;
if (sample >= sampleRate)
{
sample = 0;
}
}
return sampleCount;
}
}
对我做错了什么有什么建议吗?
注意
:NAudio 项目位于:
I took an existing mono (non-stereo) NAudio example for Visual Studio 2010 from:
http://mark-dot-net.blogspot.com/2009/10/playback-of-sine-wave-in-naudio.html
and changed it to have two channel stereo audio as shown below:
public abstract class WaveProvider32 : IWaveProvider
{
public WaveProvider32() : this(44100, 2) // Was 44100, 1
{
}
.
.
.
}
When I try to place the correct sample value in the first float in buffer and
a zero in the second float in buffer, I was expecting to get a sine wave on the
right channel and no audio on the left.
I'm seeing the same frequency 10x lower amplitude out of phase sine wave
on the left channel vs. the right channel.
Is that from some kind of signal bleed through or am I not understanding how the code should work?
Here is a sample of how I changed WaveProvider32:
public class SineWaveProvider32 : WaveProvider32
{
.
.
.
public override int Read(float[] buffer, int offset, int sampleCount)
{
int sampleRate = WaveFormat.SampleRate;
for (int n = 0; n < sampleCount; n += 1)
{
buffer[n+offset] = (float)(Amplitude * Math.Sin((2 * Math.PI * sample * Frequency) / sampleRate));
buffer[n+offset+1] = (float)(0);
sample++;
if (sample >= sampleRate)
{
sample = 0;
}
}
return sampleCount;
}
}
Any advice on what I'm doing wrong?
Regards
Note: The NAudio project is located at:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 for 循环应该有 += 2,而不是 += 1。
Your for loop should have += 2, not += 1.