Fix glitch when fading in sounds

master
Talon 2021-11-09 13:24:45 +01:00
parent 9e95b4c202
commit 576debf261
2 changed files with 4 additions and 4 deletions

View File

@ -131,18 +131,18 @@ export default class AudioSource {
}
}
fadeOut(time) {
this.gain.gain.setValueAtTime(this.getVolume(), this.context.getContext().currentTime);
if (!this.node) {
return;
}
this.gain.gain.setValueAtTime(this.getVolume(), this.context.getContext().currentTime);
this.gain.gain.exponentialRampToValueAtTime(0.0001, this.context.getContext().currentTime + time);
setTimeout(() => this.stop(), time * 1000);
}
fadeIn(time) {
this.gain.gain.setValueAtTime(0.0001, this.context.getContext().currentTime);
if (!this.node) {
this.play();
}
this.gain.gain.setValueAtTime(0.0001, this.context.getContext().currentTime);
this.gain.gain.exponentialRampToValueAtTime(this.volume, this.context.getContext().currentTime + time);
}
}

View File

@ -82,17 +82,17 @@ export class StreamingSource {
this.element.loop = true;
}
fadeIn(time) {
this.gain.gain.setValueAtTime(0.0001, this.context.getContext().currentTime);
if (!this.node) {
this.play();
}
this.gain.gain.setValueAtTime(0.0001, this.context.getContext().currentTime);
this.gain.gain.exponentialRampToValueAtTime(this.getVolume(), this.context.getContext().currentTime + time);
}
fadeOut(time) {
this.gain.gain.setValueAtTime(this.getVolume(), this.context.getContext().currentTime);
if (!this.node) {
return;
}
this.gain.gain.setValueAtTime(this.getVolume(), this.context.getContext().currentTime);
this.gain.gain.exponentialRampToValueAtTime(0.0001, this.context.getContext().currentTime + time);
setTimeout(() => this.stop(), time * 1000);
}