File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change 2525 * THE SOFTWARE.
2626 */
2727
28+ #include <math.h>
2829#include "py/mphal.h"
2930#include "drv_system.h"
3031#include "modaudio.h"
@@ -134,7 +135,7 @@ static void audio_data_fetcher(void) {
134135 // Compute the sound level.
135136 sound_level += (src [i ] - 128 ) * (src [i ] - 128 );
136137 }
137- audio_current_sound_level = sound_level / AUDIO_CHUNK_SIZE / AUDIO_CHUNK_SIZE ;
138+ audio_current_sound_level = sound_level / AUDIO_CHUNK_SIZE ;
138139
139140 audio_buffer_ready ();
140141}
@@ -277,8 +278,10 @@ mp_obj_t is_playing(void) {
277278}
278279MP_DEFINE_CONST_FUN_OBJ_0 (microbit_audio_is_playing_obj , is_playing );
279280
281+ // Returns a number between 0 and 254, being the average intensity of the sound played
282+ // from the most recent chunk of data.
280283static mp_obj_t microbit_audio_sound_level (void ) {
281- return MP_OBJ_NEW_SMALL_INT (audio_current_sound_level );
284+ return MP_OBJ_NEW_SMALL_INT (2 * sqrt ( audio_current_sound_level ) );
282285}
283286static MP_DEFINE_CONST_FUN_OBJ_0 (microbit_audio_sound_level_obj , microbit_audio_sound_level ) ;
284287
You can’t perform that action at this time.
0 commit comments