Add impulse response stuff
This commit is contained in:
@@ -9,7 +9,7 @@ export default class RoomBuilder {
|
||||
this.room.id = ID;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
withTitle(title) {
|
||||
this.room.title = title;
|
||||
return this;
|
||||
@@ -60,6 +60,21 @@ export default class RoomBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
withMusic(file) {
|
||||
this.room.music = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
withAmbience(file) {
|
||||
this.room.ambience = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
withImpulse(file) {
|
||||
this.room.impulse = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
create() {
|
||||
return this.room;
|
||||
}
|
||||
|
@@ -23,4 +23,16 @@ export default class Output {
|
||||
play(file) {
|
||||
this.sound.play(file);
|
||||
}
|
||||
|
||||
setAmbience(file) {
|
||||
return this.sound.setAmbience(file);
|
||||
}
|
||||
|
||||
setMusic(file) {
|
||||
return this.sound.setMusic(file);
|
||||
}
|
||||
|
||||
setImpulse(file) {
|
||||
this.sound.setImpulse(file);
|
||||
}
|
||||
}
|
@@ -12,9 +12,15 @@ export default class Room {
|
||||
this.canExitLogic = null;
|
||||
this.tickCallback = null;
|
||||
this.context = null;
|
||||
this.music = null;
|
||||
this.ambience = null;
|
||||
this.impulse = null;
|
||||
}
|
||||
|
||||
async onEnter() {
|
||||
this.context.output.setMusic(this.music);
|
||||
this.context.output.setAmbience(this.ambience);
|
||||
this.context.output.setImpulse(this.impulse);
|
||||
if (this.enterCallback) return this.enterCallback(this.context);
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,6 @@ import Resonator from '../framework/resonator';
|
||||
export default class Sound {
|
||||
constructor() {
|
||||
this.res = new Resonator();
|
||||
this.res.setEnvironmentImpulse(`assets/Greek7EchoHall.wav`);
|
||||
this.ambience = null;
|
||||
this.music = null;
|
||||
this.previousAmbience = null;
|
||||
@@ -15,4 +14,34 @@ export default class Sound {
|
||||
const sound = this.res.loadImmediate(file);
|
||||
sound.play();
|
||||
}
|
||||
|
||||
async setAmbience(file) {
|
||||
if (this.ambience) {
|
||||
this.previousAmbience = this.ambience;
|
||||
this.ambience = null;
|
||||
setTimeout(() => this.previousAmbience.fadeOut(6), 1500);
|
||||
// setTimeout(() => this.previousAmbience.destroy(), 6000);
|
||||
}
|
||||
if (!file) return;
|
||||
this.ambience = this.res.stream(file, 0);
|
||||
this.ambience.play();
|
||||
this.ambience.loop(true);
|
||||
this.ambience.fadeIn(3);
|
||||
}
|
||||
|
||||
setMusic(file) {
|
||||
if (this.music) {
|
||||
this.previousMusic = this.music;
|
||||
setTimeout(() => this.previousMusic.fadeOut(2), 500);
|
||||
setTimeout(() => this.previousMusic.destroy(), 2000);
|
||||
}
|
||||
if (!file) return;
|
||||
this.music = this.res.stream(file, 1);
|
||||
this.music.play();
|
||||
this.music.fadeIn(2);
|
||||
}
|
||||
|
||||
setImpulse(file) {
|
||||
this.res.setEnvironmentImpulse(file);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user