Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Sentry.init({
// Enable Logs
enableLogs: true,

// Collect Android tombstones for richer native crash context
enableTombstone: true,

// Configure Session Replay
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1,
Expand Down
32 changes: 22 additions & 10 deletions src/hooks/useVoiceMirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,33 @@ export function useVoiceMirror(
onRecordingComplete(filePath, durationMs);
}

const bufferedFrames = bufferedFramesRef.current;
// Snapshot chunks and compute actual size to avoid any mismatch between
// bufferedFramesRef and real chunk data (native copyToChannel has no bounds
// checking and will segfault on overflow).
const chunks = chunksRef.current;
const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);
if (totalLength === 0) {
await startMonitoring();
return;
}
const merged = new Float32Array(totalLength);
let pos = 0;
for (const chunk of chunks) {
merged.set(chunk, pos);
pos += chunk.length;
}
const audioBuffer = context.createBuffer(
1,
bufferedFrames,
totalLength,
context.sampleRate,
);
let offset = 0;
for (const chunk of chunksRef.current) {
audioBuffer.copyToChannel(chunk, 0, offset);
offset += chunk.length;
}
audioBuffer.copyToChannel(merged, 0, 0);

const bufferStartFrame = totalFramesRef.current - bufferedFramesRef.current;
const voiceStartSecs =
(voiceStartFrameRef.current - bufferStartFrame) / context.sampleRate;
const bufferStartFrame = totalFramesRef.current - totalLength;
const voiceStartSecs = Math.max(
0,
(voiceStartFrameRef.current - bufferStartFrame) / context.sampleRate,
);

const playerNode = context.createBufferSource();
playerNodeRef.current = playerNode;
Expand Down
Loading