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

Flac files return empty sample buffers #170

Closed
richardmitic opened this issue Nov 30, 2022 · 3 comments · Fixed by #173
Closed

Flac files return empty sample buffers #170

richardmitic opened this issue Nov 30, 2022 · 3 comments · Fixed by #173
Labels
bug Something isn't working

Comments

@richardmitic
Copy link

richardmitic commented Nov 30, 2022

Seeking to certain positions within certain flac files makes ReadableAudioFile.read() return sample buffers of all zeros.

Here is a file + code that triggers the bug:

sine_stereo_0.flac

from pedalboard.io import AudioFile

with AudioFile(file) as af:
    # read 1 second of audio and assert that it contains reasonable samples
    samples = af.read(int(af.samplerate))
    assert not (samples == 0).all()
    
    # seek to 1.1 seconds
    assert af.seekable
    af.seek(int(1.1 * af.samplerate))

    # read 1 second of audio again and assert that samples are reasonable
    samples = af.read(int(af.samplerate))
    assert not (samples == 0).all()  # this will fail

The file was created by generating a sine wave with ffmpeg and encoding with the flac reference encoder at compression level 0. Compression levels 1 and 2 will produce a file that fails in exactly the same way.

ffmpeg -f lavfi -i "sine=frequency=1000:duration=5" -filter_complex "[0:a][0:a]amerge=inputs=2[aout]" -map "[aout]" sine_stereo.wav
flac -0 sine_stereo.wav -o sine_stereo_0.flac

For comparison, here's a file that can be read without problems. It was created in the same way but uses compression level 3 instead.
sine_stereo_3.flac

flac -3 sine_stereo.wav -o sine_stereo_3.flac
@psobot
Copy link
Member

psobot commented Dec 1, 2022

Thank you @richardmitic! I've been able to reproduce this in a test, and local tests so far seem to show that the return code of the FLAC__stream_decoder_seek_absolute method is being ignored, and the return code is often false (meaning there's an error).

I'll try the simplest thing first: bumping JUCE versions, as the newest version of JUCE includes a version bump of the FLAC library itself.

@psobot
Copy link
Member

psobot commented Dec 2, 2022

Quick update: I've tracked this down to a very small bit of code in JUCE's FlacReader class and opened an issue. Until that's resolved, I'll see what we can do about fixing the issue within Pedalboard by vendoring the juce::FlacAudioFormat classes and patching out the bug.

@richardmitic
Copy link
Author

Excellent work! Thanks for tracking it down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants