Hi all. I'm a complete newbie and have made a simple audio sampler for toggle rec/stop with one key then one-touch playback with another. The array in which the audio is stored has to be given a size value (mine set to 10secs at 48kHz sr). Unfortunately, this means that if I record a long sample then subsequently record and playback a shorter sample then on playback I will hear the short sample followed by what's left of the long one. I'm trying to resize the array once each recording is stopped using the timer so that the recorded sample fills the array's space but haven't succeeded yet (see attachment). The other option would be to use the timer data to limit how much of the array is played back, but I wasn't successful doing it that way, either. Any help would be appreciated. Thanks
Resizing arrays on recording
@slickolasR Assuming that you have created a large array that is big enough for the longest recording you might wish to make.......
The easy solution is to clear the array (set every sample to 0) before you start the next recording......
.... where "exampleArray" is the name of your array.
If you want to loop it though then you will need a timer. Search for "Granular" patches..... as they will have a calculation method to set in and out times by limiting the range of [phasor~] for playback.
Or "looper"...... like the alfaloop here...... http://pdpatchrepo.info/patches .... although it is old and might need modifying for Pd Vanilla..... but most of the old externals that it might have used can now be found easily in the Pd top bar menu.... "Help" "Find Externals".
@slickolasR You were almost there. The output of the timer is in milliseconds. Multiply by 44.1 to get the number of samples. Then you need to construct the right message and send it to the array that contains your recording.
But you may find that some of the alternate solutions David mentioned are more flexible. Resizing arrays usually makes more sense when you don't have to do it repeatedly.
That's fantastic! Thank you both! I'll give those methods a try.
Really appreciate the quick response!