Buffer~ crop problem

woyteg's icon

Hello!

I am trying to copy the contents of a buffer~to another buffer and crop it to a certain length. The problem is that I cannot crop to  certain lengths in samples. See attached patch. The actual length is nearly always a bit diffferent than the one I whished to crop to, and eg. I can not crop to a length of 4 samples. I am using the 32-bit version, and I guess this might be the problem.

Is there a possibility to crop to a number of samples directly instead of ms? (not only resize, I'd like to trim the biginning of the data too.. and doesn't "sizeinsamps" also clear the contents anyway?)

Thanks for any help!

Max Patch
Copy patch and select New From Clipboard in Max.
G C's icon

running into this also and seems like the only solution is to go back to manually peek poking stuff into another buffer or make some kind of RNBO contraption external

*** helpful tip from Discord : CROP will accept fractional values.
I've tested a converted number and the result matches the recorded buffer

Source Audio's icon

samples to ms conversion will never work to copy or crop buffer
sample exactly, because of rounding.
try to convert 123 samples in 44100 sr to ms and crop buffer.
then read samps attr.
or set buffer size in samps and get ms from info~


Roman Thilenius's icon

hm, i do not understand the problem. when you properly convert samples to ms, you will always get back the correct values in samples, no?

Source Audio's icon

No
…………………

Roman Thilenius's icon

works fine for me. as you know, in max 4 everything can only be sent in milliseconds to buffer. for whatever reason.
so i do int(samples/(441.)+0.5) and get exactly what i want.
a precision of e.g. the 6 digits behind the comma which 32 bit max displays to you are already enough to always get the integer number of samples you entered.
?

woyteg's icon

Makes me nostalgic to see this 10 year old thread revived. Good to see you are still here and still on max 4 roman!
And yes, the 10 year old younger me assuming that 32 bit version has something to do with this definitely was wrong. Not quite sure what i messed up back then :*

Source Audio's icon

yep nostalgic times, in which I had trouble copying buffers
using ms, which often ended in missing or extra sample
which caused clicks in layered loops.
Max 4 had no way to query size in samples, till buff.op,
which again is not really usable for copying.
At the end I modified el.buffet~ from Lyon potpourri
to use samples for all operations insead of ms.
Worked very well for live looping, I was for example storing every overdub into extra buffer,so that one could undo recording by copying back inverted buffer on the fly, and many such things.

el.buffet is unbeatable when it comes to buffer manipulaion, has even overdub function, but unfortunatelly help files are outdated and useless.

@Roman , look at this


adding 0.5 works for some, and then not for other input values





11OLSEN's icon

Hi, setting the size in ms floats to get a desired length in samples works reliably, it seems. Just letting the buffer~ do the rounding on it's own

Max Patch
Copy patch and select New From Clipboard in Max.

For cropping: are you sure it's not simply endsample + 1. Couldn't create another case yet .?

Source Audio's icon

it is not about setting size, but to crop buffer using samples.
122 ok, 123 not .. that is ony 1 exampe


Max Patch
Copy patch and select New From Clipboard in Max.


11OLSEN's icon

not for me, I get +1 in all cases

Another difference of Win and Mac buffer~ ?

Source Audio's icon

could be, I will check it and report,
I am using max 8.1.11 mostly, have no need for higher versions.
but, for me this is not really important, because I use that exernal for the job directly in samples.
In fact it is strange that setting size in samples has been added to buffer
functions, but crop remains ms only

Source Audio's icon

same problem on windows 10, max 8.5.5
both 21 and 22 at input produce 22

11OLSEN's icon

seems to be related to the samplerate. my buffer~ was at 48000. When I set the buffer to 44100, I can reproduce it..

Roman Thilenius's icon

can´t tell you offhand now what i actually do, but it would make sense that buffer truncates down to the next full sample value.

the only thing what does not make sens is that the crop message now is the only one left which does not allow sample values.

to test how long a buffer is, just index~ from it.

Source Audio's icon

as I said I use different means of buffer manipulation since years,
only reason I posted is to show the bug.

at that time I found no solution to keep
sample count based looping buffers intact when cropping.
waveform~ was the only max tool that could crop the buffer,
problem was exacty the same, even that one could use samples and grid
1 for selection, but only for mouse.
1 sample difference caused clicks, and any ducking or whatever is no solution at all for sustaining loops.


Roman Thilenius's icon

isn´t it a relatively rare scenario that somebody wants to crop a buffer and then use the sample as is in max (apart from exporting things as sample material on disk, of course... IRs, drumsets, that kind of thing.)

when you want to play 99 samples from the buffer you can crop down from 10000 to 100 and then use wave~ or play~ to play 99 samples, if you want to crop stuff for a wavetable set you have to copy between different buffers anyway, and so on.