我正在围绕 scriptProcessorNode 振荡器构建课程。我已经将我的onaudioprocess
事件处理程序包装在一个函数中Gendy.prototype.process
。我可以从这个包装函数中访问全局变量和函数,但不能从onaudioprocess
函数中访问它们。
我为这些属性设计了一个解决方法,在包装函数中重新定义它们,但是当尝试使用this.walk()
.
这是我的代码:
Gendy.prototype.process = function(){
var point = 0;
var index = 0;
var y = 0;
var breakpoint = this.breakpoint;
var freq = this.freq;
var walk = this.walk();
this.scriptNode.onaudioprocess = function(audioProcessingEvent){
var outputBuffer = audioProcessingEvent.outputBuffer;
var outputData = outputBuffer.getChannelData(0);
for(var j = 0; j < outputData.length;j++){
// linearly interpolate between the new breakpoint positions
// get the interp point by comparing index to the x distance
var lerp = (index - breakpoint[point].x) / (breakpoint[point+1].x - breakpoint[point].x);
y = lerp * (breakpoint[point+1].y - breakpoint[point].y) + breakpoint[point].y;
if(point < breakpoint.length && index >= breakpoint[point+1].x) {
point++;
}
outputData[j] = y;
index+=freq;
if(index >= breakpoint[breakpoint.length-1].x){
index = 0;
point = 0;
walk();
}
}
}
}
这听起来不错,但会返回错误:
Uncaught TypeError: walk is not a function
几行,然后
Uncaught TypeError: undefined is not a function
永远。
这是 scriptProcessorNode 的错误吗?任何见解将不胜感激!