Changes

Jump to navigation Jump to search
Line 865: Line 865:     
Two sections  
 
Two sections  
# protected:
+
# '''protected:'''
# private:
+
# '''private:'''
       
Protected:
 
Protected:
 
Members declared as protected are accessible within the same class and in derived classes  
 
Members declared as protected are accessible within the same class and in derived classes  
 +
Some functions are declared
 +
 +
Firstly those that return character strings of text (char*)
 +
getLabel() const overide { return "SimpleGain"; }
 +
getDescription()
 +
getMaker()
 +
getLicense()
 +
 +
then a function that returns an unsigned 32 bit integer 0 -> 4 Gig
 +
 +
uint32_t getVersion() const override { return d_version(1, 0, 0); }
 +
 +
and an even more massive number 64 bit integer ( don't ask)
 +
 +
    int64_t getUniqueId() const override { return d_cconst('S', 'G', 'a', 'n'); }
 +
 +
Next we have a function that initializes some Parameters and define a range of values for that handy gain number we'd like to alter.
 +
 +
    void initParameter(uint32_t index, Parameter& parameter) override {
 +
        if (index != 0) return;
 +
        parameter.hints = kParameterIsAutomable;
 +
        parameter.name = "Gain";
 +
        parameter.symbol = "gain";
 +
        parameter.unit = "x";
 +
        parameter.ranges.def = 1.0f;
 +
        parameter.ranges.min = 0.0f;
 +
        parameter.ranges.max = 2.0f;
 +
 +
This applies extra values to the external implementation of this parameter so the two environments can pass data effectively.
 +
 +
index is required to have a value 0 to set these values to what are presumably defaults.
 +
 +
Next we have a Getter & a Setter
 +
 +
    float getParameterValue(uint32_t index) const override {
 +
        if (index != 0) return 0.0f;
 +
        return gain;
 +
    }
 +
 +
    void setParameterValue(uint32_t index, float value) override {
 +
        if (index != 0) return;
 +
        gain = value;
 +
    }
 +
 +
Again requiring a 0 index to operate.
 +
 +
Lastly in the protected section
 +
 +
    void run(const float** inputs, float** outputs, uint32_t frames) override {
 +
        const float* inL = inputs[0];
 +
        const float* inR = inputs[1];
 +
        float* outL = outputs[0];
 +
        float* outR = outputs[1];
 +
 +
        for (uint32_t i = 0; i < frames; ++i) {
 +
            outL[i] = inL[i] * gain;
 +
            outR[i] = inR[i] * gain;
 +
        }
 +
    }
 +
 +
The run function of this class, which will be called by the underlying system to process audio samples appearing at the input and generating appropriate output at the correct time.
 +
 +
i.e. doing the clever stuff between these two...
 +
 +
void run(const float** inputs, float** outputs, uint32_t frames) override
 +
It's defined as a void so it does not return a value, interacting via the arrays passed to it.
 +
 +
The inputs to the tun function are a
 +
an array of inputs
 +
an array of outputs
 +
A frame count. The number of frames in the array.
 +
 +
Don't know what override does.
 +
 +
The arrays are allocated to variables  ( notice the assumption here that we only handle the first two arrays handed to us. How it deals with other arrays is a point of discussion.)
 +
 +
        const float* inL = inputs[0];
 +
        const float* inR = inputs[1];
 +
        float* outL = outputs[0];
 +
        float* outR = outputs[1];
 +
 +
So for each frame we loop a counter i with that numbered frame of audio
 +
 +
        for (uint32_t i = 0; i < frames; ++i) {
 +
 +
and then do stuff
 +
            outL[i] = inL[i] * gain;
 +
            outR[i] = inR[i] * gain;
 +
        }
 +
 +
At the end of the process the out arrays have been filled with the adjusted values from the input arrays. . . .
 +
    
Private:
 
Private:
1,112

edits

Navigation menu