Yeah, now it's clear. thank you very much<br><br><div class="gmail_quote">On Tue, Sep 25, 2012 at 9:58 PM, Rich Caloggero <span dir="ltr"><<a href="mailto:rjc@mit.edu" target="_blank">rjc@mit.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If I just want to do a really stupid thing like a Sine at 220 Hz that sounds for 2 seconds and then stops for 2 seconds and then goes again. How could I do?<br>
</blockquote>
<br>
<br></div>
// define connection<div class="im"><br>
SinOsc s => dac;<br>
.2 => s.gain;<br>
220 => s.freq;<br>
<br></div>
// now we let the machine run for two seconds producing the sine wave<br>
2::second => now;<br>
<br>
// now we let it run for two seconds, producing no sound<div class="im"><br>
0 => s.gain;<br>
2::second => now;<br>
<br></div>
// ... and again for two seconds producing a tone<br>
.2 => s.gain;<br>
2::second => now;<br>
<br>
The secret is in the "=>' operator. Its not strictly an assignment when its second argument is the now keyword.  What this is doing is essentially suspending your code for the indicated amount of time and letting the Chuck virtual machine compute the samples and send them to the dac.<br>

<br>
When you use looping is when you want to modify some of the parameters of the thing being computed in realtime.  In that case, you generally loop and each time around the loop you change parameters, then set now to some value, say .1 second. This then would suspend your code for .1 seconds each time around the loop. When your code regains control, you change parameters and then suspend it again and let Chuck compute.  So, for instance:<br>

<br>
// using same connection graph as above:<br>
<br>
while (true) {<br>
s.freq + .1 => s.freq;<br>
.1::second => now;<br>
} // while<br>
<br>
Hope this helps ...<br>
-- Rich<br>
<br>
<br>
From: Alberto Alassio<br>
Sent: Tuesday, September 25, 2012 3:36 PM<br>
To: <a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.<u></u>princeton.edu</a><br>
Subject: [chuck-users] Looping<div><div class="h5"><br>
<br>
I cannot understand how the while structure has to be used. I mean, I understood that while ( true ) means infinite loop<br>
and also that while ( n::second => now ) means an "n" second loop duration but...<br>
<br>
If I just want to do a really stupid thing like a Sine at 220 Hz that sounds for 2 seconds and then stops for 2 seconds and then goes again.<br>
How could I do? I thought that it was necessary just to do something like this<br>
<br>
SinOsc s => dac;<br>
.2 => s.gain;<br>
220 => s.freq;<br>
while ( 2::second => now)<br>
0 =>s.gain<br>
<br>
but I know that it's not the right way, also because in this method I would have to rewrite this thing an infinite ( whiletrue ahahah) number of times to have what I'm looking for.<br>
<br>
And I don't actually understand {} . How am I supposed to use these?<br>
<br>
Thanks<br>
<br></div></div>
______________________________<u></u>_________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.<u></u>princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.<u></u>edu/mailman/listinfo/chuck-<u></u>users</a> <br>
______________________________<u></u>_________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.<u></u>princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.<u></u>edu/mailman/listinfo/chuck-<u></u>users</a><br>
</blockquote></div><br>