Inventor
Stream Operator
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Thu Mar 26, 2009 7:55 am Post subject:
Prototyping EChucK in ChucK Subject description: Examples of how to do it, explained. |
|
|
Hello again,
As an intro to programming in ChucK for EChucK purposes, I thought I would write up a description of the "Matt Belamy of Muse" Fuzz program that I wrote. It takes a guitar input connected to the line-in jack of the computer and does a Fuzz effect on it. Here is the code:
Code: |
// Fuzz Test Code
// Copyright 2009 Les Hall
// This software is protected by the GNU General Public License
// the patch
//
// automatic gain control
adc => Gain div1;
adc => FullRect fwr1 => LPF f1 => Gain add1 => div1;
Step step1 => add1;
4 => div1.op;
20 => f1.freq;
0.2 => step1.next;
1.0 => adc.gain;
//
// distortion
div1 => Gain div2 => dac;
div1 => FullRect fwr2 => Gain add2 => div2;
Step step2 => add2;
4 => div2.op;
0.02 => step2.next; // set level of distortion (less is more)
// time loop
while (true) {
second => now;
}
|
There are three sections to the code, the AGC (automatic gain control), the distortion (or Fuzz), and the time loop. I will describe these in detail.
In the AGC section the first three lines are the patch. This is where we hook up the UGens that perform the AGC. They are a divider and a signal level calculator. Then the last four lines of this section are the patch parameters. Those lines configure the UGens so they do what we wanat them to do. How it all works is as follows:
The input signal goes into the div1 divider which divides it by a slowly changing signal level value produced in the second line by a rectifier followed by a low-pass filter which gives the envelope of the signal. Then a step1 value is added to that signal level so the AGC doesn't go nuts when there is no signal. The div1.op line tells div1 to be a divider, the f1.freq line sets the f1 cutoff frequency, the step1.next line sets the maximum level of AGC, and the adc.gain line sets the input gain.
The net result is the input signal being divided by a 20 Hz envelope of itself, which is a crude form of AGC.
In the distortion section the first three lines implement the equation:
Code: |
dac = div1 / (step2 +|div1|)
|
which does a soft distortion, or fuzz of the signal. Once again the div2 line sets the divider to be a divider, and then the step2 line sets the level of severity of the fuzz effect.
Then finally we need to tell ChucK to loop forever in time, which is done with an infinite loop that advances time inside of it.
You can test this code with or without a guitar. With a guitar you just jack into the line-in Jack using a 1/4" to 1/8" adapter and play your guitar into it. Without a guitar you use your computer's microphone and talk, sing, whistle or hum into the microphone. You will hear your voice with the fuzz effect applied.
This program is a software prototype of a dsPIC implementation of the algorithm because all of the UGen operations are implementable in the dsPIC chip. This is powerful because it permits us to software prototype and share files over the web and so forth before going through the much more difficult process of actually programming a chip and testing it.
The program file is in the sticky thread called "EChucK Files", which is the open source repository. Enjoy! _________________ "Let's make noise for peace." - Kijjaz |
|