Ver código fonte

Fix sound sprite

David Catuhe 6 anos atrás
pai
commit
ed08203d0e
1 arquivos alterados com 12 adições e 9 exclusões
  1. 12 9
      src/Audio/sound.ts

+ 12 - 9
src/Audio/sound.ts

@@ -61,11 +61,11 @@ export interface ISoundOptions {
      */
     streaming?: boolean;
     /**
-     * Defines an optional length (in ms) inside the sound file
+     * Defines an optional length (in seconds) inside the sound file
      */
     length?: number;
     /**
-     * Defines an optional offset (in ms) inside the sound file
+     * Defines an optional offset (in seconds) inside the sound file
      */
     offset?: number;
 }
@@ -220,8 +220,8 @@ export class Sound {
             this.distanceModel = options.distanceModel || "linear";
             this._playbackRate = options.playbackRate || 1;
             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) {
@@ -746,21 +746,24 @@ export class Sound {
                 else {
                     var tryToPlay = () => {
                         if (Engine.audioEngine.audioContext) {
+                            length = length || this._length;
+                            offset = offset || this._offset;
+
                             this._soundSource = Engine.audioEngine.audioContext.createBufferSource();
                             this._soundSource.buffer = this._audioBuffer;
                             this._soundSource.connect(this._inputAudioNode);
                             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.onended = () => { this._onended(); };
                             startTime = time ? Engine.audioEngine.audioContext!.currentTime + time : Engine.audioEngine.audioContext!.currentTime;
                             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);
                         }
                     };