Skip to content
Snippets Groups Projects
Commit 7eaad3ab authored by Septen's avatar Septen
Browse files

CAR: refactoring and stylystic fixes.

parent 9c6fecbd
Branches
No related tags found
No related merge requests found
......@@ -22,73 +22,69 @@
*/
#include <stdio.h>
#include "CAR.h"
CAR::CAR()
: GenericProcessor("Common Avg Ref") //, threshold(200.0), state(true)
{
parameters.add (Parameter ("Gain (%)", 0.0, 100.0, 100.0, 0));
parameters.add(Parameter("Gain (%)", 0.0, 100.0, 100.0, 0));
avgBuffer = AudioSampleBuffer(1,10000); // 1-dimensional buffer to hold the avg
avgBuffer = AudioSampleBuffer (1, 10000); // 1-dimensional buffer to hold the avg
}
CAR::~CAR()
{
}
void CAR::setParameter(int parameterIndex, float newValue)
void CAR::setParameter (int parameterIndex, float newValue)
{
editor->updateParameterButtons(parameterIndex);
editor->updateParameterButtons (parameterIndex);
// std::cout << "Setting CAR Gain" << std::endl;
if (currentChannel >= 0)
{
Parameter& p = parameters.getReference(parameterIndex);
p.setValue(newValue, currentChannel);
Parameter& p = parameters.getReference (parameterIndex);
p.setValue (newValue, currentChannel);
}
}
void CAR::process(AudioSampleBuffer& buffer,
MidiBuffer& events)
void CAR::process (AudioSampleBuffer& buffer, MidiBuffer& events)
{
int nChannels = buffer.getNumChannels();
const int nChannels = buffer.getNumChannels();
const int numSamples = buffer.getNumSamples();
float gain = -1.0f * float(getParameterVar(0, 0)) / 100.0f; // just use channel 0, since we can't have individual channel settings at the moment
// just use channel 0, since we can't have individual channel settings at the moment
const float gain = -1.0f * float (getParameterVar (0, 0)) / 100.0f;
avgBuffer.clear();
for (int j = 0; j < nChannels; j++)
{
avgBuffer.addFrom(0, // destChannel
0, // destStartSample
buffer, // source
j, // sourceChannel
0, // sourceStartSample
buffer.getNumSamples(), // numSamples
1.0f); // gain to apply
}
for (int channel = 0; channel < nChannels; ++channel)
{
avgBuffer.addFrom (0, // destChannel
0, // destStartSample
buffer, // source
channel, // sourceChannel
0, // sourceStartSample
numSamples, // numSamples
1.0f); // gain to apply
}
avgBuffer.applyGain(1.0f/float(nChannels));
avgBuffer.applyGain (1.0f / float (nChannels));
for (int j = 0; j < nChannels; j++)
for (int channel = 0; channel < nChannels; ++channel)
{
buffer.addFrom(j, // destChannel
0, // destStartSample
avgBuffer, // source
0, // sourceChannel
0, // sourceStartSample
buffer.getNumSamples(), // numSamples
gain); // gain to apply
buffer.addFrom (channel, // destChannel
0, // destStartSample
avgBuffer, // source
0, // sourceChannel
0, // sourceStartSample
numSamples, // numSamples
gain); // gain to apply
}
}
......@@ -36,18 +36,16 @@
This is a simple filter that subtracts the average of all other channels from
each channel. The gain parameter allows you to subtract a percentage of the total avg.
See Ludwig et al. 2009 Using a common average reference to improve cortical
neuron recordings from microelectrode arrays. J. Neurophys, 2009 for a detailed
discussion
See Ludwig et al. 2009 Using a common average reference to improve cortical
neuron recordings from microelectrode arrays. J. Neurophys, 2009 for a detailed
discussion
*/
class CAR : public GenericProcessor
{
public:
/** The class constructor, used to initialize any members. */
CAR();
......@@ -55,16 +53,10 @@ public:
~CAR();
/** Determines whether the processor is treated as a source. */
bool isSource()
{
return false;
}
bool isSource() override { return false; }
/** Determines whether the processor is treated as a sink. */
bool isSink()
{
return false;
}
bool isSink() override { return false; }
/** Defines the functionality of the processor.
......@@ -78,22 +70,20 @@ public:
number of continous samples in the current buffer (which may differ from the
size of the buffer).
*/
void process(AudioSampleBuffer& buffer, MidiBuffer& events);
void process (AudioSampleBuffer& buffer, MidiBuffer& events) override;
/** Any variables used by the "process" function _must_ be modified only through
this method while data acquisition is active. If they are modified in any
other way, the application will crash. */
void setParameter(int parameterIndex, float newValue);
void setParameter (int parameterIndex, float newValue) override;
AudioSampleBuffer avgBuffer;
private:
AudioSampleBuffer avgBuffer;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CAR);
};
#endif // CAR_H_INCLUDED
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment