mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2024-12-22 22:12:48 -05:00
Explain loudness scaling, and clamp to 100
This commit is contained in:
parent
5add85bd60
commit
dd0d9556ed
1 changed files with 7 additions and 4 deletions
11
src/index.js
11
src/index.js
|
@ -321,11 +321,14 @@ class AudioEngine {
|
|||
}
|
||||
this._lastValue = rms;
|
||||
|
||||
// scale it
|
||||
// @todo figure out why this magic number is needed and remove it!
|
||||
// Scale the measurement so it's more sensitive to quieter sounds
|
||||
rms *= 1.63;
|
||||
// scale and round the output
|
||||
return Math.round(Math.sqrt(rms) * 100);
|
||||
rms = Math.sqrt(rms);
|
||||
// Scale it up to 0-100 and round
|
||||
rms = Math.round(rms * 100);
|
||||
// Prevent it from going above 100
|
||||
rms = Math.min(rms, 100);
|
||||
return rms;
|
||||
}
|
||||
|
||||
// if there is no microphone input, return -1
|
||||
|
|
Loading…
Reference in a new issue