Author |
Message |
electroboz
Joined: Nov 29, 2006 Posts: 25 Location: Lyndonville VT USA
Audio files: 2
G2 patch files: 6
|
Posted: Fri Dec 08, 2006 3:00 pm Post subject:
using a .WAV file as an envelope. Subject description: my first useful chuck program. |
|
|
this is one of my first chuck programs above and beyond the examples.
it requires that env.wav be in the same directory as the source.
env.wav is simply a short envelope i recorded with my nord g2 and trimmed in audacity. comments and critique welcome.
it is a workable solution to this thread
http://electro-music.com/forum/topic-12841.html
Description: |
|
Download |
Filename: |
env.wav |
Filesize: |
85.33 KB |
Downloaded: |
887 Time(s) |
Description: |
|
Download |
Filename: |
env.ck |
Filesize: |
1.28 KB |
Downloaded: |
629 Time(s) |
|
|
Back to top
|
|
|
spencer
Joined: Aug 16, 2006 Posts: 53 Location: northern california
|
Posted: Mon Dec 11, 2006 8:15 pm Post subject:
|
|
|
Hi electroboz,
this looks really useful. Though looking through your code, you might find the following aspect of ugens useful for improving the performance of your patch.
All ugens have a .op parameter, which specifies how they deal with multiple inputs. the default is for the ugen to just add multiple inputs, but specifying 3 for .op will cause the ugen to multiply its inputs together. Since this happens "below the hood" so to speak its a lot better CPU-wise than multiplying in ChucK, with the added benefit of being updated every sample.
spencer |
|
Back to top
|
|
|
kijjaz
Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Tue Dec 12, 2006 4:27 am Post subject:
|
|
|
oh.. i've just checked out your patch..
yes.. i also recommend using .op .. (you can read it in Gain section)
i usually use a Gain to apply this type of envelope.
more convenient and less codes. |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Tue Dec 12, 2006 9:21 am Post subject:
|
|
|
spencer wrote: |
All ugens have a .op parameter, which specifies how they deal with multiple inputs. the default is for the ugen to just add multiple inputs, but specifying 3 for .op will cause the ugen to multiply its inputs together. Since this happens "below the hood" so to speak its a lot better CPU-wise than multiplying in ChucK, with the added benefit of being updated every sample.
|
Hmmmm, the manual only mentions -1, 0 and 1 as .op functions that all ugens have. Sounds like a issue for the manual-erata on the Wiki? _________________ Kassen |
|
Back to top
|
|
|
spencer
Joined: Aug 16, 2006 Posts: 53 Location: northern california
|
Posted: Tue Dec 12, 2006 10:10 am Post subject:
|
|
|
Kassen wrote: | Sounds like a issue for the manual-erata on the Wiki? |
yeah, definitely. duly noted, thanks! In case anyone was looking for docs on this, see the ugen page:
http://chuck.cs.princeton.edu/doc/language/ugen.html
Also, two pages later in the ChucK manual, the manual contradicts itself by describing all 6 valid values of .op (in the Gain reference), when just before it had listed only 3...
spencer |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Tue Dec 12, 2006 10:34 am Post subject:
|
|
|
Ok, I documented it.
I didn't see the manual as contradicting itself myself; I figured that Gain had some features not found in other Ugens which seemed natural since most Ugens have features not found elsewhere. that might've been naive _________________ Kassen |
|
Back to top
|
|
|
electroboz
Joined: Nov 29, 2006 Posts: 25 Location: Lyndonville VT USA
Audio files: 2
G2 patch files: 6
|
Posted: Tue Dec 12, 2006 3:52 pm Post subject:
|
|
|
thanks for the feedback. i'm just getting back into programming (thanks in no small part to chuck).
I didn't know about the .op functionality, but i do now, thank you =).
The reason I didn't apply the envelope to the gain ugen (but did to the oscillator's.gain) was so I could add more oscillators to the gain object and not have them all follow just one envelope, and still retain 1 easy volume control.
That was by no means a finished "product". I intend to write a class for this type of thing. It was really just a demo to see if i could do it.
You guys are really helpful. Thanks! |
|
Back to top
|
|
|
kijjaz
Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Wed Dec 13, 2006 2:50 pm Post subject:
|
|
|
i usually use a Gain ugen to apply envelope
because when i'm working with an oscillator as the source
(before applying amplitude envelope)
i might have to chuck the oscillator with some other signal
(for frequency set / phasemod / fm as in syncing)
for example, here.. i wanna have 1 sine osc FMing another sine osc
and i wanna apply envelopes to both oscs' amplitude.
i've gotto do this.
Code: | // SinOsc (with gain envelope) FMing SinOsc (with gain envelope) to dac
SinOsc s1 => Gain g1 => SinOsc s2 => Gain g2 => dac;
// a phasor sets gain of the modulating oscillator
Phasor LFO1 => g1;
// Gain method = multiply (for use as an envelope)
// modulating oscillator frequency = 1100hz
// modulation index = 500
// LFO rate = 2hz
3 => g1.op;
1100 => s1.freq;
500 => s1.gain;
2 => LFO1.freq;
// envelope 1 (for setting volumn) to low-pass filter (to smooth the volumn change
// .. this will be the amplitude envelope of the carrier oscillator
Step env1 => LPF f1 => g2;
// s2 will be FMed by amplitude-enveloped s1's signal
// Gain method = multiply (for use as an envelope)
// low-pass center frequency for the amplitude control value = 5hz
2 => s2.sync;
3 => g2.op;
5 => f1.freq;
// try changing the main env value over time..
// the main LFO, FM mechanism works automatically.
while(true) {
0.7 => env1.next;
3::second => now;
0.0 => env1.next;
0.5::second => now;
} |
anyway, actually this patch can be adjusted to the way electroboz apply to an osc..
Code: | // the difference is here:
// we chuck both s1 and LFO1 directly into s2
// and set s2's gain option to 3 (multiply)
// so we don't have to use gain number 1 anymore.
// it works well, and it looks clean..
// but this way is still not flexible for future changes in code.
SinOsc s1 => SinOsc s2 => Gain g2 => dac;
Phasor LFO1 => s2;
3 => s2.op;
1100 => s1.freq;
500 => s1.gain;
2 => LFO1.freq;
Step env1 => LPF f1 => g2;
2 => s2.sync;
3 => g2.op;
5 => f1.freq;
while(true) {
0.7 => env1.next;
3::second => now;
0.0 => env1.next;
0.5::second => now;
} |
but i still stick with using Gain
coz i think it's more flexible..
for example, we can chuck some more signals into an oscillator
so that it can use another gain option that's set in that oscillator. |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Dec 13, 2006 2:57 pm Post subject:
|
|
|
Another advantage of Gain is that it can help a lot with readability. I like calling Gain's stuff like "mixer" or "muter" and for me that helps in keeping it all managable, I also find it helps when later replacing parts of the strucutre.
It's still good that we discovered another bit of missing documention. _________________ Kassen |
|
Back to top
|
|
|
kijjaz
Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Wed Dec 13, 2006 3:05 pm Post subject:
|
|
|
example change in the code
that make use of the flexibility i was talking about:
Code: | SinOsc s1 => Gain g1 => SinOsc s2 => Gain g2 => dac;
Phasor LFO1 => g1;
3 => g1.op;
1100 => s1.freq;
500 => s1.gain;
2 => LFO1.freq;
Step env1 => LPF f1 => g2;
2 => s2.sync;
3 => g2.op;
5 => f1.freq;
// add a (low-pass)filtered noise to the FMing of s2
Noise s3 => LPF f2 => Gain g3 => s2;
800 => s3.gain;
30 => f2.freq;
3 => g3.op;
// use a phasor as an envelope for the noise
Phasor LFO2 => g3;
0.2 => LFO2.freq;
while(true) {
0.7 => env1.next;
3::second => now;
0.0 => env1.next;
0.5::second => now;
} |
|
|
Back to top
|
|
|
|