Skip to content

Commit

Permalink
frame: add hashing of bit samples not evenly divisible by 8 (e.g. 12 …
Browse files Browse the repository at this point in the history
…and 20 bit)

This fixes IETF test cases 22, 37 and 62.

Updates #60.
  • Loading branch information
mewmew committed Oct 24, 2023
1 parent 2e1ff46 commit 9d50c9e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
8 changes: 4 additions & 4 deletions frame/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ func (frame *Frame) Hash(md5sum hash.Hash) {
for i := 0; i < int(frame.BlockSize); i++ {
for _, subframe := range frame.Subframes {
sample := subframe.Samples[i]
switch bps {
case 8:
switch {
case 1 <= bps && bps <= 8:
buf[0] = uint8(sample)
md5sum.Write(buf[:1])
case 16:
case 9 <= bps && bps <= 16:
buf[0] = uint8(sample)
buf[1] = uint8(sample >> 8)
md5sum.Write(buf[:2])
case 24:
case 17 <= bps && bps <= 24:
buf[0] = uint8(sample)
buf[1] = uint8(sample >> 8)
buf[2] = uint8(sample >> 16)
Expand Down
3 changes: 0 additions & 3 deletions frame/frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ var golden = []struct {
{path: "../testdata/flac-test-files/subset/19 - samplerate 35467Hz.flac"},
{path: "../testdata/flac-test-files/subset/20 - samplerate 39kHz.flac"},
{path: "../testdata/flac-test-files/subset/21 - samplerate 22050Hz.flac"},
// TODO: fix decoding of "subset/22 - ...flac": frame.Frame.Hash: support for 12-bit sample size not yet implemented
{path: "../testdata/flac-test-files/subset/22 - 12 bit per sample.flac"},
{path: "../testdata/flac-test-files/subset/23 - 8 bit per sample.flac"},
{path: "../testdata/flac-test-files/subset/24 - variable blocksize file created with flake revision 264.flac"},
Expand All @@ -66,7 +65,6 @@ var golden = []struct {
{path: "../testdata/flac-test-files/subset/34 - samplerate 192kHz, using only 32nd order predictors.flac"},
{path: "../testdata/flac-test-files/subset/35 - samplerate 134560Hz.flac"},
{path: "../testdata/flac-test-files/subset/36 - samplerate 384kHz.flac"},
// TODO: fix decoding of "subset/37 - ...flac": frame.Frame.Hash: support for 20-bit sample size not yet implemented
{path: "../testdata/flac-test-files/subset/37 - 20 bit per sample.flac"},
{path: "../testdata/flac-test-files/subset/38 - 3 channels (3.0).flac"},
{path: "../testdata/flac-test-files/subset/39 - 4 channels (4.0).flac"},
Expand All @@ -92,7 +90,6 @@ var golden = []struct {
{path: "../testdata/flac-test-files/subset/59 - AVIF PICTURE.flac"},
{path: "../testdata/flac-test-files/subset/60 - mono audio.flac"},
{path: "../testdata/flac-test-files/subset/61 - predictor overflow check, 16-bit.flac"},
// TODO: fix decoding of "subset/62 - ...flac": frame.Frame.Hash: support for 20-bit sample size not yet implemented
{path: "../testdata/flac-test-files/subset/62 - predictor overflow check, 20-bit.flac"},
// TODO: fix decoding of "subset/63 - ...flac": MD5 checksum mismatch for decoded audio samples; expected e4e4a6b3a672a849a3e2157c11ad23c6, got a0343afaaaa6229266d78ccf3175eb8d
{path: "../testdata/flac-test-files/subset/63 - predictor overflow check, 24-bit.flac"},
Expand Down

0 comments on commit 9d50c9e

Please sign in to comment.