1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2025-05-31 08:31:41 +05:30

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

This commit is contained in:
2024-01-31 23:41:49 +03:00
parent 2e15e4addc
commit 33c341f7e8

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(