-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flac: add Encoder API to encode audio samples and metadata blocks #32
Conversation
encode_meta.go
Outdated
// --- [ Padding ] ------------------------------------------------------------- | ||
|
||
// encodePadding encodes the Padding metadata block, writing to bw. | ||
func encodePadding(bw bitio.Writer, length int64, last bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encodePadding
is unused
Encode has been removed in favour of using NewEncoder. The Encode function was temporarily added to support re-encoding FLAC streams to update the metadata, but it had no support for encoding audio samples. The added flac.Encoder has support for encoding both metadata and audio samples. It also does not require that you first decode a FLAC file to later re-encode it by calling Encode (as was the previous behaviour).
Reported by golangci
frame/utf8.go:57:6: `decodeUTF8Int` is unused (deadcode) func decodeUTF8Int(r io.Reader) (n uint64, err error) { ^ internal/utf8/encode.go:32:16: unnecessary conversion (unconvert) bits = uint64(t2 | (x>>6)&mask2) ^ internal/utf8/encode.go:37:16: unnecessary conversion (unconvert) bits = uint64(t3 | (x>>(6*2))&mask3) ^ internal/utf8/encode.go:42:16: unnecessary conversion (unconvert) bits = uint64(t4 | (x>>(6*3))&mask4) ^
encode_frame.go:89:1: cyclomatic complexity 52 of func `(*Encoder).encodeFrameHeader` is high (> 30) (gocyclo) func (enc *Encoder) encodeFrameHeader(w io.Writer, hdr frame.Header) error { ^ internal/utf8/encode.go:66:17: unnecessary conversion (unconvert) bits := uint64(tx | (x>>uint(6*i))&maskx) ^ encode_subframe.go:105:46: unnecessary conversion (unconvert) if err := bw.WriteBits(uint64(sample), byte(hdr.BitsPerSample)); err != nil { ^
For the LPC stuff, just wanted to note and zc lpc So one possible way to approach flac LPC (the fixed LPC shouldn't require this BTW) would be If that is of interest to you, I'm happy to collaborate. |
Thanks for the writeup William! That information will definitely be useful for implementing LPC encoding in the future. When this future arrives depends on when there will be a good time slot to do some hobby hacking on this. For now, I'm quite involved with courses at Uni so will be some time till next long hack session on the flac lib. That being said, if you are eager to get started, feel free and my brother and I will do our best to get you up to speed with the code base. |
This change adds enc.go, which was removed in #32. To fix the build, a single change is made to enc.go, namely, updating the type of bw in the encoder struct from bitio.Writer to *bitio.Writer. Note: encoding metadata with mewkiz/flac is unsupported (for now), so maintenance of the metadata encoding feature will be governed by the Go community at large, when such need arrise. Furthermore, the metadata encoding as implemented by enc.go has not been tested locally. It is quite possible that is has broken, but if not, feel free to use! To use FLAC metadta encoding, pin the "unsupported-metadata-encoding" branch of mewkiz/flac in your go.mod. ref: #40 (comment)
This pull request deprecates the
flac.Encode
API which is now superseded byflac.NewEncoder
. The rationale is explained in ca2e405:This PR adds support for Verbatim encoding of audio samples. Future pull requests can implement the remaining prediction methods for audio sample encoding (e.g. LPC).
Fixes #15.