fix(flac): add FLAC frame-sync scan to getAlignedSegmentSize; extend IFormatDecoder rawData param

StreamDecoder peeks candidate bytes; FlacFormatDecoder scans backward for 0xFF/0xF8 sync. Fixes mid-stream decode failure where segments started mid-frame.
This commit is contained in:
daniel-c-harvey
2026-06-11 09:08:33 -04:00
parent c4930e80ba
commit 879c30a5e5
3 changed files with 55 additions and 13 deletions
@@ -73,12 +73,18 @@ export interface IFormatDecoder {
* @param availableBytes - bytes available starting at the current processedBytes position
* @param requestedSize - maximum desired segment size
* @param streamComplete - true when the stream has ended (allows draining the tail)
* @param rawData - optional; the first `Math.min(requestedSize, availableBytes)` raw audio
* bytes (starting at the current processedBytes position in the stream), made available
* for format-specific frame-sync scanning. WAV and MP3 decoders ignore this parameter;
* FLAC and similar variable-frame formats use it to find the last clean frame boundary
* within the candidate window.
*/
getAlignedSegmentSize(
info: FormatInfo,
availableBytes: number,
requestedSize: number,
streamComplete: boolean
streamComplete: boolean,
rawData?: Uint8Array
): number;
/**