From 26a4ee42cf69a992ed61188f30a0c1112bf9068d Mon Sep 17 00:00:00 2001 From: Matt Hillsdon Date: Tue, 2 Apr 2024 13:28:18 +0100 Subject: [PATCH] Roughly works Edge cases need checking. Requires a higher AUDIO_CHUNK_SIZE which has other consequences but 4ms is too short. --- src/examples/record.py | 3 --- src/jshal.js | 11 ++++------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/examples/record.py b/src/examples/record.py index c9f20830..1725a7c6 100644 --- a/src/examples/record.py +++ b/src/examples/record.py @@ -1,7 +1,4 @@ from microbit import microphone, audio frame = microphone.record(1000) -print(len(frame)) -for n in range(0, len(frame)): - print(frame[n], end=',') audio.play(frame) \ No newline at end of file diff --git a/src/jshal.js b/src/jshal.js index a0dc29eb..b20fdf97 100644 --- a/src/jshal.js +++ b/src/jshal.js @@ -294,23 +294,20 @@ mergeInto(LibraryManager.library, { /** @type {number} */ cur_len, /** @type {number} */ rate ) { - const cur_len_v = new Uint32Array( - Module.HEAPU8.buffer.slice(cur_len, cur_len + 4) - ); - cur_len_v[0] = 0; + setValue(cur_len, 0, "i32"); Module.board.audio.startRecording( rate, max_len, function (/** @type {Float32Array} */ chunk) { - console.log(cur_len_v[0]); const heap = Module.HEAPU8; - let base = buf + cur_len_v[0]; + let cur_len_v = getValue(cur_len, "i32"); + let base = buf + cur_len_v; const length = Math.max(chunk.length, max_len - cur_len); for (let i = 0; i < length; ++i) { heap[base + i] = (chunk[i] + 1) * 0.5 * 255; } - cur_len_v[0] += length; + setValue(cur_len, cur_len_v + length, "i32"); } ); },