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 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-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).