Skip to content

Commit

Permalink
Roughly works
Browse files Browse the repository at this point in the history
Edge cases need checking. Requires a higher AUDIO_CHUNK_SIZE which has
other consequences but 4ms is too short.
  • Loading branch information
microbit-matt-hillsdon committed Apr 2, 2024
1 parent 8eb6fa7 commit 26a4ee4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
3 changes: 0 additions & 3 deletions src/examples/record.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 4 additions & 7 deletions src/jshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
);
},
Expand Down

0 comments on commit 26a4ee4

Please sign in to comment.