Commit graph

94 commits

Author SHA1 Message Date
DataHoarder 42f940f815
Update module url 2022-07-26 16:14:37 +02:00
Henry Eklind 11466d8af8
Absolute seek (#46)
* frame: Add frame.SampleNumber()

* flac/seek: Make stream.Seek seek to absolute sample numbers

* seek/test: Update test case for absolute seeking

* Update flac.go

Co-authored-by: Robin <mewmew@users.noreply.github.com>

* Update flac.go

Co-authored-by: Robin <mewmew@users.noreply.github.com>

* Update flac.go

Co-authored-by: Robin <mewmew@users.noreply.github.com>

* Update flac.go

Co-authored-by: Robin <mewmew@users.noreply.github.com>

* Update flac_test.go

Co-authored-by: Robin <mewmew@users.noreply.github.com>

* Update frame/frame.go

Co-authored-by: Robin <mewmew@users.noreply.github.com>

* flac: Improve code styling

* flac: Add ErrNoSeeker documentation comment

* flac: Make searchFromStart return an error instead of panic

* Update flac.go

Co-authored-by: Robin <mewmew@users.noreply.github.com>

* Update flac.go

Co-authored-by: Robin <mewmew@users.noreply.github.com>

Co-authored-by: Robin <mewmew@users.noreply.github.com>
2021-01-28 00:23:27 +01: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 4309906bb8 frame: remove debug print of contiunation bytes
This has been tested with FLAC files containing
a lot of samples and a small block size, thus
having frame.Num make use of up to four
continuation bytes.
2018-08-19 04:21:43 +09:00
mewmew 8c556856f4 frame: make CRC mismatch warnings instead of fatal errors
Updates #31.
2018-08-19 03:50:28 +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
mewmew e8384a1c1b frame: use exclusion regexp instead of _ to skip error check of md5sum.Write and md5 import
golangci-lint run --enable-all -e "(Error return value of .md5sum\.Write. is not checked)"
2018-05-27 14:39:47 +02:00
mewmew 95b4b1d046 flac: fix issues reported by errcheck and unconvert
enc.go:178:35: unnecessary conversion (unconvert)
	if err := enc.bw.WriteBits(uint64(si.NSamples), 36); err != nil {
	                                 ^
enc.go:543:34: unnecessary conversion (unconvert)
	if _, err := enc.bw.Write([]byte(pic.Data)); err != nil {
	                                ^

frame/frame.go:161:17: Error return value of `md5sum.Write` is not checked (errcheck)
				md5sum.Write(buf[:1])
				            ^
frame/frame.go:165:17: Error return value of `md5sum.Write` is not checked (errcheck)
				md5sum.Write(buf[:2])
				            ^
frame/frame.go:170:17: Error return value of `md5sum.Write` is not checked (errcheck)
				md5sum.Write(buf[:])
				            ^

Updates #25.
2018-05-27 14:28:25 +02:00
mewmew e6f4bf95f2 frame: remove unused constant t1 used in UTF-8 decoding
frame/utf8.go:11:2: `t1` is unused (deadcode)
	t1 = 0x00 // 0000 0000

Updates #25.
2018-05-27 14:20:05 +02:00
mewmew d1bcf309b2 Merge branch 'master' of github.com:mewkiz/flac 2017-12-26 15:14:36 +01:00
mewmew 9c66335d65 frame: fix typo reported by misspell 2017-12-26 15:14:11 +01:00
chewxy 43fbacf007 Added 8297-275156-0011.flac, which is a 16kHz sampled file, derived from the LibriSpeech ASR corpus by Vassil Panayotov and Daniel Povey. The file is CCBY-4.0 2017-10-01 09:09:15 +11: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 dd4d1cd9dd frame: Evaluate and remove TODO about potential optimization.
It did not improve the performance of Frame.Hash.
2016-02-11 23:26:32 +01:00
mewmew d675e0aacc frame: Fix Frame.Parse benchmark and add Frame.Hash benchmark. 2016-02-11 19:29:03 +01:00
mewmew e64cfef4cb frame: Test frame decoding and metadata decoding independently of each other.
Use frame.Open instead of frame.ParseFile to seek past metadata in the frame
decoding test case. Metadata test cases are handled separately in the meta
package.
2016-02-11 19:01:02 +01:00
mewmew 5e5fb51cd7 frame: Add benchmark for FLAC decoding. 2016-02-11 18:51:22 +01:00
mewmew 5c6ad5e1d5 frame: Remove debug message from test cases. 2016-02-11 04:28:28 +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
Sergey Didyk 88d6a93e63 Bugfix for frame.HasFixedBlockSize 2015-05-16 18:45:39 +03:00
mewmew e95c34c138 all: Update godoc links to use gopkg.in/mewkiz/flac.v1 2015-01-30 01:58:04 +01: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 4368146290 frame: Add test cases. Currently 1/3 is failing the MD5 checksum test. 2015-01-30 01:19:34 +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 d97155529f flac,frame,meta: Fix display of links. 2014-08-08 08:52:08 +02:00
mewmew 0e7b20bac7 frame: Update Frame.Hash documentation. This is the last API update, and as such fixes issue #4. 2014-08-08 08:27:05 +02:00
mewmew 01ac9e9530 frame: Implement Frame.Hash method which adds the frame's unencoded audio samples to a running MD5 hash. 2014-08-08 08:20:59 +02:00
mewmew 7a33256cf7 meta: Return io.ErrUnexpectedEOF if EOF occurs in the middle of a metadata block. 2014-08-08 06:42:26 +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 88de0bd4a7 meta: Add a brief introduction of the FLAC metadata format. 2014-08-08 02:38:26 +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 8a948cf6c0 frame: Implement frame header decoding. This is the first piece of the new frame API. Updates issue #4. 2014-08-06 17:58:55 +02:00