diff --git a/src/cacophony.ts b/src/cacophony.ts index fc2b8f4..6ded283 100644 --- a/src/cacophony.ts +++ b/src/cacophony.ts @@ -135,7 +135,7 @@ export class Cacophony { const audio = new Audio(); audio.src = url; audio.crossOrigin = 'anonymous'; - return new Sound(url, undefined, this.context, this.globalGainNode, SoundType.HTML); + return new Sound(url, undefined, this.context, this.globalGainNode, SoundType.HTML, panType); } return CacheManager.getAudioBuffer(url, this.context).then(buffer => new Sound(url, buffer, this.context, this.globalGainNode, soundType, panType)); } diff --git a/src/playback.ts b/src/playback.ts index b329e87..c6fada8 100644 --- a/src/playback.ts +++ b/src/playback.ts @@ -17,12 +17,14 @@ * including buffer sources and media elements. It also provides detailed control over the audio's * spatial characteristics when using 3D audio. */ -import { AudioContext, IAudioBuffer, IGainNode, IPannerNode, IPannerOptions, IStereoPannerNode } from "standardized-audio-context"; + + +import { AudioContext, IAudioBuffer, IPannerNode, IPannerOptions, IStereoPannerNode } from "standardized-audio-context"; import { BaseSound, FadeType, LoopCount, PanType, Position } from "./cacophony"; -import { BiquadFilterNode, SourceNode } from "./context"; +import { BiquadFilterNode, GainNode, SourceNode } from "./context"; import { FilterManager } from "./filters"; -type GainNode = IGainNode; + type PannerNode = IPannerNode; type StereoPannerNode = IStereoPannerNode; @@ -65,20 +67,20 @@ export class Playback extends FilterManager implements BaseSound { } get stereoPan(): number | null { - if (this.panType === 'stereo' && this.panner instanceof StereoPannerNode) { - return this.panner.pan.value; + if (this.panType === 'stereo') { + return (this.panner as StereoPannerNode).pan.value; } return null; } set stereoPan(value: number) { - if (this.panType !== 'stereo' || !(this.panner instanceof StereoPannerNode)) { + if (this.panType !== 'stereo') { throw new Error('Stereo panning is not available when using HRTF.'); } if (value < -1 || value > 1) { throw new Error('Stereo pan value must be between -1 and 1.'); } - this.panner.pan.setValueAtTime(value, this.context.currentTime); + (this.panner as StereoPannerNode).pan.setValueAtTime(value, this.context.currentTime); } get duration() { diff --git a/src/sound.ts b/src/sound.ts index 5370b0e..a7bfa00 100644 --- a/src/sound.ts +++ b/src/sound.ts @@ -66,7 +66,6 @@ export class Sound extends FilterManager implements BaseSound { this.buffer = buffer; this.context = context; this.globalGainNode = globalGainNode; - this.panType = panType; } /** diff --git a/test.ogg b/test.ogg new file mode 100644 index 0000000..6c5e7f5 Binary files /dev/null and b/test.ogg differ