scratch-audio
Advanced tools
Comparing version
{ | ||
"name": "scratch-audio", | ||
"version": "0.1.0-prerelease.1490981488", | ||
"version": "0.1.0-prerelease.1491588270", | ||
"description": "audio engine for scratch 3.0", | ||
@@ -32,3 +32,3 @@ "main": "dist.js", | ||
"soundfont-player": "0.10.5", | ||
"tone": "0.8.0", | ||
"tone": "0.9.0", | ||
"travis-after-all": "1.4.4", | ||
@@ -35,0 +35,0 @@ "webpack": "1.13.2" |
@@ -56,2 +56,6 @@ var log = require('./log'); | ||
this.audioBuffers = {}; | ||
// microphone, for measuring loudness, with a level meter analyzer | ||
this.mic = null; | ||
this.micMeter = null; | ||
} | ||
@@ -157,2 +161,21 @@ | ||
/** | ||
* Get the current loudness of sound received by the microphone. | ||
* Sound is measured in RMS and smoothed. | ||
* @return {number} loudness scaled 0 to 100 | ||
*/ | ||
AudioEngine.prototype.getLoudness = function () { | ||
if (!this.mic) { | ||
this.mic = new Tone.UserMedia(); | ||
this.micMeter = new Tone.Meter('level', 0.5); | ||
this.mic.open(); | ||
this.mic.connect(this.micMeter); | ||
} | ||
if (this.mic && this.mic.state == 'started') { | ||
return this.micMeter.value * 100; | ||
} else { | ||
return -1; | ||
} | ||
}; | ||
/** | ||
* Names of the audio effects. | ||
@@ -159,0 +182,0 @@ * @readonly |
Sorry, the diff of this file is too big to display
1218527
0.96%26016
1.32%