mewkiz/flac

investigate why some encoding test cases are failing

mewmew opened this issue · 3 comments

mewmew commented

The #66 PR adds support for LPC encoding of audio samples (and thus resolving #35).

While many test cases pass for round-trip decoding/encoding of FLAC files, producing bit-by-bit identical input and output files, there are still a lot of test cases that produce different output files (during encoding) for a given input file.

This issue tracks the investigation of why these test cases are failing, and also calls for help from the community to join us in the investigation.

Cheerful regards,
Henry & Robin

mewmew commented

From #66 (comment):

The fq tool by @wader has been invaluable to investigate the cause of diffs between input (decoding) and output (encoding) FLAC files.

To investigate a mismatch between input FLAC files and corresponding FLAC files produced by encode, do as follows.

  1. switch to Git branch encode-lpc
  2. uncomment the ioutil.WriteFile lines in TestEncode to output FLAC file (to /tmp/got.flac) when the contents of the round-trip test case mismatch.
  3. uncomment a test case that is currently failing (e.g. testdata/59996.flac)
  4. run go test -v -run TestEncode/testdata/59996.flac
=== RUN   TestEncode/testdata/59996.flac
    enc_test.go:206: "testdata/59996.flac": content mismatch;
    expected 66 4C 61 ... 7C A2 21 22 3B ... 80 32 2A,
    got      66 4C 61 ... 7C 62 21 12 3B ... 80 32 2A
                             ^     ^
                             |     |
                             |     |
                            DIFF  DIFF
--- FAIL: TestEncode (0.02s)
    --- FAIL: TestEncode/testdata/59996.flac (0.02s)
  1. use fq to analyze the diff
    • 4a: analyze input FILE (source of truth): fq d -d flac testdata/59996.flac
    • 4b: analyze output FILE (produced by encode): fq d -d flac /tmp/got.flac

binary diff (using vbindiff) between input and output FLAC files

screenshot_2023-10-29_11:10:27

fq analysis of input FILE (source of truth)

fq d -d flac testdata/59996.flac

screenshot_2023-10-29_11:14:40

fq analysis of output FILE (produce by mewkiz/flac encoding)

fq d -d flac /tmp/got.flac

screenshot_2023-10-29_11:14:50

mewmew commented

From #66 (comment):

--input (orig):    testdata/59996.flac
++output (encode): /tmp/got.flac
 residual: (0b-0000000000000000011111100101101) -16173
 residual: (0b-0000000000000000011101101010011) -15187
 residual: (0b00000000000000000111101011001001) 31433
-residual: (0b-0000000000000000001110111110011) -7667
+residual: (0b-0000000000000000001110111110010) -7666
-residual: (0b00000000000000000110001000010010) 25106
+residual: (0b00000000000000000110001000010001) 25105
-residual: (0b00000000000000000010001110110100) 9140
+residual: (0b00000000000000000010001110110101) 9141
-residual: (0b-0000000000000000110000000101110) -24622
+residual: (0b-0000000000000000110000000110000) -24624
-residual: (0b00000000000000000001000011000000) 4288
+residual: (0b00000000000000000001000011000010) 4290
-residual: (0b00000000000000000110101101001001) 27465
+residual: (0b00000000000000000110101101000110) 27462
-residual: (0b-0000000000000000111100011100001) -30945
+residual: (0b-0000000000000000111100011011110) -30942
-residual: (0b00000000000000000111111110100011) 32675
+residual: (0b00000000000000000111111110100000) 32672
-residual: (0b-0000000000000000101000111001011) -20939
+residual: (0b-0000000000000000101000111001001) -20937
-residual: (0b-0000000000000000011011001011101) -13917
+residual: (0b-0000000000000000011011001011110) -13918
 residual: (0b00000000000000001000100101110011) 35187
 residual: (0b-0000000000000001101011111001001) -55241

There seem to be a small diff in the residual between the original input FLAC file and the encoded output FLAC file.

Still not sure why. Anyone who may have an idea? : )

mewmew commented

Fixed by 70d4ace.