Wav import playback too fast


Hello again,

I’m loading a wav file into my plugin using the AudioFormatReader, and reading the whole thing into an AudioSampleBuffer object.

In the processBlock loop I’m iterating through that buffer using a separate variable (which wraps to zero upon reaching the end of the file). I add to the output buffer. This worked, and I celebrated, however…

The wav file playback is too fast :scream: - though the sample rate of the file and that of the AudioProcessor/host are both at 44100 Hz.

If anyone has advice on why this may be, I would be grateful.

My code below:

   auto* outData = buffer.getWritePointer (channel);
   auto* wavSamplesToProcess = fileBuffer.getReadPointer(channel);

for(int sample = 0; sample < buffer.getNumSamples(); sample++)
*outData = wavSamplesToProcess[wavSample] ;


Is it a mono or stereo file?



Do the audio file and plugin channel counts match?


Thank you both for your replies.

Yes, all tracks I’ve tried are stereo - both channel counts match (2). Printing out
reader->numChannels and getTotalNumInputChannels() garners two for both of those.

I’ve initialised and filled the buffer in setup like so:

fileBuffer.setSize(reader->numChannels, (int) reader->lengthInSamples);
reader->read(&fileBuffer, 0, (int) reader->lengthInSamples, 0, true, true);

I am not sure whether the problem arises from importing the file incorrectly, or it’s to do with the way the app is configured (which surely shouldn’t be the case since the plug-in will be listening to the DAW)

I’ve imported the same track into an OpenFrameWorks audio app I made, and the playback is fine.


Problem solved. It was a silly one!

I was incrementing wavSamples inside the channel loop - which of course meant that I was incrementing twice as fast.


Which is why we asked about the number of channels