私は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 のバグですか? どんな洞察もいただければ幸いです!