setSize() is setting my audioBuffer length to 90,296, getNumSamples() is reporting it as 45,148 (which is half). Is this right?

Here’s my setSize()

IansAudioBuffers.setSize(2, 45148);  
iBufferLengthsAtCreation = IansAudioBuffers.getNumSamples();

Shouldn’t getNumSamples return 90,296 rather than 45148? Because 2 channels * 45,148 is the actual size of the buffer.

Each channel of the buffer has size 45148.

After you call setSize (anyNumberOfChannels, 45148), then the buffer will report its length as 45148 regardless of how many channels it has.

@benvining …oh Ok, so its a correct report. getNumSamples is brings back a report of how many samples-per-channel are in my audioBuffer, not the overall number of samples.

Yes, getNumSamples() is working correctly here.

In your example, would encourage you to think of 45148 as the total overall number of samples.
The reason why is because we are working with discreet-time signals, meaning that the distance between two successive samples represents a measurable and exact amount of time.

So IansAudioBuffers represents 45148 samples’ worth of time. Whether it has 1 channel or 48,000 channels, it still represents exactly 45148 samples’ worth of time, no more and no less.

I think, if you think about buffers as “really” having more samples than how many are in each channel, you will very quickly write some code that accesses nonexistent sample indices and seg faults.


thanks, that makes sense. I am following a tutorial by the Audio Programmer on Youtube about writing to a buffer, and he is incrementing his writePosition to his buffer for every channel. I thought this would be an error and it should be only incremented once since the write position for channel 0 and 1 would be the same value.
Is that right?
# Juce Tutorial 40- Building a Delay Plugin Pt 1 (Creating a Circular Buffer)

Yeah, quickly looking that TAP code seems to have an error if the code isn’t processing a mono signal.

1 Like

@xenakios , or Ben…
thanks, I had one final question on this circular buffer thing.
Right at the end I see these two lines of code added:

So here he is writing the bufferData to fill up to the end buffer (in the 1st line), and he’s circling around to 0 again to start writing at the start of the same buffer (the 2nd line). Thats fine.

Here’s my question though: In the 2nd line .copyFromWithRamp() I see its just copying bufferData again. Shouldn’t it be bufferData minus the the bufferData he wrote in the first line?
Isn’t this writing duplicate bufferData? (Am I explaining my question well?)