Thank you Michael, Ermina and Jean!
It is working a treat.
Micheal
On Tue, 21 Jan 2020 at 17:00,
Send chuck-users mailing list submissions to chuck-users@lists.cs.princeton.edu
To subscribe or unsubscribe via the World Wide Web, visit https://lists.cs.princeton.edu/mailman/listinfo/chuck-users or, via email, send a message with subject or body 'help' to chuck-users-request@lists.cs.princeton.edu
You can reach the person managing the list at chuck-users-owner@lists.cs.princeton.edu
When replying, please edit your Subject line so it is more specific than "Re: Contents of chuck-users digest..." Today's Topics:
1. Conversion float to int using SndBuf (M?che?l ? Cath?in) 2. Re: Conversion float to int using SndBuf (Michael Heuer) 3. Re: Conversion float to int using SndBuf (ermina) 4. Re: Conversion float to int using SndBuf (Jean Menezes da Rocha)
---------- Forwarded message ---------- From: "Mícheál Ó Catháin"
To: chuck-users@lists.cs.princeton.edu Cc: Bcc: Date: Tue, 21 Jan 2020 13:08:02 +0000 Subject: [chuck-users] Conversion float to int using SndBuf 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
---------- Forwarded message ---------- From: Michael Heuer
To: ChucK Users Mailing List Cc: Bcc: Date: Tue, 21 Jan 2020 09:35:12 -0600 Subject: Re: [chuck-users] Conversion float to int using SndBuf 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@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@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
---------- Forwarded message ---------- From: ermina
To: chuck-users@lists.cs.princeton.edu Cc: Bcc: Date: Tue, 21 Jan 2020 16:47:40 +0100 Subject: Re: [chuck-users] Conversion float to int using SndBuf Hi, to convert a float to an int, you need to explicitly cast the value with 4.8 $ int => int foo; // foo == 4 (as written here: https://chuck.cs.princeton.edu/doc/language/oper.html)
So you would do something like pctPosInit $ int => int pctPosInitInt pctPosInitInt/100*myBuf.samples() => myBuf.pos;
. e On 01/21/2020 02:08 PM, Mícheál Ó Catháin 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@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
---------- Forwarded message ---------- From: Jean Menezes da Rocha
To: ChucK Users Mailing List Cc: Bcc: Date: Tue, 21 Jan 2020 12:58:36 -0300 Subject: Re: [chuck-users] Conversion float to int using SndBuf I would suggest that you call Math.round() before casting, as to prevent undesirable effects: notice that in the example sent by ermina, 4.8 rounds down to 4 when cast to int, which could cause miscalculations *depending on your use case*. The previous example would look something like this if we used Math.round(): Math.round(pctPosInit) $ int => int pctPosInitInt; pctPosInitInt/100*myBuf.samples() => myBuf.pos;
Best regards!
On Tue, Jan 21, 2020 at 12:49 PM ermina
wrote: Hi,
to convert a float to an int, you need to explicitly cast the value with 4.8 $ int => int foo; // foo == 4 (as written here: https://chuck.cs.princeton.edu/doc/language/oper.html)
So you would do something like pctPosInit $ int => int pctPosInitInt pctPosInitInt/100*myBuf.samples() => myBuf.pos;
. e On 01/21/2020 02:08 PM, Mícheál Ó Catháin 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@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Jean Menezes da Rocha _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users