Having some trouble setting BinaryData wav file to stereo

Hi everyone,
I’m having some issues there… I’m playing fixed Binary stereo files

constructor

auto reader = formatManager.createReaderFor(std::make_unique<juce::MemoryInputStream>(BinaryData::Test7_wav, BinaryData::Test7_wavSize, true));

	if (reader != nullptr)
	{
		newSource = new juce::AudioFormatReaderSource(reader, true);
		newSource->setLooping(true);
	}
auto reader2 = formatManager.createReaderFor(std::make_unique<juce::MemoryInputStream>(BinaryData::Test8_wav, BinaryData::Test8_wavSize, true));

	if (reader != nullptr)
	{
		newSource2 = new juce::AudioFormatReaderSource(reader, true);
		newSource2->setLooping(true);
	}
void FXAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
	
	juce::ScopedNoDenormals noDenormals;
	auto totalNumInputChannels = getTotalNumInputChannels();
	auto totalNumOutputChannels = getTotalNumOutputChannels();

	for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
		buffer.clear(i, 0, buffer.getNumSamples());
	
	juce::AudioSourceChannelInfo info(&mixBuffer, 0, buffer.getNumSamples());
	
	newSource->getNextAudioBlock(info);
	for (int c = 0; c < std::min(mixBuffer.getNumChannels(), buffer.getNumChannels()); ++c)
		buffer.addFrom(0, c, mixBuffer.getReadPointer(c), buffer.getNumSamples());

	}
void FXAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
{
	mixBuffer.setSize(2, samplesPerBlock);
}

now everything plays fine but only to the left channel… would anybody notice what i do wrong ? been struggling for days with no clue thanks a lot!

Maybe try using the debugger.
Look at the value of totalNumInputChannels and totalNumOutputChannels in processBlock() and make sure they are both 2 for stereo.
Maybe you did not set your audio processor to have 2 channels for stereo?

1 Like

Thanks replying timart,
wouldn’t that already make the fit?

void FXAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
	
	juce::ScopedNoDenormals noDenormals;
	auto totalNumInputChannels = getTotalNumInputChannels();
	auto totalNumOutputChannels = getTotalNumOutputChannels();
FXAudioProcessor::FXAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
	: AudioProcessor(BusesProperties()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
		.withInput("Input", juce::AudioChannelSet::stereo(), true)
#endif
		.withOutput("Output", juce::AudioChannelSet::stereo(), true)

The constructor arguments are merely a default. Which BusesLayout is chosen is the result of a negotiation where the host is calling isBusesLayoutSupported() to find out what your plugin supports.

Thanks Daniel,
If i understand well because of

bool FXAudioProcessor::isBusesLayoutSupported(const BusesLayout& layouts) const
{
#if JucePlugin_IsMidiEffect
	juce::ignoreUnused(layouts);
	return true;
#else

	if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
		&& layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
		return false;

#if ! JucePlugin_IsSynth
	if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
		return false;
#endif

	return true;
#endif
}

the plugin should be working both mono and stereo?

It accepts everything except if output channelset is different from input channelset and if main output is neither mono nor stereo.

I don’t see it at the moment. Good luck

thanks a lot :wink:

buffer.addFrom(c, 0, mixBuffer.getReadPointer(c), buffer.getNumSamples(), calcul);
buffer.addFrom(0, c, mixBuffer.getReadPointer(c), buffer.getNumSamples(), calcul);

just got thoose to arguments mixed up my bad