I need to transfer data from one buffer array to another buffer array without audio clicks. How can I achieve this?
Thanks any advance!
Copying data from one buffer array to another buffer array
I need to transfer data from one buffer array to another buffer array without audio clicks. How can I achieve this?
Thanks any advance!
You can also use vanilla objects for that.
"array get" and "array set" are the objects you are looking for.
I was talking with @porres which made some initial tests about efficiency, and maxlib/arraycopy go bad in time.. And "array get" and "array set" go better. I'm using ofelia in the patch I'm working, so, it is an option.
Here the tests he made:
We can see array is in order of 10x faster than arraycopy. With better message management using his else library he managed to narrow that difference but it exist how we can see:
There is the possibility to use data structures, wich can be more efficient:
https://forum.pdpatchrepo.info/topic/12059/array-text-pointer/1
I put my ass on the chair and did my own tests. So I can see maxlib/arraycopy can be an out-of-the-box solution for my case. Here it go fast enough to won't produce clips. All other options produced it.
I don't understand why my tests go to different @porres tests.. Here the patch:
array_copy-test.pd
Thanks all responses!
@emviveros did you forget the [until]
stuff?
@seb-harmonik.ar woops... Yes.. forget!!!
Sorry about that! now make sense again... I will try to copy paste the data structure test as well...
For now array get/set are is making competitors eat dust!
Well... I've tested copying the entire large array and got different results (Windows 10, old laptop, Pd 0.51.4):
i'm using maxlib for the undo/redo function in my looper and it is fast enough, works perfectly, no artifacts at all
You can also try tabletool from timbreID. Its performance is comparable to (or sometimes better than) maxlib. But I don't know if there is a mac version of this external. There are also tabdump/tabset in zexy, but they seem to be about as efficient as vanilla get/set:
@artureczq thanks a lot for your tests!
It opened my eyes about performance variation against number of iterations we do.
Seems like maxlib/arraycopy have a special implementation for copy entire arrays.. It can be very useful! And in the other hand, if we need timbre classification TimbreID tabletool can be a excellent option to avoid overburden the patch with different externals libs.
The obvious version, copying from src_array to dest_array upon bang.
@emviveros said:
Seems like maxlib/arraycopy have a special implementation for copy entire arrays.
I think it depends on the number of elements being copied.
maxlib/arraycopy accepts start/size parameters with every copy request -- so it has to validate all the parameters for every request (https://github.com/electrickery/pd-maxlib/blob/master/src/arraycopy.c#L81-L166). This is overhead. The copying itself is just a simple for loop, nothing to see here.
[array get] / [array set], AFAICS, copy twice: get copies into a list, and set copies the list into the target.
So we could estimate the cost of arraycopy as: let t1 = time required to validate the request, and t2 = time required to copy one item, then t = num_trials * (t1 + (num_items * t2)) -- from this, we would expect that performance would degrade for large num_trials and small num_items, and improve the other way around.
And we could estimate the get/set cost as num_trials * 2 * t2 * num_items. Because both approaches use a simple for loop to copy the data, we can assume t2 is roughly the same in both cases. (Although... the Pd source de-allocates the list pointer after sending it out the [array get] outlet so I wonder if the outlet itself does another copy! No time to look for that right now.)
If you have a smaller number of trials but a much larger data set, then the for
loop cost is large. Get/set incurs the for
cost twice, while arraycopy does it once = arraycopy is better.
In the tests with 100000 trials but copying 5 or 10 items, the for
cost is negligible but it seems that arraycopy's validation code ends up costing more.
hjh
Oops! Looks like something went wrong!