cacophony
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -1,2 +0,2 @@ | ||
import { AudioContext, IAudioBuffer, IAudioBufferSourceNode, IAudioListener, IBiquadFilterNode, IGainNode, IMediaStreamAudioSourceNode } from 'standardized-audio-context'; | ||
import { AudioContext, IAudioBuffer, IAudioBufferSourceNode, IAudioListener, IBiquadFilterNode, IGainNode, IMediaStreamAudioSourceNode, IPannerOptions } from 'standardized-audio-context'; | ||
type GainNode = IGainNode<AudioContext>; | ||
@@ -20,2 +20,3 @@ type BiquadFilterNode = IBiquadFilterNode<AudioContext>; | ||
loop?(loopCount?: LoopCount): LoopCount; | ||
threeDOptions?: IPannerOptions; | ||
} | ||
@@ -56,3 +57,2 @@ export declare class Cacophony { | ||
loopCount: LoopCount; | ||
seek(time: number): void; | ||
constructor(buffer: AudioBuffer, context: AudioContext, globalGainNode: IGainNode<AudioContext>); | ||
@@ -64,2 +64,3 @@ preplay(): Playback[]; | ||
resume(): void; | ||
seek(time: number): void; | ||
set position(position: Position); | ||
@@ -72,2 +73,3 @@ get position(): Position; | ||
set volume(volume: number); | ||
isPlaying(): boolean; | ||
} | ||
@@ -82,6 +84,8 @@ declare class Playback extends FilterManager implements BaseSound { | ||
private buffer; | ||
seek(time: number): void; | ||
constructor(source: AudioBufferSourceNode, gainNode: GainNode, context: AudioContext, loopCount?: LoopCount); | ||
handleLoop(): void; | ||
play(): this[]; | ||
get threeDOptions(): IPannerOptions; | ||
set threeDOptions(options: Partial<IPannerOptions>); | ||
seek(time: number): void; | ||
get volume(): number; | ||
@@ -92,2 +96,3 @@ set volume(v: number); | ||
fadeOut(time: number, fadeType?: FadeType): Promise<void>; | ||
isPlaying(): boolean; | ||
cleanup(): void; | ||
@@ -94,0 +99,0 @@ loop(loopCount?: LoopCount): LoopCount; |
@@ -117,5 +117,2 @@ "use strict"; | ||
class Sound extends FilterManager { | ||
seek(time) { | ||
this.playbacks.forEach(playback => playback.seek(time)); | ||
} | ||
constructor(buffer, context, globalGainNode) { | ||
@@ -161,2 +158,5 @@ super(); | ||
} | ||
seek(time) { | ||
this.playbacks.forEach(playback => playback.seek(time)); | ||
} | ||
set position(position) { | ||
@@ -192,18 +192,8 @@ this._position = position; | ||
} | ||
isPlaying() { | ||
return this.playbacks.some(p => p.isPlaying()); | ||
} | ||
} | ||
exports.Sound = Sound; | ||
class Playback extends FilterManager { | ||
seek(time) { | ||
if (!this.source || !this.buffer || !this.gainNode || !this.panner) { | ||
throw new Error('Cannot seek a sound that has been cleaned up'); | ||
} | ||
// Stop the current playback | ||
this.source.stop(); | ||
// Create a new source to start from the desired time | ||
this.source = this.context.createBufferSource(); | ||
this.source.buffer = this.buffer; | ||
this.refreshFilters(); | ||
this.source.connect(this.panner).connect(this.gainNode); | ||
this.source.start(0, time); | ||
} | ||
constructor(source, gainNode, context, loopCount = 0) { | ||
@@ -240,2 +230,47 @@ super(); | ||
} | ||
get threeDOptions() { | ||
if (!this.panner) { | ||
throw new Error('Cannot get 3D options of a sound that has been cleaned up'); | ||
} | ||
return { | ||
coneInnerAngle: this.panner.coneInnerAngle, | ||
coneOuterAngle: this.panner.coneOuterAngle, | ||
coneOuterGain: this.panner.coneOuterGain, | ||
distanceModel: this.panner.distanceModel, | ||
maxDistance: this.panner.maxDistance, | ||
channelCount: this.panner.channelCount, | ||
channelCountMode: this.panner.channelCountMode, | ||
channelInterpretation: this.panner.channelInterpretation, | ||
panningModel: this.panner.panningModel, | ||
refDistance: this.panner.refDistance, | ||
rolloffFactor: this.panner.rolloffFactor, | ||
positionX: this.panner.positionX.value, | ||
positionY: this.panner.positionY.value, | ||
positionZ: this.panner.positionZ.value, | ||
orientationX: this.panner.orientationX.value, | ||
orientationY: this.panner.orientationY.value, | ||
orientationZ: this.panner.orientationZ.value | ||
}; | ||
} | ||
set threeDOptions(options) { | ||
if (!this.panner) { | ||
throw new Error('Cannot set 3D options of a sound that has been cleaned up'); | ||
} | ||
Object.entries(options).forEach(([key, value]) => { | ||
Object.assign(this.panner, { [key]: value }); | ||
}); | ||
} | ||
seek(time) { | ||
if (!this.source || !this.buffer || !this.gainNode || !this.panner) { | ||
throw new Error('Cannot seek a sound that has been cleaned up'); | ||
} | ||
// Stop the current playback | ||
this.source.stop(); | ||
// Create a new source to start from the desired time | ||
this.source = this.context.createBufferSource(); | ||
this.source.buffer = this.buffer; | ||
this.refreshFilters(); | ||
this.source.connect(this.panner).connect(this.gainNode); | ||
this.source.start(0, time); | ||
} | ||
get volume() { | ||
@@ -309,2 +344,6 @@ if (!this.gainNode) { | ||
} | ||
isPlaying() { | ||
var _a; | ||
return ((_a = this.source) === null || _a === void 0 ? void 0 : _a.context.state) === 'running'; | ||
} | ||
cleanup() { | ||
@@ -311,0 +350,0 @@ if (this.source) { |
{ | ||
"name": "cacophony", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"description": "Typescript audio library with caching", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
69776
945
1