From dae71723defca5c6313142fa9d5ed17324f00dd1 Mon Sep 17 00:00:00 2001 From: Ilia Pozdnyakov Date: Sat, 12 Oct 2024 17:45:30 +0500 Subject: [PATCH] fix a bug with mismatched buffer lengths --- package-lock.json | 4 ++-- package.json | 2 +- src/index.ts | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index a8d3e90..a624910 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "punkomatic", - "version": "0.5.3", + "version": "0.5.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "punkomatic", - "version": "0.5.3", + "version": "0.5.4", "license": "MIT", "devDependencies": { "@types/node": "^20.11.30", diff --git a/package.json b/package.json index 66cbc79..58905a9 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "node": "./dist/punkomatic.node.js", "browser": "./dist/punkomatic.browser.js" }, - "version": "0.5.3", + "version": "0.5.4", "description": "a tool to parse and render Punk-O-Matic 2 song data", "scripts": { "build": "./scripts/build.sh", diff --git a/src/index.ts b/src/index.ts index eb7ac0b..7b50e23 100644 --- a/src/index.ts +++ b/src/index.ts @@ -168,8 +168,7 @@ export async function renderSong( totalEventCount += events.length; - const channelSampleCount = - events.at(-1)!.endTime + events.at(-1)!.release - events.at(0)!.startTime; + const channelSampleCount = events.at(-1)!.endTime + events.at(-1)!.release; if (channelSampleCount > totalSampleCount) totalSampleCount = channelSampleCount; const channelStartOffset = events[0].startTime < 0 ? Math.abs(events[0].startTime) : 0; @@ -177,7 +176,7 @@ export async function renderSong( } const audioContext = new wa.OfflineAudioContext({ - length: totalSampleCount, + length: totalStartOffset + totalSampleCount, sampleRate: 44100, numberOfChannels: 2, }); @@ -232,7 +231,7 @@ export async function renderSong( .getChannelData(c) .subarray( totalStartOffset + event.startTime, - totalStartOffset + event.endTime + event.release, + totalStartOffset + event.startTime + src.length, ); dst.set(src);