|
@@ -621,28 +621,24 @@ class SampleNode {
|
|
if (this.isCanceled) {
|
|
if (this.isCanceled) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- this.getPositionWorklet();
|
|
|
|
- this._source.connect(this._positionWorklet);
|
|
|
|
|
|
+ this._source.connect(this.getPositionWorklet());
|
|
if (start) {
|
|
if (start) {
|
|
this.start();
|
|
this.start();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Get a AudioWorkletProcessor from the pool, or create one if no processor is available.
|
|
|
|
|
|
+ * Get a AudioWorkletProcessor
|
|
|
|
+ * @returns {AudioWorkletNode}
|
|
*/
|
|
*/
|
|
getPositionWorklet() {
|
|
getPositionWorklet() {
|
|
if (this._positionWorklet != null) {
|
|
if (this._positionWorklet != null) {
|
|
- return;
|
|
|
|
- }
|
|
|
|
- if (GodotAudio.audioPositionWorkletPool.length == 0) {
|
|
|
|
- this._positionWorklet = new AudioWorkletNode(
|
|
|
|
- GodotAudio.ctx,
|
|
|
|
- 'godot-position-reporting-processor'
|
|
|
|
- );
|
|
|
|
- } else {
|
|
|
|
- this._positionWorklet = GodotAudio.audioPositionWorkletPool.pop();
|
|
|
|
|
|
+ return this._positionWorklet;
|
|
}
|
|
}
|
|
|
|
+ this._positionWorklet = new AudioWorkletNode(
|
|
|
|
+ GodotAudio.ctx,
|
|
|
|
+ 'godot-position-reporting-processor'
|
|
|
|
+ );
|
|
this._positionWorklet.port.onmessage = (event) => {
|
|
this._positionWorklet.port.onmessage = (event) => {
|
|
switch (event.data['type']) {
|
|
switch (event.data['type']) {
|
|
case 'position':
|
|
case 'position':
|
|
@@ -652,6 +648,7 @@ class SampleNode {
|
|
// Do nothing.
|
|
// Do nothing.
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
+ return this._positionWorklet;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -681,8 +678,7 @@ class SampleNode {
|
|
if (this._positionWorklet) {
|
|
if (this._positionWorklet) {
|
|
this._positionWorklet.disconnect();
|
|
this._positionWorklet.disconnect();
|
|
this._positionWorklet.port.onmessage = null;
|
|
this._positionWorklet.port.onmessage = null;
|
|
- this._positionWorklet.port.postMessage({ type: 'clear' });
|
|
|
|
- GodotAudio.audioPositionWorkletPool.push(this._positionWorklet);
|
|
|
|
|
|
+ this._positionWorklet.port.postMessage({ type: 'ended' });
|
|
this._positionWorklet = null;
|
|
this._positionWorklet = null;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1199,7 +1195,6 @@ const _GodotAudio = {
|
|
|
|
|
|
/** @type {Promise} */
|
|
/** @type {Promise} */
|
|
audioPositionWorkletPromise: null,
|
|
audioPositionWorkletPromise: null,
|
|
- audioPositionWorkletPool: [],
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Converts linear volume to Db.
|
|
* Converts linear volume to Db.
|