electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
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 
 Forum index » DIY Hardware and Software » ChucK programming language
Trouble coding a simple method call.
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
sir honey



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Sat Feb 03, 2007 9:20 pm    Post subject: Trouble coding a simple method call. Reply with quote  Mark this post and the followings unread

Hi All,

I'm very new to ChucK and looking to make progress and friends here on the forum. I'm confused about many things at this early stage of the game, but maybe somebody would be nice enough to help me with this one snag I can't seem to wrap my head around.

when I code:

SndBuf sam => dac;

"/mysample" => sam.read;

while (true){

Std.rand2f (0.0, sam.samples ) => sam.pos;

sam.play;

1=> sam.loop;

1::second => now;
}

I'm unable to compile the program. now, is this a syntax error that I'm encountering, or a misunderstanding about how the Std.rand2f should function? Forgive my ignorance, I'm pretty new to programming, and have much more of a music background. I would just like to play "mysample" from a different random point in time with each iteration of the loop.

Thanks. I think this forum is a great resource, and I'm glad to participate in this friendly community.

jack
Back to top
View user's profile Send private message
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Sun Feb 04, 2007 12:51 am    Post subject: Reply with quote  Mark this post and the followings unread

Hey there, jack, welcome to ChucK!

There are a few problems I can see. Firstly, the .pos parameter expects an integer, not a float--thus you should use the Std.rand2 function (and change the floating-point 0.0 argument to just an integral 0). Secondly, functions that don't have arguments need an empty set of parentheses. Thus
Code:
sam.samples
should be
Code:
sam.samples()
and
Code:
sam.play
should be
Code:
sam.play()
.

Also, the sam.play() call is actually not necessary--the SndBuf will play of its own accord when you pass time with the 1::second => now;. sam.play() just returns the playback rate, and is functionally the same as sam.rate().

So all in all this revised version should work:

Code:
SndBuf sam => dac;

"/mysample" => sam.read;

while (true){

Std.rand2 (0, sam.samples() ) => sam.pos;

1=> sam.loop;

1::second => now;
}


hope this helps,
spencer
Back to top
View user's profile Send private message
sir honey



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Sun Feb 04, 2007 7:35 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks a lot, Spencer

That does help, and thanks for the welcome!

If I didn't have to work, I'd ChucK all day long.

best,

jack
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 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


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