Skip to content

Open source CapCut alternative.

TypeScript

fix(site): silence scan windows ride an integer sample index

David Led404bc192cad
diff --git a/site/src/cut/lib/audioScan.ts b/site/src/cut/lib/audioScan.ts
index 2197b46c..68f67a66 100644
--- a/site/src/cut/lib/audioScan.ts
+++ b/site/src/cut/lib/audioScan.ts
@@ -93,8 +93,11 @@ export async function scanSilence(
for await (const { channels, timestamp, sampleRate } of chunks) {
if (channels.length === 0) continue;
const length = channels[0].length;
+ // Sample times rebuild from an integer sample index, so a chunk split
+ // cannot move a boundary sample across a window by a rounding error.
+ const base = Math.round(timestamp * sampleRate);
for (let i = 0; i < length; i++) {
- const at = timestamp + i / sampleRate;
+ const at = (base + i) / sampleRate;
if (at < from) continue;
if (to !== undefined && at >= to) break;
const window = Math.floor((at - from) / WINDOW);