Handling loops in sequencers

Lets say for fun we’re building a sequencer and the user puts some loops points down and hits play. When our processBlock gets closes to the loop point, how should I handle the looping if the timeInSamples + sampleBlock ends up slightly past the loop point?

Should I grab the buffer from timeInSamples + sampleBlock, play, then loop on next iteration? Or should I calculate how many samples would exist in the current loop and then grab the remainder from anything at the beginning of the loop point?

1 Like

regardless of what you want to do with a sequencer, imo it makes most sense to just start by letting a simple saw-osc be in sync with whatever rate you want over the current bpm and project pos. that already gives you a lot of useful tools. you can use the phase of the osc to determine at which point of your loop you are relatively spoken. in your case you could just directly map that onto the size of your audio sample and play it back that way. but a saw wave also has a point where it resets from 1 to 0 (or -1, whatever), so you can think of it like this: whenever the dif between 2 samples of that modulator is bigger than .5 at some point the loop start occurs. you could use that to determine when to switch to another mode when the user has used a parameter like going to play another loop or so