Re: [PD] nearest power of 2

2008-12-18 Thread Mathieu Bouchard

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; 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 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] nearest power of 2

2008-12-12 Thread hard off
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)
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] nearest power of 2

2008-12-12 Thread Si Mills

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  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


___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] nearest power of 2

2008-12-11 Thread Kyle Klipowicz
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  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


Re: [PD] nearest power of 2

2008-12-11 Thread Matt Barber
This might be silly, but here are three abstractions I made a couple
years or so when I was learning...

the "nearest" one defaults to the higher value for numbers halfway between.


Matt

> Date: Fri, 12 Dec 2008 00:48:48 +0900
> From: "hard off" 
> Subject: [PD]  nearest power of 2
> To: "Pd List" 
> Message-ID:
><161320dd0812110748w620d032g7b9bdff22d2f4...@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> 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_into_nearest_power_of_two_number
> -- next part --
> An HTML attachment was scrubbed...
> URL: 
> http://lists.puredata.info/pipermail/pd-list/attachments/20081212/bb3be031/attachment-0001.htm
>
> --


nextpowoftwo.pd
Description: Binary data


lastpowoftwo.pd
Description: Binary data


nearestpowoftwo.pd
Description: Binary data
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] nearest power of 2

2008-12-11 Thread Thomas Grill
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


___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] nearest power of 2

2008-12-11 Thread hard off
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.


nextpow2.pd
Description: application/extension-pd
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] nearest power of 2

2008-12-11 Thread 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


[PD] nearest power of 2

2008-12-11 Thread hard off
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_into_nearest_power_of_two_number
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list