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:
parent
2e15e4addc
commit
33c341f7e8
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user