简体   繁体   English

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

[英]NAudio - How to send sine wave only to one audio channel on jack

I took an existing mono (non-stereo) NAudio example for Visual Studio 2010 from: 我从Visual Studio 2010中获取了现有的单声道(非立体声)NAudio示例:

http://mark-dot-net.blogspot.com/2009/10/playback-of-sine-wave-in-naudio.html 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. 我在左声道和右声道上看到相同频率相差10倍的相位正弦波。

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: 以下是我如何更改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: 注意:NAudio项目位于:

http://naudio.codeplex.com/ http://naudio.codeplex.com/

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM