what's the easiest way for pd to find the nearest power of 2 for any float?
so 10 would give a result of 8, 53 would give a result of 64,
etc..
http://en.wikipedia.org/wiki/Power_of_two#Algorithm_to_convert_any_number_in...
ah don't worry. the bitwise operators in pd correspond exactly to the process in that wikipedia article. couldn't guess it would be that easy.
may as well post the patch i guess. actually it just gets the NEXT power of 2, not the nearest, but that is fine for my purpose - which is to decide how many slices to make in a sound file to cut it into individual beats.
This is neat. Please share your continued research in this territory. Also, has anyone made a beat slicer that chops up a sound file based on transients?
~Kyle
On Thu, Dec 11, 2008 at 11:07 AM, hard off hard.off@gmail.com wrote:
may as well post the patch i guess. actually it just gets the NEXT power of 2, not the nearest, but that is fine for my purpose - which is to decide how many slices to make in a sound file to cut it into individual beats.
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Hardoff* has actually :-) Uses bonk~ and works bloody well.
*is there a link for that somewhere?
On 12 Dec 2008, at 00:25, Kyle Klipowicz wrote:
This is neat. Please share your continued research in this
territory. Also, has anyone made a beat slicer that chops up a sound
file based on transients?~Kyle
On Thu, Dec 11, 2008 at 11:07 AM, hard off hard.off@gmail.com wrote: may as well post the patch i guess. actually it just gets the NEXT
power of 2, not the nearest, but that is fine for my purpose - which
is to decide how many slices to make in a sound file to cut it into
individual beats.
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
--
http://perhapsidid.wordpress.com http://myspace.com/kyleklipowicz _______________________________________________ Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
http://puredata.hurleur.com/sujet-1953-sample-slicer-user-selectable-slices
scroll down the page a bit to get the latest revised version. (oh, and you have to log in to the pd forum to be able to see and download the attachments)
Hi,
one could also use
expr pow(2, int(log($f1)/log(2)+0.5))
which takes the dual log, rounds that to the nearest integer and
calculates the dual power again.
gr~~~
Am 11.12.2008 um 18:02 schrieb hard off:
ah don't worry. the bitwise operators in pd correspond exactly to
the process in that wikipedia article. couldn't guess it would be
that easy.
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On Fri, 12 Dec 2008, hard off wrote:
what's the easiest way for pd to find the nearest power of 2 for any float?
depends how you define «nearest». multiplication-wise, 92 is closer to 128 than to 64, because 92*92 > 64*128, whereas addition-wise, it's closer to 64 because 92+92 < 64+128.
For nearest powers of something, I'd use the multiplication-wise definition, whereas for nearest multiples of something, I'd use the addition-wise definition.
To get the position of the highest bit of x, you can do log(x)/log(2), though there is an int-only algorithm in gridflow.h:
#define Z(N) if ((x>>N)&(((typeof(x))1<<N)-1)) { x>>=N; i+=N; } static int highest_bit(uint32 x) {int i=0;Z(16)Z(8)Z(4)Z(2)Z(1)return i;}
... this splits a number in two sets of bits repeatedly to find where the top bit is.
However, I suspect that log(x)/log(2) could be faster than the version without log, because interpretation of pd patches is slow.
when you have the highest bit you have the previous-or-equal power-of-two as 1<<highest_bit. To find the multiplication-wise nearest power-of-two for x, you could round half of the highest bit of x*x, but if log(x)/log(2) is better for you, then you could round log(x)/log(2).
_ _ __ ___ _____ ________ _____________ _____________________ ... | Mathieu Bouchard - tél:+1.514.383.3801, Montréal, Québec