Skip to content

Add ChannelConvertedReadableAudioFile for .mono() support when reading files.#453

Draft
psobot wants to merge 2 commits into
masterfrom
psobot/channel-count
Draft

Add ChannelConvertedReadableAudioFile for .mono() support when reading files.#453
psobot wants to merge 2 commits into
masterfrom
psobot/channel-count

Conversation

@psobot
Copy link
Copy Markdown
Member

@psobot psobot commented Jan 16, 2026

We've had ResampledReadableAudioFile for a while now, providing a nice interface for on-the-fly resampling with .resampled_to(new_sample_rate). However, a common complaint is that there's no corresponding method for changing channel counts; users have to do np.mean(chunk, axis=0) instead to downmix.

This PR adds ChannelConvertedReadableAudioFile, which adds three new helpers for this:

  • .mono(), which downmixes to a single channel
  • .stereo(), which upmixes mono to stereo
  • .with_channels(channel_count: int), which upmixes mono to any number of channels (or downmixes any number to mono).

Downmixing to any number of channels other than 1 is currently not supported; there are multiple methods to go from 5.1 or other multichannel formats to stereo, and Pedalboard should not (yet) be opinionated about them.

Under the hood, to make this chaining work, I had to pull out AbstractReadableAudioFile as a base class and do a bit of class hierarchy refactoring.

gijzelaerr added a commit to gijzelaerr/pedalboard that referenced this pull request Mar 18, 2026
Fixes CI failures from psobot's spotify#453 (channel conversion feature):
- Apply clang-format (LLVM style) to ReadableAudioFile.h,
  ChannelConvertedReadableAudioFile.h, and python_bindings.cpp
- Add ChannelConvertedReadableAudioFile class to type stubs
- Add mono(), stereo(), with_channels() method stubs to
  ReadableAudioFile, ResampledReadableAudioFile, and
  ChannelConvertedReadableAudioFile
- Add resampled_to() method stubs to ResampledReadableAudioFile and
  ChannelConvertedReadableAudioFile (inherited from abstract base)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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