Skip to content
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

Merged
merged 13 commits into from
Aug 18, 2018

Conversation

mewmew
Copy link
Member

@mewmew mewmew commented Aug 18, 2018

This pull request deprecates the flac.Encode API which is now superseded by flac.NewEncoder. The rationale is explained in ca2e405:

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 (see #14), 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).

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.

encode_meta.go Outdated
// --- [ Padding ] -------------------------------------------------------------

// encodePadding encodes the Padding metadata block, writing to bw.
func encodePadding(bw bitio.Writer, length int64, last bool) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encodePadding is unused

@mewmew mewmew merged commit 3e3f4b5 into mewkiz:master Aug 18, 2018
mewmew added 13 commits August 20, 2018 01:51
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).
	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 {
																	 ^
@wsc1
Copy link

wsc1 commented Sep 12, 2018

For the LPC stuff, just wanted to note
this mail

this chapter

and zc lpc

So one possible way to approach flac LPC (the fixed LPC shouldn't require this BTW) would be
to extend zc/lpc to use line spectral pairs, expose the parcor coefficients, and work with some of the quantisation methods in the chapter.

If that is of interest to you, I'm happy to collaborate.

@mewmew
Copy link
Member Author

mewmew commented Sep 13, 2018

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.

Cheers,
@karlek and @mewmew

mewmew added a commit that referenced this pull request Dec 13, 2021
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)
@wader wader mentioned this pull request Dec 27, 2023
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.

3 participants