I cannot understand how the while structure has to be used. I mean, I understood that while ( true ) means infinite loop and also that while ( n::second => now ) means an "n" second loop duration but... 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? I thought that it was necessary just to do something like this SinOsc s => dac; .2 => s.gain; 220 => s.freq; while ( 2::second => now) 0 =>s.gain 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. And I don't actually understand {} . How am I supposed to use these? Thanks
Try this: SinOsc s => dac; while(true) { .2 => s.gain; 220 => s.freq; 2::second => now; 0 =>s.gain; 2::second => now; } --Jeff Albert Assistant Professor (Extraordinary) of Music Industry Studies Loyola University New Orleans Office: Communications/Music Complex 428P Office Phone: (504) 865-2606 Google Voice: (504) 315-5167 jvalbert@loyno.edu (mailto:jvalbert@loyno.edu) http://www.loyno.edu/~jvalbert On Tuesday, September 25, 2012 at 2:36 PM, Alberto Alassio wrote:
SinOsc s => dac; .2 => s.gain; 220 => s.freq; while ( 2::second => now) 0 =>s.gain
understood. thank u
On Tue, Sep 25, 2012 at 9:48 PM, Jeff Albert
Try this:
SinOsc s => dac;
while(true) { .2 => s.gain; 220 => s.freq; 2::second => now; 0 =>s.gain; 2::second => now; }
-- Jeff Albert Assistant Professor (Extraordinary) of Music Industry Studies Loyola University New Orleans Office: Communications/Music Complex 428P Office Phone: (504) 865-2606 Google Voice: (504) 315-5167 jvalbert@loyno.edu http://www.loyno.edu/~jvalbert
On Tuesday, September 25, 2012 at 2:36 PM, Alberto Alassio wrote:
SinOsc s => dac; .2 => s.gain; 220 => s.freq; while ( 2::second => now) 0 =>s.gain
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
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?
// define connection SinOsc s => dac; .2 => s.gain; 220 => s.freq; // now we let the machine run for two seconds producing the sine wave 2::second => now; // now we let it run for two seconds, producing no sound 0 => s.gain; 2::second => now; // ... and again for two seconds producing a tone .2 => s.gain; 2::second => now; 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. 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: // using same connection graph as above: while (true) { s.freq + .1 => s.freq; .1::second => now; } // while Hope this helps ... -- Rich From: Alberto Alassio Sent: Tuesday, September 25, 2012 3:36 PM To: chuck-users@lists.cs.princeton.edu Subject: [chuck-users] Looping I cannot understand how the while structure has to be used. I mean, I understood that while ( true ) means infinite loop and also that while ( n::second => now ) means an "n" second loop duration but... 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? I thought that it was necessary just to do something like this SinOsc s => dac; .2 => s.gain; 220 => s.freq; while ( 2::second => now) 0 =>s.gain 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. And I don't actually understand {} . How am I supposed to use these? Thanks _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Yeah, now it's clear. thank you very much
On Tue, Sep 25, 2012 at 9:58 PM, Rich Caloggero
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?
// define connection
SinOsc s => dac; .2 => s.gain; 220 => s.freq;
// now we let the machine run for two seconds producing the sine wave 2::second => now;
// now we let it run for two seconds, producing no sound
0 => s.gain; 2::second => now;
// ... and again for two seconds producing a tone .2 => s.gain; 2::second => now;
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.
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:
// using same connection graph as above:
while (true) { s.freq + .1 => s.freq; .1::second => now; } // while
Hope this helps ... -- Rich
From: Alberto Alassio Sent: Tuesday, September 25, 2012 3:36 PM To: chuck-users@lists.cs.**princeton.edu
Subject: [chuck-users] Looping I cannot understand how the while structure has to be used. I mean, I understood that while ( true ) means infinite loop and also that while ( n::second => now ) means an "n" second loop duration but...
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? I thought that it was necessary just to do something like this
SinOsc s => dac; .2 => s.gain; 220 => s.freq; while ( 2::second => now) 0 =>s.gain
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.
And I don't actually understand {} . How am I supposed to use these?
Thanks
______________________________**_________________ chuck-users mailing list chuck-users@lists.cs.**princeton.edu
https://lists.cs.princeton.**edu/mailman/listinfo/chuck-**usershttps://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-**usershttps://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Alberto Alassio wrote:
I cannot understand how the while structure has to be used. I mean, I understood that while ( true ) means infinite loop and also that while ( n::second => now ) means an "n" second loop duration but...
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? I thought that it was necessary just to do something like this
SinOsc s => dac; .2 => s.gain; 220 => s.freq; while ( 2::second => now) 0 =>s.gain
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.
And I don't actually understand {} . How am I supposed to use these?
The curly brackets '{' and '}' encapsulate what you would like to loop over with the while construct: SinOsc s => dac; 220.0 => s.freq; while (true) { 0.2 => s.gain; 2::second => now; 0.0 => s.gain; 2::second => now; } Does that make sense? If you want to loop a certain number of times, you can use the for construct, e.g. SinOsc s => dac; 220.0 => s.freq; for (0 => int i; i < 10; i++) { 0.2 => s.gain; 2::second => now; 0.0 => s.gain; 2::second => now; } would loop 10 times. If you want to take this further, with LiCK you can put the part between the {}s into a functor class class Play extends Procedure { SinOsc s => dac; fun void run() { freq => s.freq; 0.2 => s.gain; 2::second => now; 0.0 => s.gain; } } and then use the Loops class to do the looping Play playA; 220.0 => playA.s.freq; Play playC; 130.81278 => playC.s.freq; spork ~ Loops.loop(playA, 2::second, 10).run(); spork ~ Loops.loop(playC, 1::second, 2::second, 10).run(); michael
Ok for the first example, I did that by myself but don't know why it wasn't running but that is what I did, maybe I've just forgotten some ";" or whatelse! Thank you! I don't understand the second one with FOR, what is i++? How would you say that line command? For i starting from 0 then make the sound till i is equal to 10 then stop?
Alberto Alassio wrote:
Ok for the first example, I did that by myself but don't know why it wasn't running but that is what I did, maybe I've just forgotten some ";" or whatelse! Thank you! I don't understand the second one with FOR, what is i++?
i++ is "add one to i"
How would you say that line command? For i starting from 0 then make the sound till i is equal to 10 then stop?
Yes, that is correct. michael
Thank you another time
On Tue, Sep 25, 2012 at 10:28 PM, Michael Heuer
Alberto Alassio wrote:
Ok for the first example, I did that by myself but don't know why it wasn't running but that is what I did, maybe I've just forgotten some ";" or whatelse! Thank you! I don't understand the second one with FOR, what is i++?
i++ is "add one to i"
How would you say that line command? For i starting from 0 then make the sound till i is equal to 10 then stop?
Yes, that is correct.
michael _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
but what if I want to do this with 2 sines? I mean, for example Sineosc s1 that sounds and stop the same freq every 2 second, and another Sineosc thats sound at the same freq every 1 second I can use while true and put everthing in the bracklets. Right? Is it possible to do the same thing also with the For structure you mentioned? And what about sineosc s1 at 220 hz that goes on and off every 2 seconds sineosc s2 that has a random frequency ( std.rand2f for example ) How could I manage this situation with while? I need while ( true ) to make it in an infinite loop but I also need to make the random freq goes on!
Alberto Alassio wrote:
but what if I want to do this with 2 sines?
I mean, for example
Sineosc s1 that sounds and stop the same freq every 2 second, and another Sineosc thats sound at the same freq every 1 second I can use while true and put everthing in the bracklets. Right? Is it possible to do the same thing also with the For structure you mentioned?
And what about
sineosc s1 at 220 hz that goes on and off every 2 seconds sineosc s2 that has a random frequency ( std.rand2f for example ) How could I manage this situation with while? I need while ( true ) to make it in an infinite loop but I also need to make the random freq goes on!
If you do this SinOsc s1 => dac; 220.0 => s1.freq; for (0 => int i; i < 10; i++) { 0.2 => s1.gain; 2::second => now; 0.0 => s1.gain; 2::second => now; } SinOsc s2 => dac; for (0 => int i; i < 10; i++) { Std.rand2f(130.0, 440.0) => s2.freq; 0.2 => s2.gain; 2::second => now; 0.0 => s2.gain; 2::second => now; } then s2 will follow s1. If you want them to go simultaneously, then you'll need to put one or both loops in a function and spork the function call, for example SinOsc s1 => dac; 220.0 => s1.freq; spork ~ loop1(); SinOsc s2 => dac; spork ~ loop2(); <<<"waiting on main shred">>>; 2::minute => now; fun void loop1() { <<<"sporked loop1">>>; for (0 => int i; i < 10; i++) { 0.2 => s1.gain; 2::second => now; 0.0 => s1.gain; 2::second => now; } <<<"loop1 done">>>; } fun void loop2() { <<<"sporked loop2">>>; for (0 => int i; i < 10; i++) { Std.rand2f(130.0, 440.0) => s2.freq; 0.2 => s2.gain; 2::second => now; 0.0 => s2.gain; 2::second => now; } <<<"loop2 done">>>; } michael
Thank you very much, tomorrow I'll look at your lines! Really kind
On Tue, Sep 25, 2012 at 11:37 PM, Michael Heuer
Alberto Alassio wrote:
but what if I want to do this with 2 sines?
I mean, for example
Sineosc s1 that sounds and stop the same freq every 2 second, and another Sineosc thats sound at the same freq every 1 second I can use while true and put everthing in the bracklets. Right? Is it possible to do the same thing also with the For structure you mentioned?
And what about
sineosc s1 at 220 hz that goes on and off every 2 seconds sineosc s2 that has a random frequency ( std.rand2f for example ) How could I manage this situation with while? I need while ( true ) to make it in an infinite loop but I also need to make the random freq goes on!
If you do this
SinOsc s1 => dac; 220.0 => s1.freq; for (0 => int i; i < 10; i++) { 0.2 => s1.gain; 2::second => now; 0.0 => s1.gain; 2::second => now; }
SinOsc s2 => dac; for (0 => int i; i < 10; i++) { Std.rand2f(130.0, 440.0) => s2.freq; 0.2 => s2.gain; 2::second => now; 0.0 => s2.gain; 2::second => now; }
then s2 will follow s1.
If you want them to go simultaneously, then you'll need to put one or both loops in a function and spork the function call, for example
SinOsc s1 => dac; 220.0 => s1.freq; spork ~ loop1();
SinOsc s2 => dac; spork ~ loop2();
<<<"waiting on main shred">>>; 2::minute => now;
fun void loop1() { <<<"sporked loop1">>>; for (0 => int i; i < 10; i++) { 0.2 => s1.gain; 2::second => now; 0.0 => s1.gain; 2::second => now; } <<<"loop1 done">>>; }
fun void loop2() { <<<"sporked loop2">>>; for (0 => int i; i < 10; i++) { Std.rand2f(130.0, 440.0) => s2.freq; 0.2 => s2.gain; 2::second => now; 0.0 => s2.gain; 2::second => now; } <<<"loop2 done">>>; }
michael _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Ok, I have other questions for you! What if I want to loop these loops? I mean, you wrote 2 loops going together that stop when i arrives to his maximum. If I'd like to make something like = s1 and s2 go till i reaches his maximum, then stop for 2 seconds and then restart again. Maybe I could use while (true) to make it? I was trying but I couldn't find a good way to make it. Or maybe I have to make another spork that is a loop containing the others 2 loops?
I've made it in this way: SinOsc s1 => g => dac; 220.0 => s1.freq; spork ~ loop1(); SinOsc s2 => g ; spork ~ loop2(); 0.4 => g.gain ; 0.01 => g.mix; spork ~ loop3(); <<<"waiting on main shred">>>; 2::minute => now; fun void loop3() { for (0 => int ca; ca < 10; ca++) { 0.2 => g.gain; 10::second => now; 0.0 => g.gain; 1::second => now; 0.2 => g.gain; 10::second => now; 0.0 => g.gain; 1::second => now; } } fun void loop1() { <<<"sporked loop1">>>; for (0 => int i; i < 21; i++) { Std.rand2f(130.0, 440.0) => s1.freq; 0.2 => s1.gain; 0.5::second => now; 0.0 => s1.gain; 0.5::second => now; } <<<"loop1 done">>>; } fun void loop2() { <<<"sporked loop2">>>; for (0 => int i; i < 21; i++) { Std.rand2f(130.0, 440.0) => s2.freq; 0.2 => s2.gain; 0.5::second => now; 0.0 => s2.gain; 0.5::second => now; } } Is it a good way, or are there other ways more elegant and simpler?
participants (4)
-
Alberto Alassio
-
Jeff Albert
-
Michael Heuer
-
Rich Caloggero