@@ -22,6 +22,7 @@ export class BoardAudio {
22
22
private oscillator : OscillatorNode | undefined ;
23
23
private volumeNode : GainNode | undefined ;
24
24
private muteNode : GainNode | undefined ;
25
+ private sensitivityNode : GainNode | undefined ;
25
26
26
27
default : BufferedAudio | undefined ;
27
28
speech : BufferedAudio | undefined ;
@@ -46,6 +47,11 @@ export class BoardAudio {
46
47
this . context . currentTime
47
48
) ;
48
49
this . muteNode . connect ( this . context . destination ) ;
50
+ this . sensitivityNode = this . context . createGain ( ) ;
51
+ this . sensitivityNode . gain . setValueAtTime (
52
+ 0.2 , // sensitivity medium level
53
+ this . context . currentTime
54
+ ) ;
49
55
this . volumeNode = this . context . createGain ( ) ;
50
56
this . volumeNode . connect ( this . muteNode ) ;
51
57
@@ -133,6 +139,14 @@ export class BoardAudio {
133
139
}
134
140
}
135
141
142
+ setSensitivity ( sensitivity : number ) {
143
+ this . sensitivityNode ! . gain . setValueAtTime (
144
+ // check if this is correct
145
+ sensitivity ,
146
+ this . context ! . currentTime
147
+ )
148
+ }
149
+
136
150
setVolume ( volume : number ) {
137
151
this . volumeNode ! . gain . setValueAtTime (
138
152
volume / 255 ,
@@ -195,9 +209,7 @@ export class BoardAudio {
195
209
this . microphoneEl . style . display = "unset"
196
210
197
211
const source = this . context ! . createMediaStreamSource ( micStream ) ;
198
- // TODO: wire up microphone sensitivity to this gain node
199
- const gain = this . context ! . createGain ( ) ;
200
- source . connect ( gain ) ;
212
+ source . connect ( this . sensitivityNode ! ) ;
201
213
// TODO: consider AudioWorklet - worth it? Browser support?
202
214
// consider alternative resampling approaches
203
215
// what sample rates are actually supported this way?
@@ -222,12 +234,12 @@ export class BoardAudio {
222
234
} ) ;
223
235
offlineContext . startRendering ( ) ;
224
236
} ;
225
- gain . connect ( recorder ) ;
237
+ this . sensitivityNode ! . connect ( recorder ) ;
226
238
recorder . connect ( this . context ! . destination ) ;
227
239
228
240
this . stopActiveRecording = ( ) => {
229
241
recorder . disconnect ( ) ;
230
- gain . disconnect ( ) ;
242
+ this . sensitivityNode ! . disconnect ( ) ;
231
243
source . disconnect ( ) ;
232
244
micStream . getTracks ( ) . forEach ( track => track . stop ( ) )
233
245
this . microphoneEl . style . display = "none"
0 commit comments