forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioListener.js
More file actions
113 lines (65 loc) · 2.05 KB
/
AudioListener.js
File metadata and controls
113 lines (65 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* @author mrdoob / http://mrdoob.com/
*/
import { Vector3 } from '../math/Vector3';
import { Quaternion } from '../math/Quaternion';
import { Object3D } from '../core/Object3D';
import { getAudioContext } from './AudioContext';
function AudioListener() {
Object3D.call( this );
this.type = 'AudioListener';
this.context = getAudioContext();
this.gain = this.context.createGain();
this.gain.connect( this.context.destination );
this.filter = null;
}
AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
constructor: AudioListener,
getInput: function () {
return this.gain;
},
removeFilter: function ( ) {
if ( this.filter !== null ) {
this.gain.disconnect( this.filter );
this.filter.disconnect( this.context.destination );
this.gain.connect( this.context.destination );
this.filter = null;
}
},
getFilter: function () {
return this.filter;
},
setFilter: function ( value ) {
if ( this.filter !== null ) {
this.gain.disconnect( this.filter );
this.filter.disconnect( this.context.destination );
} else {
this.gain.disconnect( this.context.destination );
}
this.filter = value;
this.gain.connect( this.filter );
this.filter.connect( this.context.destination );
},
getMasterVolume: function () {
return this.gain.gain.value;
},
setMasterVolume: function ( value ) {
this.gain.gain.value = value;
},
updateMatrixWorld: ( function () {
var position = new Vector3();
var quaternion = new Quaternion();
var scale = new Vector3();
var orientation = new Vector3();
return function updateMatrixWorld( force ) {
Object3D.prototype.updateMatrixWorld.call( this, force );
var listener = this.context.listener;
var up = this.up;
this.matrixWorld.decompose( position, quaternion, scale );
orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
listener.setPosition( position.x, position.y, position.z );
listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
};
} )()
} );
export { AudioListener };