NAudio - 如何仅将正弦波发送到插孔上的一个音频通道

发布于 2024-12-05 20:09:10 字数 1285 浏览 3 评论 0原文

我从以下位置获取了 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 项目位于:

http://naudio.codeplex.com/

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:

http://naudio.codeplex.com/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

装纯掩盖桑 2024-12-12 20:09:10

你的 for 循环应该有 += 2,而不是 += 1。

for (int n = 0; n < sampleCount; n += 2)

Your for loop should have += 2, not += 1.

for (int n = 0; n < sampleCount; n += 2)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文