spotify / pedalboard

🎛 🔊 A Python library for audio.
https://spotify.github.io/pedalboard
GNU General Public License v3.0
5.23k stars 262 forks source link

Incorrect FLAC files reading after ReadableAudioFile.seek() to non-zero position on macOS Catalina #201

Closed Gdalik closed 1 year ago

Gdalik commented 1 year ago

Hello!

When trying to read() a flac audiofile on macOS Catalina from a certain non-zero position after seek(), each try to read a chunk gives out silence (a NumPy array of zeroes of the corresponding length/shape). seekable() returns True. Exactly the same code works fine with wav and mp3 files, including the same stuff converted from flac. Reading without seeking or after seek(0) works ok as well.

psobot commented 1 year ago

Hi @Gdalik!

This sounds almost identical to https://github.com/spotify/pedalboard/issues/170, which was fixed back in December 2022 as part of version 0.6.7. Which version of Pedalboard are you using?

Gdalik commented 1 year ago

Hi, @psobot !

I'm using the latest version 0.7.0

psobot commented 1 year ago

Thanks @Gdalik - any chance you can share an example file that exhibits this behaviour? We have plenty of tests for ensuring seek accuracy and I've confirmed that they all pass on macOS Ventura, although I don't have a Catalina machine available to test with. (Our FLAC code should behave identically on Catalina, though, as we don't use any OS-provided code when reading FLAC files.)

Gdalik commented 1 year ago

Hi @psobot!

Here is the example of seeking/reading two files (FLAC and WAVE) with 30 seconds of pink noise, generated in Audacity. Here is the link to them: I run it with Python 3.9 on macOS Catalina 10.15.7 .

import pedalboard
from pedalboard.io import AudioFile
import numpy as np

def read_audio(filename: str, seek=0):
    with AudioFile(filename, mode='r') as f:
        f.seek(int(seek * f.samplerate))
        a_slice = np.empty((f.num_channels, 0))
        while f.tell() < f.frames:
            chunk = f.read(int(f.samplerate))
            a_slice = np.concatenate((a_slice, chunk), axis=1)
    return a_slice

print(f'{pedalboard.__version__=}')
print(f"FLAC from zero: {read_audio('pinknoise.flac')}")
print(f"FLAC from 1st sec: {read_audio('pinknoise.flac', seek=1)}")
print(f"FLAC from 10th sec: {read_audio('pinknoise.flac', seek=10)}")
print(f"WAV from zero: {read_audio('pinknoise.wav')}")
print(f"WAV from 1st sec: {read_audio('pinknoise.wav', seek=1)}")
print(f"WAV from 10th sec: {read_audio('pinknoise.wav', seek=10)}")

And the output:

pedalboard.version='0.7.0' FLAC from zero: [[0.07504501 0.0483108 0.09653004 ... 0.17435224 0.23133031 0.21039461]] FLAC from 1st sec: [[0. 0. 0. ... 0. 0. 0.]] FLAC from 10th sec: [[0. 0. 0. ... 0. 0. 0.]] WAV from zero: [[0.07504273 0.04830933 0.09652711 ... 0.17434694 0.23132327 0.21038821]] WAV from 1st sec: [[-0.16204788 -0.11825599 0.0003053 ... 0.17434694 0.23132327 0.21038821]] WAV from 10th sec: [[0.1043091 0.16769399 0.0360111 ... 0.17434694 0.23132327 0.21038821]]

Gdalik commented 1 year ago

BTW, while looking through your tests, I saw the test_real_mp3_parsing_with_lyrics3(), and I get exactly the described issue with some mp3 files on Windows 10 with Pedalboard 0.7.0. Sorry for not writing this in a separate topic. I just thought, these issues might have the same nature, e.g. the accidental use of the unfixed version of JUCE in the latest release of your library.

psobot commented 1 year ago

Thanks @Gdalik - I've been able to reproduce this issue locally (on all operating systems) and confirmed that there was a gap in our test code that did not catch this specific bug. I've got a fix up at #203, which hopefully should be merged and deployed shortly.

Re: the MP3 parsing issues you mentioned - please open a separate issue for that to track that, and if you can send examples of MP3 files that fail to parse (privately or publicly) then that would greatly help debug.

psobot commented 1 year ago

The fix for this issue is now publicly available on PyPI as part of Pedalboard v0.7.1.

Gdalik commented 1 year ago

Hi @psobot !

Awesome! I have upgraded to v0.7.1, and now it works as expected! Thank you so much!

As for the issues with mp3, I will open a separate issue and get back to you soon.