On my current project, the client would like me to be able to display a stereo WAV file as if it were mixed to mono (L+R)/2 – what’s the cleanest way to make that happen? I can’t quite decide where it’s best to stick code to perform that mono-ification.
Poking around, personally I would subclass
AudioThumbnail (note, NOT
setSource methods to get the proper reader/source to use (since they are not made accessible to subclasses), then
drawChannels to scan all channels that need drawing and draw an averaged signal. These would be 90% copied from the base implementation of
However, a more clever way of doing it which I imagine would be acceptable for all but the most picky clients, would be to simply override
drawChannels method to call
drawChannel a number of times and simply draw all channels on top of each other. The result is a visualization of a
max function on all signals, which depending on the types of signals you’re processing will be as useful as a “quick look” at the stereo signal as a properly summed signal with a lot less engineering effort.
The AudioThumbnail takes an AudioSource as well, so you could probably use a ChannelRemappingAudioSource (haven’t tested it):
// AudioFormatManager manager; // AudioThumbnail thumbnail; AudioFormatReaderSource* reader = manager.createReaderFor (file); ChannelRemappingAudioSource mapper (reader, true); mapper.setNumberOfChannelsToProduce (1); thumbnail.setSource (mapper);
This was actually my approach, except performed more simply by calling code like
thumb->drawChannel(g, waveRect, 0.f, end, 0, 1.f); thumb->drawChannel(g, waveRect, 0.f, end, 1, 1.f);
…in the component that owns the thumbnail. Everything was great until their QA folks zoomed in far enough so that you end up seeing the channels as separate waveforms (my initial reaction to the report was “can’t repro” because I didn’t zoom in far enough until a screenshot got attached.
I was hoping for exactly this kind of pointer based on my JUCE heuristic “Jules probably already wrote this code but you don’t yet know what he called it.”
I’ll give this a shot today, thanks!