Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/lib/free-queue/free-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
// Byte per audio sample. (32 bit float)
const BYTES_PER_SAMPLE = Float32Array.BYTES_PER_ELEMENT;

// Basic byte unit of WASM heap. (16 bit = 2 bytes)
const BYTES_PER_UNIT = Uint16Array.BYTES_PER_ELEMENT;

// The max audio channel on Chrome is 32.
const MAX_CHANNEL_COUNT = 32;

Expand Down Expand Up @@ -80,11 +77,11 @@ class FreeQueue {
for (let i = 0; i < this._channelCount; ++i) {
const startByteOffset = this._dataPtr + i * channelByteSize;
const endByteOffset = startByteOffset + channelByteSize;
// Get the actual array index by dividing the byte offset by 2 bytes.
// Get the actual array index by dividing the byte offset by 4, the size of float. (right shift >> 2 === dividing by 4)
this._channelData[i] =
this._module.HEAPF32.subarray(
startByteOffset >> BYTES_PER_UNIT,
endByteOffset >> BYTES_PER_UNIT);
startByteOffset >> 2,
endByteOffset >> 2);
Comment on lines +83 to +84
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For even more clarity, what do you think about either of these options?

  1. Make the 2 a named constant like FLOAT32_INDEX_SHIFT

or

  1. Use division by BYTES_PER_SAMPLE along with Math.floor()

}
}

Expand Down Expand Up @@ -249,4 +246,4 @@ export {
MAX_CHANNEL_COUNT,
RENDER_QUANTUM_FRAMES,
FreeQueue
};
};