[chuck-users] Conversion float to int using SndBuf

Michael Heuer heuermh at gmail.com
Tue Jan 21 10:35:12 EST 2020


Hello Mícheál,

The ChucK language has a cast operator '$' which might come in handy in this situation

(pctPosInit/100*myBuf.samples()) $ int => myBuf.pos;

Cheers,

   michael


> On Jan 21, 2020, at 7:08 AM, Mícheál Ó Catháin <micheal.ocathain at gmail.com> wrote:
> 
> Hi
> What is the best way to convert a float to int in the following please?
> 
> //I want to set myBuf.pos to a percentage of myBuf.samples()...
> //Start playing at say 40% through the total number of samples.
> 
> 40.0 => float pctPosInit;
> pctPosInit/100*myBuf.samples() => myBuf.pos;
> 
> 
> This throws the error argument types don't match. 
> I'm not seeing how to convert the float to an int here.
> Thanks for your help!
> 
> Micheal
> _______________________________________________
> 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