2016-05-04 24 views
0

我需要循環我的來源與一些交叉參數(以秒爲單位)。在示例邊框上不中斷循環播放會很棒.AudioBufferSourceNode在我的代碼中是audioNode。 我面臨無法重用緩衝區的問題,是否有可能解決這個問題?我如何循環AudioBufferSourceNode與重疊(使用相同的AudioBuffer)

playNoteOn: function(indexNote){ 
     var attack = this.get('attack'), 
      release = this.get('release'), 
      volume = 1 + this.get('volume')/100, 
      reverb = _.clone(this.get('reverb')), 
      loop = this.get('loop'), cross; 

     //peace for Loop process 
     if (loop) { 
      //milli sec 
      attack = this.get('startLoop')*1000; 
      release = this.get('endLoop')*1000; 
      //sec 
      cross = this.get('crossLoop'); 
     } 

     //peace for ADSR process 
     var t0 = this.get('audioNode').context.currentTime, 
      spread = attack/1000 + release/1000, 
      attackSpread = t0 + attack/1000; 

     [this.get('schema').leftGain, this.get('schema').rightGain].forEach(function(gain, index){ 
      gain.gain.cancelScheduledValues(0); 
      gain.gain.setValueAtTime(0, t0); 
      gain.gain.linearRampToValueAtTime(volume, attackSpread); 
      // gain.gain.setValueAtTime(volume, decaySpread); 
      // gain.gain.linearRampToValueAtTime(0, releaseSpread); 
     }); 
     this.get('audioNode').connect(this.get('schema').splitter, 0, 0); 
     this.get('audioNode').connect(this.get('schema').leftGain); 
     this.get('audioNode').connect(this.get('schema').rightGain); 
     this.get('audioNode').connect(this.get('schema').reverb); 
     this.get('audioNode').connect(APP.Models.Synth.get('schema').reverb); 

     APP.Models.Synth.get('effects').where({active: false}).forEach(function(effect){ 
      effect.get('node').disconnect(); 
     }); 

     APP.Models.Synth.get('effects').where({active: true}).forEach(function(effect){ 
      effect.get('node').disconnect(); 
      effect.get('node').setParams(effect.toJSON()).getNode(this.get('audioNode'), [this.get('schema').leftGain, this.get('schema').rightGain]); 
     }, this); 

     if(loop){ 
      this.get('audioNode').loop = true; 
      this.get('audioNode').loopEnd = this.get('audioNode').buffer.duration - cross; 
     } 
     this.get('audioNode').start(t0); 
    }, 

回答

0

您不能重複使用緩衝區。一旦停止,源緩衝區將永遠消失。無論如何,你的音頻節點對象在哪裏?但這沒有問題。當您從聲音文件解碼時,您可以再次使用來自解碼的緩衝區。只需創建更多緩衝源。你可以創建儘可能多的,你喜歡。你用什麼語言?說一些你正在做的事情以及你使用的框架。

請注意緩衝區與解碼緩衝區之間的區別。您的audionode是一個緩衝區來源,可以通過緩衝區來提供。您可以重新使用緩衝區而不是緩衝區源。因此,請在您的playnote代碼中創建緩衝區源。

相關問題