Repository navigation
feat: add FLAC streaming encoder, completing item 8 - #121
Merged
Merged
Conversation
Implements the FLAC sub-item of docs/streaming-plan.md item 8 (the last of its three codec sub-items, now that the pattern has been proven three times over for AAC/Opus/MP3): FlacStreamingEncoder is the fourth IStreamingEncoder implementation, reusing FlacFrameEncoder's own encode internals unchanged. Genuinely simpler than the other three, for two real codec-level reasons rather than a shortcut: this encoder's own FIXED predictors are purely causal (never look at future samples), so there is no encoder lookahead to drain at all (EncoderDelaySamples is always 0); and FLAC's own frame format natively allows a final block shorter than the nominal size with no padding, unlike AAC-LC/Opus/MP3's own fixed-or-padded frame sizes. Complete() therefore just flushes whatever's left pending, nothing more. Genuinely not independently decodable, unlike the other three: FlacFrameEncoder's own existing frame header always defers sample-rate and bits-per-sample to STREAMINFO (a pre-existing characteristic of this project's frame encoder, not introduced here) rather than using FLAC's own available explicit escape codes. Building a STREAMINFO (a whole-stream, container-level concept) is out of scope for this raw packet-level encoder, the same boundary every other IStreamingEncoder already draws. Widened FlacEncoderSession.WriteStreamInfoPayload from private to internal (zero behavior change, confirmed by the full existing FlacEncoderTest suite still passing unchanged) so this item's own conformance tests can build a real STREAMINFO out-of-band and reuse that exact bit layout rather than duplicating it. Conformance verifies EXACT sample equality after a full decode, not an SNR floor -- the same bar every lossless codec in this project is already held to, unlike the lossy AAC/Opus/MP3 sub-items. This completes docs/streaming-plan.md item 8 in full. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docs/streaming-plan.mditem 8 — the last of its three codec sub-items, now that the pattern has been proven three times over for AAC/Opus/MP3 (PRs feat: add push-style IStreamingEncoder + AAC-LC streaming session #110, feat: add Opus streaming encoder (item 8's Opus sub-item) #118, feat: add MP3 streaming encoder (item 8's MP3 sub-item) #120).FlacStreamingEncoderis the fourthIStreamingEncoderimplementation, reusingFlacFrameEncoder's own encode internals unchanged.EncoderDelaySamplesis always0); and FLAC's own frame format natively allows a final block shorter than the nominal size with no padding, unlike AAC-LC/Opus/MP3's own fixed-or-padded frame sizes.Complete()therefore just flushes whatever's left pending, nothing more.FlacFrameEncoder's own existing frame header always defers sample-rate and bits-per-sample to STREAMINFO (a pre-existing characteristic of this project's frame encoder, not introduced here) rather than using FLAC's own available explicit escape codes. Building a STREAMINFO (a whole-stream, container-level concept: total duration, a whole-stream MD5, min/max block size) is out of scope for this raw packet-level encoder, the same boundary every otherIStreamingEncoderalready draws.FlacEncoderSession.WriteStreamInfoPayloadfromprivatetointernal(zero behavior change, confirmed by the full existingFlacEncoderTestsuite still passing unchanged) so this item's own conformance tests can build a real STREAMINFO out-of-band and reuse that exact bit layout rather than duplicating it.FlacDecoder), not an SNR floor — the same bar every lossless codec in this project is already held to, unlike the lossy AAC/Opus/MP3 sub-items.docs/streaming-plan.mditem 8 in full.docs/streaming-plan.md(FLAC sub-item + item 8 overall both marked done),CLAUDE.md,README.md,llms.txt,llms-full.txt.Test plan
FlacStreamingEncoderTest: construction validation (null callback, zero channels, out-of-range bits-per-sample both directions),SamplesPerFrame == 4096,Complete()with zero samples emits nothing, idempotentComplete()/safe doubleDispose(),WriteafterComplete()throws, monotonic frame indices, exact short-final-block sample count with no padding, the "exactly one full block, nothing else emitted" edge case (no lookahead to drain, unlike Opus/MP3), and exact (not SNR-based) round-trip for mono and stereo via a real decoded FLAC file built from the streaming encoder's raw frames plus an out-of-band STREAMINFO.dotnet test, net10.0 locally): 1718 passed, 1 pre-existing unrelated skip, 0 failed.🤖 Generated with Claude Code