我正在做一个在线音频播放器,所以我想整合变调器在我的应用程序中,可以在Tone js但不在网络音频API...
所以我的想法是连接Tonejs 变调器 to 网络音频 API 音频上下文。
有什么可行的办法吗?
这是我的代码供参考
var audioCtx = new (window.AudioContext || window.webkitAudioContext);
var mediaElem = document.querySelector('audio');
var stream = audioCtx.createMediaElementSource(mediaElem);
var gainNode = audioCtx.createGain();
stream.connect(gainNode);
// tone js
var context = new Tone.Context(audioCtx); // Which is Mentioned in Tonejs Docs!
var pitchShift = new Tone.PitchShift().toMaster();
pitchShift.connect(gainNode);
// Gives Error!
gainNode.connect(audioCtx.destination);
我猜你想实现这样的信号流:
mediaElement > gainNode > pitchShift > destination
为了确保 Tone.js 使用相同的 AudioContext,您可以使用 Tone 对象上的 setter 来分配它。这需要在使用 Tone.js 执行任何其他操作之前完成。
Tone.context = context;
Tone.js 还导出一个帮助器,可用于将本机 AudioNode 连接到 Tone.js 提供的节点。
Tone.connect(gainNode, pitchShift);
我对您的示例代码进行了一些修改以合并这些更改。
var audioCtx = new (window.AudioContext || window.webkitAudioContext);
var mediaElem = document.querySelector('audio');
var stream = audioCtx.createMediaElementSource(mediaElem);
var gainNode = audioCtx.createGain();
// This a normal connection between to native AudioNodes.
stream.connect(gainNode);
// Set the context used by Tone.js
Tone.context = audioCtx;
var pitchShift = new Tone.PitchShift();
// Use the Tone.connect() helper to connect native AudioNodes with the nodes provided by Tone.js
Tone.connect(gainNode, pitchShift);
Tone.connect(pitchShift, audioCtx.destination);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)