2

私のオブジェクトでは、既にオブジェクト ( ) に格納されている (有効な) を再生するゲイン ノード ( ) に接続されたAudioBufferSourceNodeオブジェクト ( ) を取得しました。this.bSrcthis.audioDestinationAudioBufferthis.audioBuffer

this.audioDestinationがオーディオ コンテキストの最終宛先に接続されていて、オブジェクト ( ) でメソッドthis.mainContext.destinationを呼び出すと、正常に再生されます。start(0)AudioBufferSourceNodethis.bSrc

がオーディオ コンテキストの最終目的地にまだ接続されていない場合、バッファは再生されませんthis.audioDestinationが(問題ありません)、接続が確立されるまで再生が遅延されます (したがって、AudioBufferSourceNode の再生がいつ終了するかについての仮定は無効になります)。 .

私は現在、プラグイン アーキテクチャを実装しています。このアーキテクチャでは、すべてのプラグインに audioDestination ゲイン ノードがあり、最終的なオーディオ コンテキストの宛先に間接的に接続されているかどうかを認識していません (認識してはなりません)。私にとって論理的に思えるのは、AudioBufferSourceNode が最終的なオーディオ コンテキストの宛先に接続されていなくても、すぐに「再生」して終了する必要があるということです。しかし、このようにはうまくいかないようです。私は正しいですか、それとも間違っていますか?この動作を変更する方法はありますか?

コード:

/* Create the audio Context. */
this.mainContext = new webkitAudioContext;

/* Create an audio gain node */
this.audioDestination = this.mainContext.createGainNode();

/* [...] An AudioBuffer gets decoded and stored into this.audioBuffer*/

/* Create an AudioBufferSourceNode and try to play it immediately */
this.bSrc = this.audioContext.createBufferSource();
this.bSrc.connect (this.audioDestination);
this.bSrc.buffer = this.audioBuffer;
this.bSrc.start(0);

/* Create a callback for when the AudioBufferSourceNode finishes playing */
if (!this.bSrc.loop) {
       var pbTimer = setTimeout(function() {
            this.playFinishedCallback();
        }.bind(this), this.audioBuffer.duration * 1000 / this.bSrc.playbackRate.value);
    }

 /* Connect this.audioDestination to the final AudioContext destination */
 /* If this statement is executed after the previous ones, playback will start NOW */
 this.audioDestination.connect(this.mainContext.destination);
4

2 に答える 2

2

これは、Web Audio API が現在 Chrome に実装されている方法であり、そこで使用されている設計です。それを変更するという話がありました。実際、私はあなたが説明する「オーディオ ケーブル モデル」の支持者でした。:) とはいえ、まともなモデルはこれだけではありません。現在の実装では、この動作を変更する方法はありません。

ただし、簡単な回避策があります。ゼロに設定されたゲイン ノードを context.destination に接続したままにして、すべての ABSN をそれに接続し、(最終的に) context.destination に接続します。

于 2013-01-31T22:22:20.357 に答える
0

意味あり。context.destination を stdout と考えてください。context.destination に接続しないと、音声の行き先がありません。最後の行 (context.destination への接続) を gain ノードを作成した直後まで移動すると、遅延は発生しないと思います。

于 2013-01-31T13:34:05.747 に答える