@@ -22,6 +22,7 @@ export class BoardAudio {
2222 private oscillator : OscillatorNode | undefined ;
2323 private volumeNode : GainNode | undefined ;
2424 private muteNode : GainNode | undefined ;
25+ private sensitivityNode : GainNode | undefined ;
2526
2627 default : BufferedAudio | undefined ;
2728 speech : BufferedAudio | undefined ;
@@ -46,6 +47,11 @@ export class BoardAudio {
4647 this . context . currentTime
4748 ) ;
4849 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+ ) ;
4955 this . volumeNode = this . context . createGain ( ) ;
5056 this . volumeNode . connect ( this . muteNode ) ;
5157
@@ -133,6 +139,14 @@ export class BoardAudio {
133139 }
134140 }
135141
142+ setSensitivity ( sensitivity : number ) {
143+ this . sensitivityNode ! . gain . setValueAtTime (
144+ // check if this is correct
145+ sensitivity ,
146+ this . context ! . currentTime
147+ )
148+ }
149+
136150 setVolume ( volume : number ) {
137151 this . volumeNode ! . gain . setValueAtTime (
138152 volume / 255 ,
@@ -195,9 +209,7 @@ export class BoardAudio {
195209 this . microphoneEl . style . display = "unset"
196210
197211 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 ! ) ;
201213 // TODO: consider AudioWorklet - worth it? Browser support?
202214 // consider alternative resampling approaches
203215 // what sample rates are actually supported this way?
@@ -222,12 +234,12 @@ export class BoardAudio {
222234 } ) ;
223235 offlineContext . startRendering ( ) ;
224236 } ;
225- gain . connect ( recorder ) ;
237+ this . sensitivityNode ! . connect ( recorder ) ;
226238 recorder . connect ( this . context ! . destination ) ;
227239
228240 this . stopActiveRecording = ( ) => {
229241 recorder . disconnect ( ) ;
230- gain . disconnect ( ) ;
242+ this . sensitivityNode ! . disconnect ( ) ;
231243 source . disconnect ( ) ;
232244 micStream . getTracks ( ) . forEach ( track => track . stop ( ) )
233245 this . microphoneEl . style . display = "none"
0 commit comments