Syncing MIDI note on with variable rate PlayBuf loop

I might be missing some super obvious way, but i’m stuck trying to solve this.

i have a function that contains a looping PlayBuf that then gets passed onto some effects for further fun – quite straightforward:

u = { x =, b,, 1.63), loop:1); x = x + (((FX))) }.play(s);

i am looking for a way to send a MIDI note on event (out of SC) every time the loop starts, which would be easy if the duration of the soundfile was constant, but since its playback rate is being modulated, it’s constantly drifting.

I bet i’m overlooking some easy way out…

This is easy if you have access to the playback head position, which PlayBuf doesn’t give you…

… but Phasor does. Here, rate can be whatever modulator you need.

// maybe got these arguments wrong
var phase =, rate *, 0,, 0);
var loopTrig = < 0;
var sig =, bufnum, phase);, '/looped');

And see OSCFunc / OSCdef to receive the “looped” message.

Btw use triple backticks to enclose code blocks on the forum:

code here


Sounds like your use case doesn’t involve minutes-long buffers, but note that when you use BufRd you are limited in how far into your buffer you can access before your audio is degraded.

From the BufRd helpfile:
WARNING: The phase argument only offers precision for addressing 2**24 samples (about 6.3 minutes at 44100Hz).

(if you need to use longer buffers with BufRd, check out – helpfiles still a work in progress… for right now see ‘SuperUGens Overview’ helpfile)