Skip to content

feat: add FLAC streaming encoder, completing item 8 - #121

Merged
cloud-hai-vo merged 2 commits into
mainfrom
feat/flac-streaming-encoder
Oct 17, 2026
Merged

cloud-hai-vo merged 2 commits into
mainfrom
feat/flac-streaming-encoder

Conversation

@cloud-hai-vo

Copy link
Copy Markdown
Contributor

Summary

  • 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 (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). 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, not 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: total duration, a whole-stream MD5, min/max block size) 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 (via the project's own 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.
  • This completes docs/streaming-plan.md item 8 in full.
  • Docs synced: docs/streaming-plan.md (FLAC sub-item + item 8 overall both marked done), CLAUDE.md, README.md, llms.txt, llms-full.txt.

Test plan

  • New FlacStreamingEncoderTest: construction validation (null callback, zero channels, out-of-range bits-per-sample both directions), SamplesPerFrame == 4096, Complete() with zero samples emits nothing, idempotent Complete()/safe double Dispose(), Write after Complete() 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.
  • Full existing suite (dotnet test, net10.0 locally): 1718 passed, 1 pre-existing unrelated skip, 0 failed.
  • Full solution build (all target frameworks + AotSmokeTest): 0 warnings/errors.

🤖 Generated with Claude Code

cloud-hai-vo and others added 2 commits October 17, 2026 18:08
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>
@cloud-hai-vo
cloud-hai-vo merged commit 9b3dba4 into main Oct 17, 2026
9 checks passed
@cloud-hai-vo
cloud-hai-vo deleted the feat/flac-streaming-encoder branch October 17, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant