Author |
Message |
sir honey
Joined: Aug 04, 2006 Posts: 36 Location: NY
|
Posted: Sat Feb 03, 2007 9:20 pm Post subject:
Trouble coding a simple method call. |
 |
|
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
|
|
 |
spencer

Joined: Aug 16, 2006 Posts: 53 Location: northern california
|
Posted: Sun Feb 04, 2007 12:51 am Post subject:
|
 |
|
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 should be and should be .
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
|
|
 |
sir honey
Joined: Aug 04, 2006 Posts: 36 Location: NY
|
Posted: Sun Feb 04, 2007 7:35 am Post subject:
|
 |
|
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
|
|
 |
|