Commit graph

55 commits

Author SHA1 Message Date
DataHoarder 42f940f815
Update module url 2022-07-26 16:14:37 +02:00
Robin Eklind 3e3f4b5fcf
flac: add Encoder API to encode audio samples and metadata blocks (#32)
* flac: encode frame header

* flac: calculate CRC-8 when encoding frame headers

* flac: fix encoding of frame header

* flac: add preliminary subframe encoder

* flac: fix UTF-8 encoding of frame number

* frame: add sanity check for sample count in decodeLPC

Updates #31.

* flac: update flac encoding API, depricate flac.Encode

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).

* flac: add MD5 running hash of unencoded audio samples to StreamInfo

* flac: remove unused encodePadding

Reported by golangci

* flac: fix golangci lint issues

	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)
							 ^

* flac: fix golangci lint issues

	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 {
																	 ^

* flac: clarify that frame.Header.Num is calculated by the encoder

* flac: minor re-phrasing
2018-08-19 03:18:12 +09:00
mewmew 46e9cd6b14 frame: simplify parseHeader by refactoring
Fixes lint issue reported by gocyclo:

frame/frame.go:212:1: cyclomatic complexity 52 of func `(*Frame).parseHeader` is high (> 30) (gocyclo)
func (frame *Frame) parseHeader() error {
^

Updates #25.
2018-05-27 15:10:15 +02:00
Henry Eklind 0dc1119122
denser error handling 2016-07-22 00:56:37 +02:00
mewmew 3f1d1096d8 internal: Add bits and hashutil packages to make the flac package self-contained. 2016-04-05 02:40:46 +02:00
mewmew 9970b89a55 flac: Drop use of gopkg.in in import paths. Rely on vendoring instead.
ref: azul3d/engine#1
2016-03-07 00:06:54 +01:00
mewmew aadf80aa28 frame: Extend test cases to increase code coverage.
Test a corpus of 585 public domain FLAC files with a duration of less than 1 minute from freesound.org.

Out of these files, the following increased code coverage and where thus added to the test suit.

* 19875 (sample rate 48 kHz)
* 44127 (8 bits-per-sample, sample rate 22254)
* 80574 (sample rate 22050)
* 191885 (block size 1, verbatim)
* 212768 (sample rate 88200)
* 220014 (utf-8 continuation byte)
* 243749 (sample rate 8000)
* 257344 (sample rate 32000)
* 256529 (sample rate 192000)
2016-02-11 04:12:51 +01:00
mewmew 154b8f6f7f frame: Fix decoding of FLAC files with wasted bits-per-sample.
Fixes issue #12.
2016-02-02 14:51:37 +01:00
mewmew bd85ea13e2 frame: Implement decoding samples with wasted bits-per-sample. 2016-01-20 19:36:23 +01:00
mewmew 8a188c6be0 frame: Treat negative shifts as errors.
Because Josh didn't have complete understanding of LPC analysis back in < 2006 many developers over the years have disputed over negative shifts. Should the switch direction? Should the roll around? Nobody knows. Not even Josh.

The answer finally came to us when Josh stepped forward and told us the truth.

What else has Josh put us through? Is fLaC a lie?

http://lists.xiph.org/pipermail/flac-dev/2006-December/002030.html

- Karlek
2016-01-20 19:25:22 +01:00
mewmew c1a3f64314 frame: Implement Rice partition Escape code decoding. 2016-01-20 19:07:17 +01:00
mewmew a81eb2312c frame: Add function name prefix to error messages. 2015-09-17 13:00:51 +02:00
Patrick Mezard 91b22b5748 subframe: turn panics into errors
I believe panics should be reserved to internal invariant violations or
irrecoverable errors, not invalid user inputs. Also, they are triggered
by go-fuzz, removing them helps testing the package.
2015-09-17 09:29:38 +02:00
Robin Eklind f2604cc85b Merge pull request #7 from perotinus/master
Fix two bugs with subframe decoding
2015-01-30 01:20:56 +01:00
mewmew 6e68e06c25 frame: Remove the bit reader field from the SubFrame structure. This change will facilitate future test cases by allowing the use of reflect.DeepEqual on subframes. 2015-01-30 01:18:22 +01:00
J. MacMillan 5d83ffb7bf Fix two bugs in the FLAC library:
- the linear predictive coding has an overflow error -- with FIR-encoded frames, this often causes the output signal to be noise rather than what it should be. Type-converting to int64 to do the summation, then back to int32 after shifting fixed this for the files that I tested against.
- the check if the Rice parameter was the escape code did not handle the 5-bit escape code -- it checked for 0x1f and a 4-bit-long code instead of a 5-bit-long one

I don't have any FLAC files that test the latter issue; I have a number of FLAC files that caused the former, all of which have
2015-01-03 22:51:44 -05:00
mewmew 50ad5a4321 flac: Use versioned imports. 2014-09-30 02:24:15 +02:00
mewmew 654f26264a frame: Return io.ErrUnexpectedEOF if EOF occurs in the middle of an audio frame. 2014-08-08 05:33:21 +02:00
mewmew 0bfe584626 frame: Add a brief introduction of the FLAC audio format and describe the various prediction methods. 2014-08-08 01:04:38 +02:00
mewmew 4a7d57d6cd frame: Implement FIR linear prediction decoding. This is the last piece of the new frame API. Updates issue #4. 2014-08-07 02:55:15 +02:00
mewmew b30021351f frame: Reuse existing bit reader. 2014-08-07 02:18:12 +02:00
mewmew 23da211707 frame: Implement LPC decoding. 2014-08-07 02:10:14 +02:00
mewmew d6ed5eeb52 frame: Implement decoding of Rice encoded residuals. 2014-08-07 00:43:16 +02:00
mewmew e1936fb870 frame: Implement decoding of residuals encoded using the fixed prediction method. 2014-08-07 00:25:43 +02:00
mewmew 4eab65d99b frame: Implement inter-channel correlation and decoding of constant and verbatim subframes. 2014-08-06 23:19:33 +02:00
mewmew 5743fb0574 frame: Implement subframe header parsing. 2014-08-06 20:29:06 +02:00
mewmew c8442ce5b6 frame: Add Parse and remove Frame.Next. Stub out a few functions. 2014-08-06 18:49:18 +02:00
mewmew 923cdff51a frame: Add Header, Channels, SubHeader and Pred definitions. This was the last piece of the new frame API. Updates issue #4. 2014-08-06 04:24:36 +02:00
mewmew 7e1f8d2b03 frame: Initial version of the new frame API. Updates issue #4. 2014-08-06 03:08:32 +02:00
mewmew 51d342ff4b flac: Clean start in preparation for the new API. All functionality will be back ported later on. 2014-08-05 21:51:52 +02:00
mewmew 6d8d6f28a4 frame: Implement rice2 decoding. 2014-08-03 15:59:00 +02:00
mewmew a5595f088c flac: Add license notice for eaburns/flac code segments. 2014-08-03 15:26:35 +02:00
mewmew 060f13b6f9 frame: Make use of mewkiz/pkg/bit instead of eaburns/bit.
The real time it takes to decode a 32 MB flac file is on average 5.5% less.
2014-08-03 14:57:12 +02:00
mewmew f911f2e145 frame: Speed optimization. 2014-08-03 01:16:49 +02:00
mewmew b7742ffb7c frame: Toggle debug output. 2014-08-02 22:34:12 +02:00
mewmew d1efb29881 frame: Interchannel decorrelation (part 1). 2014-08-02 21:43:13 +02:00
mewmew 7a54bca667 frame: Implement DecodeLPC. 2014-08-01 03:58:35 +02:00
mewmew 916e9cfc9b frame: Update comments. 2014-08-01 03:16:39 +02:00
mewmew 8c3f6695f3 frame: Fix riceDecode implementation. 2014-08-01 02:53:13 +02:00
mewmew d066f2f029 frame: Initial implementation of lpcDecode. 2014-07-31 17:41:10 +02:00
mewmew b8cceb5fc6 frame: Reimplement riceDecode. 2014-07-31 16:49:27 +02:00
mewmew 79e02a43a5 frame: Initial implementation of rice decoding; making it possible to decode residuals :) 2014-07-31 04:53:26 +02:00
mewmew 5057601481 frame: Update TODO comments. 2014-07-31 03:05:39 +02:00
mewmew af4e6cbd90 frame: Implement parsing of rice parameters which uses the escape code. 2013-12-02 23:20:32 +01:00
mewmew 7a122b13ac frame: Use bitutil.DecodeUnary and pre-allocate samples instead of using append. 2013-11-18 17:33:29 +01:00
mewmew 8443fd2cce frame: Add some comments and panic on unreachable branches. 2013-11-16 17:59:43 +01:00
mewmew dfd18aa2cb frame: Refactor to make use of github.com/eaburns/bit and hash readers. 2013-11-16 14:57:18 +01:00
mewmew c4e2b604f7 go fmt * 2013-11-03 22:19:15 +01:00
mewmew f583bf6928 all: Fix issues located by golint.
- "error strings should not end with punctuation"
2013-10-29 14:45:05 +01:00
mewmew 1a2f006677 Rename the package from rsf to flac. A command can later use the rsf name. 2013-06-07 03:23:23 +02:00