Mixing WAV and AudioSampleBuffer



Right now I am trying to combine the AudioSampleBuffer given from the proccessBlock method, with an AudioSampleBuffer that I created from a WAV file. I am mixing them using the addFrom method.

When I am encountering is a ‘buzzing’ sound ontop of the other track when I apply my filter, as opposed to the desired mix of the two buffers.

When I create a reader for the WAV, usingFloatingPointData is false. The sample rate of the WAV matches the sample rate of the audio file I’ve been testing with. Anymore values I should poke at?

Here is a code sample from my constructor.

	/* buffer initialization. */
        SoundFile = File(SoundPath);  /*  SoundPath is correct I believe */
	AudioFormatManager manager;
	Reader = manager.createReaderFor(SoundFile);
	Buffer.setSize(Reader->numChannels, Reader->lengthInSamples);
	Reader->read(&Buffer, 0, Reader->lengthInSamples, 0, true, true);

Here is a code sample from my processBlock

void ShowerfyAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
	for (int channel = 0; channel < buffer.getNumChannels(); ++channel)
		buffer.addFrom(channel, 0, Buffer, channel, 0, buffer.getNumSamples(), 1);	

I have tried changing the numSamples argument of addFrom to Buffer.getNumSamples(), which did not work either.

Sorry if some of my terminology is off, I am still learning.

EDIT: Some more info, when I replace the data in the AudioSampleBuffer buffer in processBlock with the data from the AudioSampleBuffer made from the WAV file, only the buzzing sound is present.

As a newbie I just want to load a sample and play it

You must keep track of where you are in the WAV file buffer and advance that read position at each processBlock call. Currently your code just plays the beginning of the file buffer over and over, resulting in the buzzing sound.


Ahh, that did the trick. What a silly mistake.

Thank you very much!