2016-05-04 8 views
0

ソースをいくつかのクロスパラメーター(秒単位)でループする必要があります。サンプルborder.AudioBufferSourceNodeを中断することなくループを聴くことは素晴らしいことでしょう。私のコードでは、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は、バッファによって供給されるバッファソースです。バッファを再利用することはできますが、バッファソースは再利用することはできません。したがって、あなたのプレイノートコードにバッファーソースを作成してください。

関連する問題