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
How do you ramp a gain?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Acoustic Interloper



Joined: Jul 07, 2007
Posts: 2073
Location: Berks County, PA
Audio files: 89

PostPosted: Sat Jun 14, 2008 9:16 am    Post subject: How do you ramp a gain?
Subject description: Going from current to desired gain in 100 ms . . .
Reply with quote  Mark this post and the followings unread

I am attaching my first attempt at modifying a ChucK program, and I have hit a snag. (Thanks to Inventor for drafting an initial version, which I have now messed up!) The program is attached, but maybe you don't have to read it.

There is a Python program sending lists of

bank(i), oscillatorNumber(i), freq(f), phase(f), leftampl(f), rightampl(f)

to ChucK via OSC. I want to use the left and right amplitude numbers 0.0 .. 1.0 to set gain, but I want to ramp it so gain doesn't change immediately, but rather ramps in 100 msec. I am trying to port a patch from MSP.

I am using an Envelope to ramp the changes in gain, and the Envelope .target is being set corretcty, but the .value() never goes anywhere but 0. Any suggestions?

Thanks.


chesstones.ck
 Description:

Download (listen)
 Filename:  chesstones.ck
 Filesize:  10.03 KB
 Downloaded:  309 Time(s)


_________________
When the stream is deep
my wild little dog frolics,
when shallow, she drinks.
Back to top
View user's profile Send private message Visit poster's website
Frostburn



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Sat Jun 14, 2008 9:45 am    Post subject: Reply with quote  Mark this post and the followings unread

I think you just forgot to chuck your Envelopes to a blackhole.
Everything in ChucK needs to be sample sucked to work.

_________________
To boldly go where no man has bothered to go before.
Back to top
View user's profile Send private message
Acoustic Interloper



Joined: Jul 07, 2007
Posts: 2073
Location: Berks County, PA
Audio files: 89

PostPosted: Sat Jun 14, 2008 1:38 pm    Post subject: Reply with quote  Mark this post and the followings unread

That helped, thanks!
_________________
When the stream is deep
my wild little dog frolics,
when shallow, she drinks.
Back to top
View user's profile Send private message Visit poster's website
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Sat Jun 14, 2008 4:31 pm    Post subject: Reply with quote  Mark this post and the followings unread

Tell you what, AI, one little trick I like to use in my programs is a "running average". Maybe someone else like Frostburn knows the real name for it, but what you do is this:

You have a running average value A that you would like to gradually approach some new value B. You make a varible tau which is a float and usually has a value of 0.99 or 0.995, something like that. Then you do this:

Code:
tau * A + (1.0 - tau) * B => A;


A will exponentially approach the value of B over time.

In your case for a smoothly varying amplitude normalizer, I'd just make a Gain element and a shred spinning on say 10::ms that changes the gain from A to B all the time.

And it's OK if B suddenly changes course at any time, it will just start up a new exponential approach.

Hope that helps. Now on to the rest of my Budweiser!

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Kassen
Janitor
Janitor


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

PostPosted: Sat Jun 14, 2008 4:35 pm    Post subject: Reply with quote  Mark this post and the followings unread

A Sttep followed by a LPF set to something really low will get you the same kind of thing, without the shred, as this can be chucked straight into a Gain set to multiply.

Cheers.

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


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Sat Jun 14, 2008 5:35 pm    Post subject: Reply with quote  Mark this post and the followings unread

Kassen wrote:
A Sttep followed by a LPF set to something really low will get you the same kind of thing, without the shred, as this can be chucked straight into a Gain set to multiply.

Cheers.


Oh, man, I like my tau thingie! But you're right, that would be better.

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Kassen
Janitor
Janitor


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

PostPosted: Sun Jun 15, 2008 5:00 am    Post subject: Reply with quote  Mark this post and the followings unread

Inventor wrote:

Oh, man, I like my tau thingie! But you're right, that would be better.


Well, but your "tau thingie" is a simple LPF as well, I think it's a OnePole. I think that if you use the OnePole with the .pole() function for setting the coefficients you end up with exactly what you have now, except at sample-rate and optimised in C++.

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



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Sun Jun 15, 2008 8:47 am    Post subject: Reply with quote  Mark this post and the followings unread

Inventor wrote:
Maybe someone else like Frostburn knows the real name for it...

That tau thingie is called leaky integrator. I like to use two in a row to get smooth results even with sudden changes in the input.

A running average is a filter that takes the average over a finite number of samples and moves the window as it goes.
Code:
input => OnePole average => blackhole;
input => Delay averageDelay => average;
1.0 => amplitude.b0;
-1.0 => amplitude.a1;
10::ms => dur averageDur => averageDelay.max => averageDelay.delay;
-1.0 => averageDelay.gain;
samp/averageDelay.delay() => average.gain; //normalize

That patch adds the input samples to an accumulator and subtracts them off after some time has passed.

_________________
To boldly go where no man has bothered to go before.
Back to top
View user's profile Send private message
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Sun Jun 15, 2008 10:50 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks guys, you be edgeukatin' me brain again!
_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 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