Skip to content

Lesson 2: set(), triggers and meter_()

npisanti edited this page Feb 15, 2016 · 23 revisions

In this lesson we will learn about more basic functions. Copy again the init app code and be ready to modify it. First we need to declare some modules we will use:

    // pdsp modules
    pdsp::PRNoiseGen noise;
    pdsp::MultiLadder4 filter;
    pdsp::Amp amp;
    pdsp::TriggerControl gate;
    pdsp::ADSR ampEnv;
    pdsp::AHR modEnv;
    pdsp::PitchToFreq p2f;
    pdsp::Processor engine; 

now in the ofApp.cpp code:

void ofApp::patch(){
    gate.out_trig() >> ampEnv.set(0.0f, 50.0f, 1.0f, 700.0f);
                       ampEnv * 0.5f >> amp.in_mod();
                               noise >> amp >> engine.channels[0];
                                        amp >> engine.channels[1;
}

void ofApp::mousePressed(int x, int y, int button){
    gate.trigger(1.0f);
}

void ofApp::mouseReleased(int x, int y, int button){
    gate.off();
}

Compile and run. Now if you click on the app window you should hear a burst of noise, when you release the mouse the noise fade outs to zero in precisely 700ms. Now i will explain what the modules do: pdsp::Amp, in our case amp has two input: in_mod() and in_signal()(the default in). The signal is multiplied for the mod input. You can learn more on why the inputs are different in the documentation. In our case into the in_mod() we have connected a pdsp::ADSR. pdsp::ADSR is and Attack-Decay-Sustain-Release envelope, and it needs an out_trig() patched to its in_trig() (that is also the default input). pdsp::TriggerControl is an object with an out_trig() that can be controlled with thread-safe functions (the ones we have put into the mouse oF functions).

Sometimes in pdsp there are some outputs that should be connected only to output with the same name. If you're not planning on making your own oscillator modules you will mostly just remember about out_trig() and in_trig(). If an input requires an output with a matching name it is specified in the documentation.

Also we have used the set() method of pdsp::ADSR. Set methods let you choose some default values for a module, and sometimes also some extra variables, and return the module ready to be patched so you can use a set() function with a module in a chain. Remember that patching something to an input, even a float number, will disable those default values. In our case we are setting ampEnv's in_attack(), in_decay(), in_sustain(), in_release() default values, but gate.out_trig() is being patched to in_trig() (the default input)