1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-10 06:42:02 +05:30

bytebeat-render.js: fix memory usage, fixup for 2e15e4addc

This commit is contained in:
Intel A80486DX2-66 2024-01-31 23:41:49 +03:00
parent 2e15e4addc
commit 33c341f7e8
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -90,15 +90,16 @@ let filePath = generateRandomFilePath()
writeFileSync(filePath, Buffer.alloc(0))
// the loop of sequential file writing, created to ease load on RAM
// (it doesn't work as intended)
const max = (PRODUCT + (BUFFER_SIZE - 1)) / BUFFER_SIZE
const max = Math.floor((PRODUCT + (BUFFER_SIZE - 1)) / BUFFER_SIZE),
needTwoBuffers = max > 1, needSingleBuffer = !needTwoBuffers
let audioData = new Uint8Array(needSingleBuffer ? PRODUCT : BUFFER_SIZE)
for (let seq = 0; seq < max; seq++) {
let calculatedSize = BUFFER_SIZE
if ((t + BUFFER_SIZE) >= PRODUCT)
calculatedSize = PRODUCT - t
let audioData = new Uint8Array(calculatedSize)
if (needTwoBuffers && (t + BUFFER_SIZE) >= PRODUCT) {
let calculatedSize = PRODUCT - t
audioData = new Uint8Array(calculatedSize)
}
for (let idx = 0; t < PRODUCT && idx < BUFFER_SIZE; idx++, t++) {
let sample = generateAudio(t * FINAL_SAMPLE_RATE_CONVERSION)
@ -111,8 +112,6 @@ for (let seq = 0; seq < max; seq++) {
}
appendFileSync(filePath, Buffer.from(audioData.buffer))
audioData = null
}
execSync(