AudioSampleBuffer Playback Issues

#1

Hi everyone! I’m new to JUCE and am trying to build a simple Audio Sample Playback plugin to learn the ropes a little bit. In my PluginProcessor.h I store a unique_ptr to an AudioSampleBuffer, set that pointer once I read the contents of a file in the PluginProcessor ctor, and then copy the contents (sample by sample) to the buffer passed into processBlock().

When I run the plugin, things seem to be working properly except that the audio playback is extremely glitchy and sounds terrible compared to how the sample should sound. Any help on this would be much appreciated!

0 Likes

#2

Welcome to the forum!

Please show your code so we can better understand the issue. Playing the contents of an AudioBuffer should be pretty trivial to get right, but there are of course some details that can be wrong. (There’s also no need to use an AudioBuffer via a unique_ptr, it works fine as a value type. That however likely isn’t causing your playback issue.)

0 Likes

#3

Thanks for the response, Xenakios! Attached is a screenshot of my code:

0 Likes

#4

You are probably advancing the file buffer read position twice or more because your outer loop iterates over the plugin channels. Try inverting the looping order so that the outer loop iterates the samples and the inner loop iterates over the channels and only advance the read position when you advance the sample loop.

Something like :

for (int i = 0; i < buffer.getNumSamples(); ++i)
		{
			for (int j = 0; j < buffer.getNumChannels(); ++j)
			{
				int chantoread = j % m_fileBuffer.getNumChannels();
				buffer.setSample(j, i, 0.1*m_fileBuffer.getSample(chantoread,m_filePos));
			}
			++m_filePos;
			if (m_filePos >= m_fileBuffer.getNumSamples())
				m_filePos = 0;
		}
2 Likes

#5

Ah yes that solved it, thank you!

0 Likes