Repository navigation
feat: add FLAC as a Stream-to-Stream ConvertFile/CutFile destination - #122
Merged
Merged
Conversation
FlacEncoder.OpenSession gained a Stream-based overload, mirroring WavWriter/ AiffWriter/AuWriter's own Create(Stream, ...) overloads but genuinely requiring CanSeek (unlike those three): FlacEncoderSession.Finish() seeks back to patch STREAMINFO's provisional totalSamples/MD5/block-size-range fields once the real values are known, so a non-seekable destination throws ArgumentException up front instead of failing confusingly mid-Finish(). FlacEncoderSession's own destination field was widened from FileStream to Stream plus a leaveOpen flag (mirroring WavWriter's own convention) so Dispose() only closes a stream this type actually owns. Channel/bits-per- sample/tag validation was factored into a shared private helper so the path-based and Stream-based OpenSession overloads can't drift apart. Wired into AudioCutter.Stream.cs's OpenSinkStream as the AudioFormat.Flac destination case -- no DeferredFixedHeaderSink needed, since FlacEncoder already patches its header after the fact rather than needing an exact frame count up front. Fixed two pre-existing tests that used AudioFormat.Flac as their "still unsupported" example destination format, now stale. Also fixed a stale doc comment/CLAUDE.md note that had drifted out of sync with the codebase (still said "WAV only" for the Stream destination set, when AIFF/AU had already landed). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ion mid-stream after Finish() Self-review finding: unlike WavWriter/AiffWriter/AuWriter's own Stream-based destinations (which never seek back), FlacEncoderSession.Finish()'s STREAMINFO patch-seek leaves the caller's stream Position shortly after the start of the stream, not at the true end. Length is unaffected and still correct. Documented on the new overload so a caller doesn't get surprised relying on Position to mean "how much was written". 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/feature-roadmap.mditem 1's own "destination-Stream" half, which the owner's own cron instructions called out by name as an example next step. WAV/AIFF/AU were already done (none of the three needStream.CanSeek); FLAC is the first destination here that genuinely does.FlacEncoder.OpenSession(Stream destStream, ...)-- a new overload, mirroringWavWriter/AiffWriter/AuWriter's ownCreate(Stream, ...)overloads. RequiresdestStream.CanSeek(throwsArgumentExceptionup front if not) becauseFlacEncoderSession.Finish()still seeks back to a fixed byte offset to patch STREAMINFO's provisionaltotalSamples/MD5/block-size-range fields once their real values are known -- exactly the way the path-based overload's ownFileStreamdestination already does. Does not dispose the caller's stream.FlacEncoderSession's own destination field was widened fromFileStreamtoStream, plus aleaveOpenflag (mirroringWavWriter's own_leaveOpenconvention) soDispose()only closes a stream this type actually owns.OpenSessioninto a shared private helper (ValidateAndGetCommentListBytes) so the two overloads can never drift apart on what's a valid request.AudioCutter.Stream.cs'sOpenSinkStreamas theAudioFormat.Flaccase -- unlike WAV/AIFF/AU, noDeferredFixedHeaderSinkwrapper is needed at all, since FLAC's own header-patch-after-the-fact design never needed an exact frame count up front in the first place (matching the existing path-basedAudioCutter.csdispatch for.flac, which already callsFlacEncoder.OpenSessiondirectly with no such wrapper).NativeEncoderTest.ConvertFile_Stream_WithUnsupportedDestFormat_Should_ThrowandAudioCutterStreamTest.Convert_Stream_WithUnsupportedDestFormat_Should_Throwboth usedAudioFormat.Flacas their "still unsupported" example destination -- now true, so both were switched toAudioFormat.Wma(still genuinely unsupported as a destination).CLAUDE.md's ownAudioCutter.Stream.csrow still said "Destination: WAV only so far", which had already drifted out of sync with reality once AIFF/AU landed in an earlier PR; corrected while updating the same line for FLAC.CLAUDE.md,README.md,llms.txt,llms-full.txt,docs/feature-roadmap.mditem 1's own status note.Test plan
FlacEncoderTestcases: null stream, non-seekable stream (throws with "seekable" in the message), zero channels, bits-per-sample out of range (0/33), invalid tag field name (throws before a single byte reaches the caller's stream), exact round-trip via aMemoryStreamdestination, andDispose()not disposing the caller's stream.AudioCutterStreamTestcases: WAV source → FLACStreamdestination round-trip (exact samples), non-seekable FLAC destination throws through the fullAudioCutter.Convertcall, and aResamplingTransformpipeline into a FLACStreamdestination writes the correct total frame count.NonSeekableWriteStream(the write-side counterpart to the existingNonSeekableStream).dotnet test, net10.0 locally): 1729 passed (1718 baseline + 11 new), 1 pre-existing unrelated skip, 0 failed.🤖 Generated with Claude Code