Author |
Message |
Acoustic Interloper

Joined: Jul 07, 2007 Posts: 2073 Location: Berks County, PA
Audio files: 89
|
Posted: 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 . . . |
 |
|
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.
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
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sat Jun 14, 2008 9:45 am Post subject:
|
 |
|
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
|
|
 |
Acoustic Interloper

Joined: Jul 07, 2007 Posts: 2073 Location: Berks County, PA
Audio files: 89
|
Posted: Sat Jun 14, 2008 1:38 pm Post subject:
|
 |
|
That helped, thanks! _________________ When the stream is deep
my wild little dog frolics,
when shallow, she drinks. |
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 14, 2008 4:31 pm Post subject:
|
 |
|
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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Sat Jun 14, 2008 4:35 pm Post subject:
|
 |
|
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
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sat Jun 14, 2008 5:35 pm Post subject:
|
 |
|
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
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Sun Jun 15, 2008 5:00 am Post subject:
|
 |
|
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
|
|
 |
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sun Jun 15, 2008 8:47 am Post subject:
|
 |
|
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
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Sun Jun 15, 2008 10:50 am Post subject:
|
 |
|
Thanks guys, you be edgeukatin' me brain again! _________________ "Let's make noise for peace." - Kijjaz |
|
Back to top
|
|
 |
|