Fix glitch when fading in sounds
parent
9e95b4c202
commit
576debf261
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue