Buffer start sample offsets

I am just wondering, with modern DAW’s / soundcards, will buffers still have variance in how many samples they process and which sample they start processing on?

I have been kind of avoiding using things like:


and things SEEM ok. But is this just very naive? Or are you pretty much guaranteed to get a block of however many samples you set your buffer to, and always starting at sample 0 in the buffer?

Yes, very naive!

1 Like

OK, I’ll sort it out then.

two more questions:

(1) If i have to pre-allocate other buffers in my prepareToPlay methods, is it pretty safe just to make them twice as large as the expected buffer size?

(2) how do i get the original sample offset from my main AudioProcessor ?

Yeah, twice as large is fine.
Sorry, don’t understand your second question.

2nd question again:

in my PluginProcessor class, the processBlock method only takes an AudioSampleBuffer as an argument. So, where do i find the start sample to plug into any AudioSourceChannelInfo objects that i need to create???

Oh, that one always starts at sample zero.

But in places where there is a start sample, you do need to use it!

sorry for being so thick,

but i’m going through all the documentation i can find online here, all the tutorials…and i just cannot figure out WHERE that start sample offset originates.

does it come from the DAW, the soundcard?? …i have no idea.

I’m probably missing something very fundamental here in my understanding, i know.

Doesn’t matter where it comes from. It’s just a parameter that the caller can use if it wants you to write into a part of the buffer that’s not at the start.

ah ok, so for all intents and purposes, i can just set the offset to zero if all my plugin code does the same, and i don’t care too much about sharing my code? guess so yeah?

The startSample is only in the AudioSourceInformation. It is not present in the AudioBuffer nor in the processBlock.
It is a handy abbreviation, if you write from an AudioSource into an existing buffer, but want to keep samples at the beginning of the buffer.

AudioBuffer<float> original;  // has already audio, and I want to keep existing samples 0-15
AudioSourceChannelInfo (original, 16, numSamples - 16);

It is the same like:

AudioBuffer<float> original;  // has already audio, and I want to keep existing samples 0-15
AudioBuffer<float> subset (original.getArrayOfWritePointers(), 16, numSamples - 16);
AudioSourceChannelInfo (subset);

So you have to respect that when writing a getNextAudioBlock method for an AudioSource subclass.

maybe that helps…

ah ok…personally i don’t need to use that offset now, but will remember that if i ever need to share or extend my AudioSource subclasses.

thanks Daniel, thanks Jules :slight_smile: