[chuck-users] Math.trunc

Jascha Narveson jnarveson at wesleyan.edu
Mon Oct 8 07:58:34 EDT 2007

Hello, Ge and Kassen -

Thanks for the welcomes both of you, and thanks for the interesting  
software, Ge!  And yes, you've accurately pegged me as a SC user  
learning ChucK - i've been 'translating' examples in both directions  
in an attempt to learn the language.  It's been interesting to see  
how the languages differ - i love how intuitive signal flow is in ChucK.

Both of your suggestions are useful.  Is "Osc" in the documentation  
somewhere?  I don't see it on the online UGen reference list...



On Oct 8, 2007, at 6:54 AM, Kassen wrote:

> Hi!
> That was a good question, I think sorting where to use "modular  
> synth style" signal flow and where to us "plain code" is a  
> important part of ChucKing. Many things can be done both ways but  
> if you do it the "wrong" way you'll end up with ugly code and high  
> cpu costs.
> If there is still a need to round to a multiple of some number in a  
> "5.trunc(2);" style it could be done using something like this;
> fun float trunc(float input, float multiple)
>   {
>   return (input - input%multiple);
>   }
> which will always round down. If we really need the closest value  
> we can use something like;
> fun float trunc(float input, float multiple)
>   {
>   if ( input%multiple < ( .5 * multiple)  ) return (input - input% 
> multiple);
>   else return (input - input%multiple + multiple);
>   }
> This would be overkill if we just want a series of tones that hits  
> every multiple of 400Hz (in that case we'd be much better off with  
> simply generating that series directly like Ge said) but it's still  
> a valid question in itself.
> Hope that helps.
> Kas.
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

More information about the chuck-users mailing list