electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
Live streaming at radio.electro-music.com

  host / artist show at your time
  Faux Pas Quartet and friends Music From Last Thursday
Please visit the chat
 Forum index » DIY Hardware and Software » ChucK programming language
Casting time or dur to a float or int.
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
jbum



Joined: Oct 24, 2006
Posts: 26
Location: Los Angeles

PostPosted: Sat Nov 04, 2006 12:04 am    Post subject: Casting time or dur to a float or int. Reply with quote  Mark this post and the followings unread

I'd like to be able to compute a parameter for Math.sin() that is based on the passage of time, but thus far, my attempts to put times or durations into floats or ints haven't worked.

Is there a way to do something like this?

Code:

SinOsc voc => dac;
now => time startTime;
// time elapses...
now - startTime => dur elapsed;

// THIS IS THE PROBLEM LINE...
(Math.sin(Math.pow(elapsed,2)) *1000 + 20) => voc.freq;


I realize I can accomplish this using a SinOsc instead of Math.sin, but nonetheless, it would be nice to be able to use time as a parameter for Math functions...

_________________
<a href="http://www.krazydad.com/">krazydad.com</a>
Back to top
View user's profile Send private message Visit poster's website
ge



Joined: Aug 13, 2006
Posts: 105
Location: Palo Alto, CA

PostPosted: Sat Nov 04, 2006 2:36 am    Post subject: Re: Casting time or dur to a float or int. Reply with quote  Mark this post and the followings unread

jbum wrote:
I'd like to be able to compute a parameter for Math.sin() that is based on the passage of time, but thus far, my attempts to put times or durations into floats or ints haven't worked.

Is there a way to do something like this?


Sure can, I think. It's all about making the unit come out. Just divide the duration or even time value by any duration, and get the result as float.

Code:
Math.sin(Math.pow(elapsed/ms, 2)) => ...


One can also compute the sample rate this way.

Code:
 <<< "sample rate:", second/samp >>>;


Hope this helps.

Ge!
Back to top
View user's profile Send private message Visit poster's website
cbit



Joined: Dec 01, 2005
Posts: 35

PostPosted: Fri Nov 06, 2009 3:45 am    Post subject: Reply with quote  Mark this post and the followings unread

I'm trying to convert a duration to a float representig a number of milliseconds. Here's my first confused attempt to do this based on the comments above:

Code:
10::ms=>dur d;
d/1.0 => float f;


"cannot resolve operator '=>' on types 'dur' and 'float'"

Any help would be appreciated!

Edit:

Ah! now i understand the use of the built in ms type to do the conversion. The following works:

Code:
10::ms=>dur d;
d/ms => float f;
<<< f >>>;

_________________
http://basementhum.blogspot.com
Back to top
View user's profile Send private message Visit poster's website
Antimon



Joined: Jan 18, 2005
Posts: 3744
Location: Sweden
Audio files: 277
G2 patch files: 97

PostPosted: Fri Nov 06, 2009 4:46 am    Post subject: Reply with quote  Mark this post and the followings unread

Syntaxwise, I think you can look at a solitary <time unit> (what I'm calling time unit is what's after the double colon in expressions like 2::second or 365::day - second and day respectively) as shorthand for 1::<time unit>. I.e., this is a valid expression:

Code:
second => now;


And since a duration divided by another duration always yields a float result, myTime/second will convert myTime from a ChucK duration to an amount of seconds as a float. This is also useful if you want to divide time into a count of some other arbitrary length in time, you can do that similarly:

Code:
myTime/250::ms => float beatCount;


I do this a lot when coding sequencers in ChucK.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
cbit



Joined: Dec 01, 2005
Posts: 35

PostPosted: Fri Nov 06, 2009 4:49 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks for the additional information stefan, that's clearer now.
_________________
http://basementhum.blogspot.com
Back to top
View user's profile Send private message Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Fri Nov 06, 2009 11:56 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks everyone and thanks to Ge also.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use