Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网络音频api在第一次嘟嘟声后不工作_Javascript_Web Audio Api - Fatal编程技术网

Javascript 网络音频api在第一次嘟嘟声后不工作

Javascript 网络音频api在第一次嘟嘟声后不工作,javascript,web-audio-api,Javascript,Web Audio Api,我正在使用JavaScript构建一个简单的可扩展metronome类,其灵感来源于“两个时钟的故事”中的代码: 我已经将原始代码转换为一个类,遵循与原始代码相同的基本模式,并且还包括了一些附加的位和块。这段代码工作得很好,除了一个巨大的问题,那就是振荡器在播放第一个声音后不会启动(在我的代码版本中)。如果我在“scheduleNote”中包含一个警报,那么声音效果会非常好 this.scheduleNote = function( beatNumber ) { if (( this.

我正在使用JavaScript构建一个简单的可扩展metronome类,其灵感来源于“两个时钟的故事”中的代码:

我已经将原始代码转换为一个类,遵循与原始代码相同的基本模式,并且还包括了一些附加的位和块。这段代码工作得很好,除了一个巨大的问题,那就是振荡器在播放第一个声音后不会启动(在我的代码版本中)。如果我在“scheduleNote”中包含一个警报,那么声音效果会非常好

this.scheduleNote = function( beatNumber ) {

    if (( this.noteResolution == 1 ) && ( beatNumber % 2 )) {
        return; // we're not playing non-8th 16th notes
    }
    if (( this.noteResolution == 2 ) && ( beatNumber % 4 )) {
        return; // we're not playing non-quarter 8th notes
    }

    var oscillator = myAC.audioContext.createOscillator(); // Create sound source
    var gainNode = myAC.audioContext.createGain(); // Create gain node

    oscillator.type = "square"; // Square wave
    oscillator.frequency.value = this.frequency; // Frequency in hertz 
    oscillator.connect(gainNode); // Connect sound source 2 to gain node 2
    gainNode.connect(myAC.audioContext.destination); // Connect gain node 2 to output
    gainNode.gain.value = 1; // Set volume to 100 percent
    oscillator.start(myAC.audioContext.currentTime);
    oscillator.stop(myAC.audioContext.currentTime + this.noteLength);
// alert("un-comment this: suddenly the sound works perfectly...");
    oscillator = null;
} // this.scheduleNote( beatNumber )
我的问题:为什么我的声音不能播放(在第二个++循环中),最重要的是,修复方法是什么


我的例子:。

似乎在某个地方有一个无限循环。我现在没有时间调试,但控制台中出现了“Uncaught RangeError:超出了最大调用堆栈大小”,这让我觉得是这样的…@Oskarerikson我有几天没有靠近计算机了。scheduleNote(我记得)设计为无休止地运行(播放/暂停按钮控制它的启动)。