Skip to content

Commit

Permalink
Re-do update brstm to 1.4, I'm bad with git
Browse files Browse the repository at this point in the history
  • Loading branch information
rphsoftware committed Dec 18, 2020
2 parents 00bfed6 + 1cb68a1 commit 6f985fc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 396 deletions.
18 changes: 11 additions & 7 deletions dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1811,17 +1811,19 @@ style="stroke:#fff;stroke-width:5;stroke-linejoin:round;fill:#fff;"

// Process bufferSize
let bufferSize = scriptNode.bufferSize;

// If we have to resample, the buffer that we get from the BRSTM will be different size.
bufferSize = capabilities.sampleRate ? bufferSize : getResampledSample(
audioContext.sampleRate,
brstm$1.metadata.sampleRate,
bufferSize
);
let loadBufferSize = bufferSize;

// If we resample, we need to also fetch some extra samples to prevent audio glitches
if (!capabilities.sampleRate) ;
if (!capabilities.sampleRate) {
loadBufferSize += 20;
}

gui.updateState({ready: true, samples: brstm$1.metadata.totalSamples});
gui.updateState({sampleRate: brstm$1.metadata.sampleRate});
Expand Down Expand Up @@ -1872,14 +1874,16 @@ style="stroke:#fff;stroke-width:5;stroke-linejoin:round;fill:#fff;"
playbackCurrentSample,
(brstm$1.metadata.totalSamples - playbackCurrentSample)
);

let endSamplesLength = samples[0].length;

console.log((brstm$1.metadata.totalSamples - playbackCurrentSample), (loadBufferSize - samples[0].length));
console.log((brstm$1.metadata.totalSamples - playbackCurrentSample), (loadBufferSize - endSamplesLength));

// Get enough samples to fully populate the buffer AFTER loop start point
let postLoopSamples = partitionedGetSamples(
brstm$1,
brstm$1.metadata.loopStartSample,
(loadBufferSize - samples[0].length)
(loadBufferSize - endSamplesLength)
);

// For every channel, join the first and second buffers created above
Expand All @@ -1890,8 +1894,8 @@ style="stroke:#fff;stroke-width:5;stroke-linejoin:round;fill:#fff;"
samples[i] = buf;
}

// Set to loopStartPoint + length of second buffer
playbackCurrentSample = brstm$1.metadata.loopStartSample + postLoopSamples[0].length;
// Set to loopStartPoint + length of second buffer (recalculated to not set extra resampling samples)
playbackCurrentSample = brstm$1.metadata.loopStartSample + bufferSize - endSamplesLength;
} else {
// No looping
// Get enough samples until EOF
Expand Down
2 changes: 1 addition & 1 deletion dist/bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
}
</script>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"build": "rollup --config rollup.config.js"
},
"dependencies": {
"brstm": "^1.3.3"
"brstm": "^1.4.0"
}
}
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ async function startPlaying(url) { // Entry point to the

// Process bufferSize
let bufferSize = scriptNode.bufferSize;

// If we have to resample, the buffer that we get from the BRSTM will be different size.
bufferSize = capabilities.sampleRate ? bufferSize : getResampledSample(
audioContext.sampleRate,
Expand Down
Loading

0 comments on commit 6f985fc

Please sign in to comment.