|
@@ -61,11 +61,11 @@ export interface ISoundOptions {
|
|
*/
|
|
*/
|
|
streaming?: boolean;
|
|
streaming?: boolean;
|
|
/**
|
|
/**
|
|
- * Defines an optional length (in ms) inside the sound file
|
|
|
|
|
|
+ * Defines an optional length (in seconds) inside the sound file
|
|
*/
|
|
*/
|
|
length?: number;
|
|
length?: number;
|
|
/**
|
|
/**
|
|
- * Defines an optional offset (in ms) inside the sound file
|
|
|
|
|
|
+ * Defines an optional offset (in seconds) inside the sound file
|
|
*/
|
|
*/
|
|
offset?: number;
|
|
offset?: number;
|
|
}
|
|
}
|
|
@@ -220,8 +220,8 @@ export class Sound {
|
|
this.distanceModel = options.distanceModel || "linear";
|
|
this.distanceModel = options.distanceModel || "linear";
|
|
this._playbackRate = options.playbackRate || 1;
|
|
this._playbackRate = options.playbackRate || 1;
|
|
this._streaming = options.streaming || false;
|
|
this._streaming = options.streaming || false;
|
|
- this._length = options.length ? options.length / 1000 : undefined;
|
|
|
|
- this._offset = options.offset ? options.offset / 1000 : undefined;
|
|
|
|
|
|
+ this._length = options.length;
|
|
|
|
+ this._offset = options.offset;
|
|
}
|
|
}
|
|
|
|
|
|
if (Engine.audioEngine.canUseWebAudio && Engine.audioEngine.audioContext) {
|
|
if (Engine.audioEngine.canUseWebAudio && Engine.audioEngine.audioContext) {
|
|
@@ -746,21 +746,24 @@ export class Sound {
|
|
else {
|
|
else {
|
|
var tryToPlay = () => {
|
|
var tryToPlay = () => {
|
|
if (Engine.audioEngine.audioContext) {
|
|
if (Engine.audioEngine.audioContext) {
|
|
|
|
+ length = length || this._length;
|
|
|
|
+ offset = offset || this._offset;
|
|
|
|
+
|
|
this._soundSource = Engine.audioEngine.audioContext.createBufferSource();
|
|
this._soundSource = Engine.audioEngine.audioContext.createBufferSource();
|
|
this._soundSource.buffer = this._audioBuffer;
|
|
this._soundSource.buffer = this._audioBuffer;
|
|
this._soundSource.connect(this._inputAudioNode);
|
|
this._soundSource.connect(this._inputAudioNode);
|
|
this._soundSource.loop = this.loop;
|
|
this._soundSource.loop = this.loop;
|
|
- if (this._offset !== undefined) {
|
|
|
|
- this._soundSource.loopStart = this._offset;
|
|
|
|
|
|
+ if (offset !== undefined) {
|
|
|
|
+ this._soundSource.loopStart = offset;
|
|
}
|
|
}
|
|
- if (this._length !== undefined) {
|
|
|
|
- this._soundSource.loopEnd = (this._offset! | 0) + this._length!;
|
|
|
|
|
|
+ if (length !== undefined) {
|
|
|
|
+ this._soundSource.loopEnd = (offset! | 0) + length!;
|
|
}
|
|
}
|
|
this._soundSource.playbackRate.value = this._playbackRate;
|
|
this._soundSource.playbackRate.value = this._playbackRate;
|
|
this._soundSource.onended = () => { this._onended(); };
|
|
this._soundSource.onended = () => { this._onended(); };
|
|
startTime = time ? Engine.audioEngine.audioContext!.currentTime + time : Engine.audioEngine.audioContext!.currentTime;
|
|
startTime = time ? Engine.audioEngine.audioContext!.currentTime + time : Engine.audioEngine.audioContext!.currentTime;
|
|
const actualOffset = this.isPaused ? this._startOffset % this._soundSource!.buffer!.duration : offset ? offset : 0;
|
|
const actualOffset = this.isPaused ? this._startOffset % this._soundSource!.buffer!.duration : offset ? offset : 0;
|
|
- this._soundSource!.start(startTime, actualOffset, this.loop ? undefined : this._length);
|
|
|
|
|
|
+ this._soundSource!.start(startTime, actualOffset, this.loop ? undefined : length);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|