Skip to content

Commit

Permalink
fix a bug with mismatched buffer lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
iliazeus committed Oct 12, 2024
1 parent 36d8eee commit dae7172
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,15 @@ 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;
if (channelStartOffset > totalStartOffset) totalStartOffset = channelStartOffset;
}

const audioContext = new wa.OfflineAudioContext({
length: totalSampleCount,
length: totalStartOffset + totalSampleCount,
sampleRate: 44100,
numberOfChannels: 2,
});
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dae7172

Please sign in to comment.