On 7/30/06, <b class="gmail_sendername">Ollie Glass</b> &lt;<a href="mailto:ollieglaskovik@gmail.com">ollieglaskovik@gmail.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'd love a compression effect in ChucK. Any chance of adding one as<br>an object, or can anyone make one with a script?</blockquote><div><br><br>Yes, you could make one but I never tried making a compressor without a pre build envelope follower. Having a&nbsp; envelope follower would be nice.
<br><br>The basic idea is this;&nbsp; you set the&nbsp; &quot;treshold level&quot; by defining some value. If the envelope follower (that tracks the input signal) goes over that level you start multiplying the signal's gain by some value that's less then 1 (yet more then what would push it below this treshold). How strongly you do this forms the compressor's &quot;ratio&quot;, 
b.t.w.<br><br>The tricky bit is that if you do this dynamic (signal dependant) gain controll too rapidly you get a overdrive/ saturator type thing. If you do it too slowly you get a compressor that's not very usefull. Those settings form the attack and release of the compressor.
<br><br>Anyway, that's roughly it; a variable gain, a envelope follower and a way to compare the envelope follower to values (this can also get you a expander or a leveling amp or whatever). The one bit we are missing to DIY these is the envelope follower so I think I'd instead propose having one of those. I'm certain somebody more at home in DSP then I am could do one i'n a few lines but I also suspect those would be cpu heavy lines.
<br><br>If nobody else gives it a go I'll refresh my memory and try in a few days. Oh, and once more; sample rate multiplications work way faster if done with a gain set to multiply instead of a code loop, I'd strongly recomend that anybody trying to build a compressor uses that because the alternative is three or four times as expensive.
<br></div><br></div><br>Hope that helps a little?<br><br>Kas.<br>