electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
using a .WAV file as an envelope.
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [10 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
electroboz



Joined: Nov 29, 2006
Posts: 25
Location: Lyndonville VT USA
Audio files: 2
G2 patch files: 6

PostPosted: Fri Dec 08, 2006 3:00 pm    Post subject: using a .WAV file as an envelope.
Subject description: my first useful chuck program.
Reply with quote  Mark this post and the followings unread

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


env.wav
 Description:

Download
 Filename:  env.wav
 Filesize:  85.33 KB
 Downloaded:  886 Time(s)


env.ck
 Description:

Download
 Filename:  env.ck
 Filesize:  1.28 KB
 Downloaded:  629 Time(s)

Back to top
View user's profile Send private message Visit poster's website MSN Messenger
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Mon Dec 11, 2006 8:15 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Tue Dec 12, 2006 4:27 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Tue Dec 12, 2006 9:21 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Tue Dec 12, 2006 10:10 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Tue Dec 12, 2006 10:34 am    Post subject: Reply with quote  Mark this post and the followings unread

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 Smile

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
electroboz



Joined: Nov 29, 2006
Posts: 25
Location: Lyndonville VT USA
Audio files: 2
G2 patch files: 6

PostPosted: Tue Dec 12, 2006 3:52 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website MSN Messenger
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Wed Dec 13, 2006 2:50 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Dec 13, 2006 2:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Wed Dec 13, 2006 3:05 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [10 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use