How to make a class that samples incoming audio to be used as a synth voice later?

Hello everybody:
I am having trouble trying to build a class with which I could record a certain amount of an incoming stereo signal (a chunk several seconds long) and play it later at will. I intent to record a second chunk of audio while the first recorded is playing (better if is multiplaying) and switch the playing to it upon the recording of the second chunk has ended. Something like this has been done already beautifully by Katja Vetter for a couple of PureData externals (slicerec~ and sliceplay~). That code is written in C with all the PureData protocol intertwined and it’s beyond my current understanding.
I suspect that this has been implemented before and “lays dormant” in a beautiful add-on without an example. I’m currently trying to learn how to do it using the ofxPDSP add-on, which I find awesome.
Well, any guidance is welcome. Thank you very much in advance.

Hi, I think that ofxPDSP implements what you are saying. Probably @npisanti can help there.
Another option is to use ofxSoundObjects, where its example-soundRecorderToPlayer example does more or less what you mention. if you try to record it will erase what was recorded before but what you can do is that you keep a collection of players and whenever you start a new recording you add a new player, then follow the logic in the example to put into it what was recorder, and you’ll end up with that you need. Let me know if you need help of if you are able to figure it out.

“live sampling” has still to be implemented in ofxPDSP. Mostly like because it will require some additional code for managing memory in a separate thread and on one side it is not trivial, on anoher i didn’t had any need for it in projects or commissions, sorry

Thanks @roymacdonald, @npisanti for your quick response. It seems this is the first step in a long walk. I’ll try to do my best and share the results if useful. Best regards.

1 Like

You can try to use a DelayLine as implemented here

The write method will write samples and the read can be used to read separate to writing and will smoothly move to the next item. They all use the same “playhead” though and depends on if that works for you or not (if you need to go back to previously recorded items, then it might not be the best path)

Thank you very much! I will check on that. By the way, your ofxPatchbay addon looks interesting too. Wow, so many things to learn…

Thanks! ofxPatchbay really helped me move fast on my project so hope it’s useful!

Also, you can actually use an array of DelayLine for your use case. I used 2 of them for Grainproc