Error: 'release' cannot be used as a function

Status
Not open for further replies.

nickdbot

New member
I'm working on an audio effect object to do sidechained compression sounds. I've written the code, placed the .cpp and .h files in the Audio library folder, but now run into an issue where every time I try to compile any Teensyduino program that includes the Audio library header (for instance, the Delay example), I get this error:
Code:
/Applications/Arduino 2.app/Contents/Java/hardware/teensy/avr/libraries/Audio/effect_sidechain.cpp:104:23: error: 'release' cannot be used as a function
     release(block_read);

I've tried looking at all the other effect code examples and cannot for the life of me figure out why the compiler doesn't like me using the release function when it's used the same way in every other example I saw, so I imagine it's the result of something less obvious, like maybe where I placed the files in the library? Any help is appreciated. Thanks.

Here's the source code:

Code:
//effect_sidechain.cpp
#include "effect_sidechain.h"
#include <math.h>

void AudioEffectSidechain::setParameter(int param_index, int param_val)
{
    switch(param_index) {
        case(0) : thresh_val = param_val;
            break;
        case(1) : ratio_val = param_val;
            break;
        case(2) : attack_val = param_val;
            break;
        case(3) : release_val = param_val;
            break;
    }
    
}

float AudioEffectSidechain::getParameter(int param_index)
{
    float return_val = 0;
    
    switch(param_index) {
        case(0) : return_val = thresh_val;
            break;
        case(1) : return_val = ratio_val;
            break;
        case(2) : return_val = attack_val;
            break;
        case(3) : return_val = release_val;
            break;
    }
    
    return return_val;
}


void AudioEffectSidechain::update(void)
{
    int i = 0;
    audio_block_t *block_comp;
    audio_block_t *block_read;
    block_read = receiveWritable(1); //this is the sidechained signal
    block_comp = receiveWritable(0); //this is the signal to be compressed
    
    float thresh = getParameter(0);
    float ratio = getParameter(1);
    float attack = getParameter(2);
    float release = getParameter(3);
    float x_dB = 0;
    float alpha_a = exp(-log(9)/(AUDIO_SAMPLE_RATE*attack));
    float alpha_r = exp(-log(9)/(AUDIO_SAMPLE_RATE*release));
    
    for( i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
        
        //convert read signal to dB
        block_read->data[i] = 20*log10(block_read->data[i]);
        
        //calculate new gain for block_comp
        if(block_read->data[i] >= thresh) {
            x_dB = ((ratio*thresh+block_read->data[i]-thresh)/block_read->data[i]);
            //compute gain
            block_read->data[i] = block_read->data[i] - x_dB;
        }
        //smooth gain
        if(block_read->data[i] > prev_val) {
            block_read->data[i] = alpha_a*prev_val+(1-alpha_a)*block_read->data[i];
        }
        else {
            block_read->data[i] = alpha_r*prev_val+(1-alpha_r)*block_read->data[i];
        }
        //write over previous value for next cycle
        prev_val = block_read->data[i];
        
        //convert back to linear units
        block_read->data[i] = pow(10,block_read->data[i]/20);
        
        //multiply comp block by new gain
        block_comp->data[i] = block_comp->data[i] * block_read->data[i];
        
    }
    release(block_read);
    transmit(block_comp,0);
    transmit(block_comp,1);
    release(block_comp);
}

Code:
/* Audio Library for Teensy 3.X
 * Copyright (c) 2017, Nick (nickdbot)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef effect_sidechain_h_
#define effect_sidechain_h_

#include "Arduino.h"
#include "AudioStream.h"

class AudioEffectSidechain : public AudioStream {
public:
    AudioEffectSidechain() : AudioStream(2, inputQueueArray)
    { }
    virtual void update(void);
    virtual void setParameter(int param_index, int param_val);
    virtual float getParameter(int param_index);
    
private:
    audio_block_t *inputQueueArray[2];
    float thresh_val, ratio_val, attack_val, release_val;
    float prev_val = 0;
    };
    
#endif
 
Status
Not open for further replies.
Back
Top