cacophony
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "cacophony", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Typescript audio library with caching", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -24,2 +24,4 @@ import { AudioContext, IAudioBuffer, IAudioBufferSourceNode, IAudioListener, IBiquadFilterNode, IGainNode, IPannerNode } from 'standardized-audio-context'; | ||
moveTo(x: number, y: number, z: number): void; | ||
volume: number; | ||
loop(loopCount?: LoopCount): LoopCount; | ||
@@ -72,3 +74,2 @@ } | ||
pause() { | ||
@@ -96,2 +97,10 @@ if ('suspend' in this.context) { | ||
get volume(): number { | ||
return this.globalGainNode.gain.value; | ||
} | ||
set volume(volume: number) { | ||
this.setGlobalVolume(volume); | ||
} | ||
mute() { | ||
@@ -203,5 +212,13 @@ this.prevVolume = this.globalGainNode.gain.value; | ||
} | ||
get volume(): number { | ||
return this.globalGainNode.gain.value; | ||
} | ||
set volume(volume: number) { | ||
this.globalGainNode.gain.value = volume; | ||
this.playbacks.forEach(p => p.volume = volume); | ||
} | ||
} | ||
class Playback extends FilterManager implements BaseSound { | ||
@@ -230,3 +247,2 @@ context: AudioContext; | ||
handleLoop(): void { | ||
@@ -246,2 +262,6 @@ if (this.loopCount === 'infinite' || this.currentLoop < this.loopCount) { | ||
get volume(): number { | ||
return this.gainNode.gain.value; | ||
} | ||
set volume(v: number) { | ||
@@ -253,15 +273,12 @@ this.gainNode.gain.value = v; | ||
return new Promise(resolve => { | ||
// Setting the initial gain value to 0 | ||
this.gainNode.gain.setValueAtTime(0, this.context.currentTime); | ||
switch (FfadeType) { | ||
case 'exponential': | ||
// Scheduling an exponential fade up | ||
this.gainNode.gain.exponentialRampToValueAtTime(1, this.context.currentTime + time); | ||
break; | ||
case 'linear': | ||
// Scheduling a linear ramp to the target gain value over the given duration | ||
this.gainNode.gain.linearRampToValueAtTime(1, this.context.currentTime + time); | ||
} | ||
// Resolving the Promise after the fade-in time | ||
setTimeout(() => resolve(), time * 1000); | ||
let volume = 0; | ||
const increment = this.gainNode.gain.value / (time * 60); // Assuming time is in seconds | ||
const interval = setInterval(() => { | ||
volume += increment; | ||
this.gainNode.gain.value = volume; | ||
if (volume >= this.gainNode.gain.value) { | ||
clearInterval(interval); | ||
resolve(); | ||
} | ||
}, 1000 / 60); // 60 times per second | ||
}); | ||
@@ -307,4 +324,4 @@ } | ||
} | ||
} | ||
} | ||
resume(): void { | ||
@@ -402,3 +419,11 @@ if ('resume' in this.source.context) { | ||
get volume(): number { | ||
return this.sounds[0].volume; | ||
} | ||
set volume(volume: number) { | ||
this.sounds.forEach(sound => sound.volume = volume); | ||
} | ||
} | ||
33232
519
39
8