spotify / pedalboard

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

Allow processing square buffers. #347

Open psobot opened 3 days ago

psobot commented 3 days ago

Fixes #336. (cc @mttbernardini)

This PR fixes the issue that occurs when passing a square (i.e.: (x, x)) buffer into a Plugin instance. Like https://github.com/spotify/pedalboard/pull/338, this PR adds caching of the last-detected channel layout to each Plugin instance, making the following example pass:

board = Pedalboard([Reverb(), Gain()])
with AudioFile("file_with_17_stereo_samples.wav") as f:
    while f.tell() < f.frames:
        # Read three frames at a time; but the last frame will
        # end up with only two samples in it.
        output = board(f.read(3), f.samplerate)

Prior to this PR, the above example would have failed as the last f.read(3) call would return an array of shape (2, 2).

mttbernardini commented 3 days ago

Hey @psobot, thank you for fixing this. Does this PR include the "memorization" feature as in the AudioFile scenario, i.e. process (n, 0) or (0, n) to hint the layout for the next buffer call?