[chuck-users] Global Variables (herman asked)

herman verbaeten hverb54 at hotmail.com
Thu Feb 27 13:28:51 EST 2020


Thanks for your answer Perry,
Do you happen to know something about SndBuf and the members .loop and .interp and how to use them.
Not many chuck users know about them....
thanks in advance!

Kind regards,

herman

________________________________
Van: chuck-users-bounces at lists.cs.princeton.edu <chuck-users-bounces at lists.cs.princeton.edu> namens Perry Cook <prc at cs.princeton.edu>
Verzonden: donderdag 27 februari 2020 17:57
Aan: chuck-users at lists.cs.princeton.edu <chuck-users at lists.cs.princeton.edu>
Onderwerp: Re: [chuck-users] Global Variables (herman asked)

You script got scrubbed for some reason, but I suspect that you’re shadowing
the global somehow locally (if you use the same name as an argument or a
local within a function, it masks the global version).

Here’s a simple example of using a global:

1000 => float freqGlob; // global frequency variable

SinOsc s => dac;  // note that this osc is treated globally as well

spork ~ sweep();

while (true)  {  // main loop randomly (re)sets freq
    Std.rand2f(500.0,3000.0) => freqGlob => s.freq;
    Std.rand2f(0.3,1.0)::second => now;
}

// this shred sweeps the frequency exponentially down
fun void sweep()  {
  while (true)  {
    (0.999*=> freqGlob) => s.freq;
    ms => now;
  }
}

_______________________________________________
chuck-users mailing list
chuck-users at lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20200227/6f44ce73/attachment.html>


More information about the chuck-users mailing list