[chuck-users] my first chuck program

Robert Poor rdpoor at gmail.com
Thu Mar 28 14:19:07 EDT 2013

```Rustom:

Welcome to a lifetime of happy ChucK, but be warned: it can be addictive.

If you're willing to accept a somewhat pre-packaged answer, take a
look at the Blit, BlitSaw and BlitSquare unit generators -- with a
single unit generator, you can generate any number of harmonics.

Also, if you want to hear the effect of adding harmonics, you probably
want to wait after adding each one rather than adding them all at
once.

Uh, my ChucK chops are rusty -- someone else will have to debug my
code, but try this:

6 => int N;
Blit blit => dac;  // or BlitSaw or BlitSquare
440.0 => blit.freq;
0.5 => blit.gain;
for (1 => int harmonics; i <= N; i++) {
harmonics => blit.harmonics;
1.5::second => now;
}
blit =< dac;

On Thu, Mar 28, 2013 at 10:51 AM, Rustom Mody <rustompmody at gmail.com> wrote:
> Ive just written a chuck program (my first!) to demo harmonics
>
> If there is some way I could write the code better, Id like to know.
>
> Also from the audio POV can I do better?
> Basically I want to show that as I change N from 1 upto 6 the pure sine wave
> moves from sounding very mathematical/electrical to sounding more musical
> Any ideas to make it more convincing?
>
>
> Code
> --------
> 8 => int N;
> SinOsc s[N];
> [.45,.3,.2,.1,.05,.03,.02,.01] @=> float gains[];
> 440.0 => float freq;
> for (0 => int i; i < N;i++)
> {
>   s[i] => dac;
>   freq => s[i].freq;
>   gains[i] => s[i].gain;
>   440.0 +=> freq;
> }
>
> 1.5::second => now;
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
```