Multichannel Sampler WAV file interleave/deinterleave problem

Hi all,

I am building a VST3/AU sampler for REAPER that takes in quadraphonic audio files and outputs quadraphonic audio.

Currently my audio output from the VST is indeed 4 channels, but only Output Channels 1&2 have signal while 3&4 is silent. After some prodding, I find that during some processing stage JUCE incorrectly interleaved the audio file loaded into the sampler: the 1&3 channels of the audio file is summed to Output Channel 1 of the sampler output and the 2&4 channels summed to Output Channel 2.

I’ve tried to print the channel numbers of every processing unit of the sampler. The plugin processor output channels (BusesProperties().withOutput("Output", juce::AudioChannelSet::quadraphonic(), true)), the audio format reader (when loaded with a quadraphonic audio file), and the audio buffer for the PluginProcessor::processBlock() input are all 4.

Can anyone enlighten me what I’m missing and how may I fix this? Thank you!!!

First to clarify: the BusesProperties you supply as constructor arguments is not necessarily the BusesLayout that ends up being used. The host and the plugin negotiate a suitable BusesLayout by calling isBusesLayoutSupported() with different layouts, where your implemenation answers yes or no to the layout. After that negotiation, the host will set a layout and call prepareToPlay(). So this is the place where you finally know the BusesLayout and you can allocate resources for that layout.

The AudioBuffer in processBlock has the maximum number of channels for all inputs and outputs.
If you have more outputs than inputs, the unused channels will contain garbage, and it is your responsibility to fill or clear them.

And to be clear: the address is identical:

getReadPointer(0) == getWritePointer(0)

The only difference is the constness.

Thank you! My guess is also that I haven’t properly initialized the prepareToPlay() method; it now only contains sample rate checking (Sampler.setCurrentPlaybackSampleRate(sampleRate);) and ADSR update.

I would appreciate it immensely if you could be more specific about what to do from here!

To clarify, I have checked everything except allocating memories for prepareToPlay():

  1. Checked in isBusesLayoutSupported() that the host DAW/track supports mono & stereo & quadraphonic:
if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
     && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo()
     && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::quadraphonic())
        return false;
  1. Cleared extra output channel for garbage.
    As this is a sampler plugin, no audio input channel is allocated; it only has one MIDI input.
: AudioProcessor (BusesProperties()
                       .withOutput("Output", juce::AudioChannelSet::quadraphonic(), true))

To avoid loopback upon compiling

    for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
    {
        buffer.clear (i, 0, buffer.getNumSamples());
    }