mirror of
https://gitlab.com/80486DX2-66/gists
synced 2025-01-10 08:27:48 +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))
|
writeFileSync(filePath, Buffer.alloc(0))
|
||||||
|
|
||||||
// the loop of sequential file writing, created to ease load on RAM
|
// the loop of sequential file writing, created to ease load on RAM
|
||||||
// (it doesn't work as intended)
|
const max = Math.floor((PRODUCT + (BUFFER_SIZE - 1)) / BUFFER_SIZE),
|
||||||
const max = (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++) {
|
for (let seq = 0; seq < max; seq++) {
|
||||||
let calculatedSize = BUFFER_SIZE
|
if (needTwoBuffers && (t + BUFFER_SIZE) >= PRODUCT) {
|
||||||
if ((t + BUFFER_SIZE) >= PRODUCT)
|
let calculatedSize = PRODUCT - t
|
||||||
calculatedSize = PRODUCT - t
|
audioData = new Uint8Array(calculatedSize)
|
||||||
|
}
|
||||||
let audioData = new Uint8Array(calculatedSize)
|
|
||||||
|
|
||||||
for (let idx = 0; t < PRODUCT && idx < BUFFER_SIZE; idx++, t++) {
|
for (let idx = 0; t < PRODUCT && idx < BUFFER_SIZE; idx++, t++) {
|
||||||
let sample = generateAudio(t * FINAL_SAMPLE_RATE_CONVERSION)
|
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))
|
appendFileSync(filePath, Buffer.from(audioData.buffer))
|
||||||
|
|
||||||
audioData = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
execSync(
|
execSync(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user