Flac writer bug

I have a simple little program that loads an audio file (usually wav) and then outputs it again in flac format.

Works perfectly for shorter files, but if the input buffer is more than about 10 minutes long, the output is incorrect.

Below are 2 outputs from the code.

The only difference is that the top one is built from a 5 minute clip, and the bottom one is the same audio, but taking a longer section of it (15 minutes).

It looks like it just downsamples (grabbing every 4th sample or something). Not sure if this is a wrapper issue, or some flac thing (shouldn’t be that, but who knows).

To be clear, I read the entire file into an AudioSampleBuffer which I can then play and view. The audio in that buffer is correct regardless of input length.

It’s only when written to a longer FLAC file that it gets messed up.

In any event, would love any thoughts. Also, maybe a flac update is in the works?

Ok - slight correction - the distortions get worse as you go along in the file.

So … the end of the FLAC will always be the worst, and the first few minutes are always fine.

This seems to indicate something stateful, like a filter, gets out of whack.

I’m no expert on flac encoding … but surely this will make sense to someone.

Have you tested outputting a WAV file? If that also has the problem, then it points to some other problem in your code.

Yeah, it’s something I am doing (wav shows error too … only after 8 or 10 minutes again).

I have a resampling stage in there with an antialiasing filter.

That must be it, I recently changed that code to use a dsp::IIRFilter.

Looks like the filter calls snapToZero() after each process call, which I assume takes care of denormals though.

hmmm