summaryrefslogtreecommitdiff
path: root/index.htm
diff options
context:
space:
mode:
Diffstat (limited to 'index.htm')
-rw-r--r--index.htm66
1 files changed, 30 insertions, 36 deletions
diff --git a/index.htm b/index.htm
index 6624c78..d4729bf 100644
--- a/index.htm
+++ b/index.htm
@@ -26,6 +26,11 @@
let num_samples = output[0][0].length;
let num_frames = num_samples * num_channels;
+ if (num_frames > this.max_num_frames) {
+ console.error("Sound buffer overflow");
+ return true;
+ }
+
let frames = new Float32Array(this.ring);
if (num_frames <= this.max_num_frames - this.position)
@@ -270,51 +275,40 @@
},
p_cleanup : () => {},
p_wait_events_impl : () => { wait_for_events = true; },
- p_sleep_for : (time) => { sleep_duration += time; },
- p_time : Date.now,
+ p_sleep_for_impl : (time) => { sleep_duration += time; },
+ p_time_impl : Date.now,
p_handle_audio_impl : (samples_elapsed) => {
+ if (!sound_ready)
+ return;
+
let num_frames = samples_elapsed * sound_num_channels;
+ if (num_frames > sound_max_num_frames) {
+ console.error("Sound buffer overflow");
+ return;
+ }
+
+ let dst = new Float32Array(sound_shared_ring);
+ let src = new Float32Array(memory.subarray(sound_buffer_address, sound_buffer_address + sound_max_num_frames * 4));
+
if (num_frames <= sound_max_num_frames - sound_position)
- new Uint8Array(
- sound_shared_ring.slice(
- sound_position * 4,
- sound_position * 4 + num_frames * 4
- )
- ).set(
- memory.subarray(
- sound_buffer_address + sound_position * 4,
- sound_buffer_address + sound_position * 4 + num_frames * 4
- )
- );
+ for (let i = 0; i < num_frames; ++i) {
+ dst[sound_position + i] = src[sound_position + i];
+ src[sound_position + i] = 0.0;
+ }
else {
let part_one = sound_max_num_frames - sound_position;
let part_two = num_frames - part_one;
- new Uint8Array(
- sound_shared_ring.slice(
- sound_position * 4,
- sound_position * 4 + part_one * 4
- )
- ).set(
- memory.subarray(
- sound_buffer_address + sound_position * 4,
- sound_buffer_address + sound_position * 4 + part_one * 4
- )
- );
-
- new Uint8Array(
- sound_shared_ring.slice(
- 0,
- part_two * 4
- )
- ).set(
- memory.subarray(
- sound_buffer_address,
- sound_buffer_address + part_two * 4
- )
- );
+ for (let i = 0; i < part_one; ++i) {
+ dst[sound_position + i] = src[sound_position + i];
+ src[sound_position + i] = 0.0;
+ }
+ for (let i = 0; i < part_two; ++i) {
+ dst[i] = src[i];
+ src[i] = 0.0;
+ }
}
sound_position = (sound_position + samples_elapsed * sound_num_channels) % sound_max_num_frames;