简体   繁体   English

无法使用Tone.js将音频拆分为单独的通道

[英]Can't Split Audio Into Separate Channels with Tone.js

I've started creating an application with a library called Tone.js that allows me to manipulate Audio on the web in all sorts of ways. 我已经开始使用名为Tone.js的库创建应用程序,该库使我能够以各种方式来操纵Web上的音频。

Currently I'd like to create two channels (left and right) for headphone users and play one different frequency in each ear (eg 400Hz in left and 500Hz in right) 目前,我想为耳机用户创建两个声道(左和右),并在每个耳朵中播放一个不同的频率(例如,左为400Hz,右为500Hz)

With my current code, I've got two frequencies playing both are playing in each ear. 在我当前的代码中,我的两个耳朵都在演奏两个频率。 Does anyone have any suggestions as to how I could separate them? 有人对我如何分开建议有什么建议吗?

Here's my code thus far: 到目前为止,这是我的代码:

//create a synth and connect it to the master output (your speakers)

//Connect each separate tone to split
var split = new Tone.Split();
var leftEar = new Tone.Oscillator().toMaster();
var rightEar = new Tone.Oscillator().toMaster();

leftEar.frequency.value = 400;
rightEar.frequency.value = 500;

split.left = leftEar;
split.right = rightEar;

leftEar.connect(split);
rightEar.connect(split);

leftEar.start();
rightEar.start();

//Frequency is equivalent to difference between frequency in left and right ear
var frequency = {
  "Gamma" : [30, 50],
  "Beta" : [14, 30],
  "Alpha" : [8, 14],
  "Theta" : [4, 8],
  "Delta" : [0.1, 4]
};

Thanks! 谢谢!

Reference: https://tonejs.github.io/docs/#Split and https://github.com/Tonejs/Tone.js/wiki/Signals 参考: https : //tonejs.github.io/docs/#Splithttps://github.com/Tonejs/Tone.js/wiki/Signals

  • You want to use Merge , not Split 您要使用合并 ,而不是拆分
  • You are sending both your left and right oscillators directly to the master output, you should only be calling .toMaster() on split 您将左右振荡器都直接发送到主输出,只应在split上调用.toMaster()
  • You are deleting the GainNodes that Merge produces by doing split.left = leftEar; 您通过执行split.left = leftEar;删除合并产生的split.left = leftEar;
  • You are connecting both oscillators to both channels, you should be connecting them to their respective channels by doing leftEar.connect(split.left) 您要将两个振荡器都连接到两个通道,应该通过执行leftEar.connect(split.left)将它们连接到各自的通道。

After these changes your code will look like this: 这些更改之后,您的代码将如下所示:

var split = new Tone.Merge().toMaster();
var leftEar = new Tone.Oscillator();
var rightEar = new Tone.Oscillator();

leftEar.frequency.value = 400;
rightEar.frequency.value = 500;

leftEar.connect(split.left);
rightEar.connect(split.right);

leftEar.start();
rightEar.start();

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

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