41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
// The code that deals with 3d audio
|
|
import ResonanceAudio from '../vendor/resonance-es6/main';
|
|
import EventEmitter from 'eventemitter3';
|
|
import vec3 from '../../tsm/vec3';
|
|
export default class Scene extends EventEmitter {
|
|
constructor(context) {
|
|
super();
|
|
this.context = context;
|
|
this.scene = new ResonanceAudio(this.context.getContext(), {
|
|
ambisonicOrder: 3
|
|
});
|
|
this.listener = this.context.getContext().listener;
|
|
this.init();
|
|
}
|
|
init() {
|
|
// this.scene.output.connect(this.context.getOutputDestination());
|
|
}
|
|
createSource() {
|
|
const source = this.scene.createSource();
|
|
return Object.assign(Object.assign({}, source), { getInput: () => source.input });
|
|
}
|
|
getOutput() {
|
|
return this.scene.output;
|
|
}
|
|
getInput() {
|
|
return this.scene.input;
|
|
}
|
|
setListenerPosition(x, y, z) {
|
|
this.scene.setListenerPosition(x, y, z);
|
|
}
|
|
setListenerOrientation(forward, rawup) {
|
|
let fwd = new vec3([forward.x, forward.y, forward.z]);
|
|
let up = fwd.copy();
|
|
vec3.cross(up, new vec3([rawup.x, rawup.y, rawup.z]), up);
|
|
vec3.cross(up, fwd, up);
|
|
fwd.normalize();
|
|
up.normalize();
|
|
this.scene.setListenerOrientation(forward.x, forward.y, forward.z, rawup.x, rawup.y, rawup.z);
|
|
}
|
|
}
|