forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioListener.js
129 lines (77 loc) · 2.78 KB
/
AudioListener.js
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* @author mrdoob / http://mrdoob.com/
*/
import { Vector3 } from '../math/Vector3';
import { Quaternion } from '../math/Quaternion';
import { Object3D } from '../core/Object3D';
import { AudioContext } from './AudioContext';
function AudioListener() {
Object3D.call( this );
this.type = 'AudioListener';
this.context = AudioContext.getContext();
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 );
if ( listener.positionX ) {
listener.positionX.setValueAtTime( position.x, this.context.currentTime );
listener.positionY.setValueAtTime( position.y, this.context.currentTime );
listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
listener.upX.setValueAtTime( up.x, this.context.currentTime );
listener.upY.setValueAtTime( up.y, this.context.currentTime );
listener.upZ.setValueAtTime( up.z, this.context.currentTime );
} else {
listener.setPosition( position.x, position.y, position.z );
listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
}
};
} )()
} );
export { AudioListener };