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

Decoder write fixes #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

braheezy
Copy link

@braheezy braheezy commented Jan 7, 2025

The first commit removes the bit shift being performed on samples in the decoder write callback. The FLAC decoder library already ensures the samples are in the right range for the bit depth. After this change, @divExact produced a remainder, so that was changed to @divTruncate, but that is possibly moot...

I wrote a small Zig program to decode a 16-bit FLAC and count how many samples exceeded the max range for 16-bit numbers. It also writes all the samples to a text file:

> zig build demo
bad samples: 6217730
Decoded FLAC: Channels: 2, Sample Rate: 44100, Bits per Sample: 16, Samples: 6311566

As a reference, I wrote the same program in Go so I can diff the samples in the text file:

> diff decoded_samples.zig.txt decoded_samples.go.txt  -q
Files decoded_samples.txt and decoded_samples.go.txt differ

After removing the bit shift, there are no more bad samples and the samples are identical to the Go program:

> zig build demo
bad samples: 0
Decoded FLAC: Channels: 2, Sample Rate: 44100, Bits per Sample: 16, Samples: 6311566
> diff decoded_samples.zig.txt decoded_samples.go.txt -q

The second commit adds support for 3 channels because...it was right there and it works :) center.flac now passes the sanity checks I demonstrated above.

If needed, I can provided the code I used to check my work.


  • By selecting this checkbox, I agree to license my contributions to this project under the license(s) described in the LICENSE file, and I have the right to do so or have received permission to do so by an employer or client I am producing work for whom has this right.

FLAC decoder returns samples in the correct range for the bit depth already
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.

1 participant