diff --git a/Source/Processors/CAR/CAR.cpp b/Source/Processors/CAR/CAR.cpp new file mode 100644 index 0000000000000000000000000000000000000000..51e8c054ffb1407e51cea2509098947a229e21fe --- /dev/null +++ b/Source/Processors/CAR/CAR.cpp @@ -0,0 +1,81 @@ + +/* + ------------------------------------------------------------------ + + This file is part of the Open Ephys GUI + Copyright (C) 2014 Open Ephys + + ------------------------------------------------------------------ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +*/ + + + + +#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)); + +} + +CAR::~CAR() +{ + +} + + + +void CAR::setParameter(int parameterIndex, float newValue) +{ + editor->updateParameterButtons(parameterIndex); + // std::cout << "Setting CAR Gain" << std::endl; + + if (currentChannel >= 0) + { + Parameter& p = parameters.getReference(parameterIndex); + p.setValue(newValue, currentChannel); + } +} + +void CAR::process(AudioSampleBuffer& buffer, + MidiBuffer& events, + int& nSamples) +{ + int nChannels=buffer.getNumChannels(); + for (int i = 0; i < nSamples; i++) + { + float average=0; + for (int j = 0; j < (nChannels); j++) + { + average=average+buffer.getSample(j, i); + } + average=average/nChannels; + + for (int j = 0; j < nChannels; j++) + { + float gain=getParameterVar(0, j); + // Subtract from sample + float subtracted=(buffer.getSample(j,i)*(1+(1/nChannels*gain/100))-average*gain/100); + buffer.setSample(j,i, subtracted); + } + } +} diff --git a/Source/Processors/CAR/CAR.h b/Source/Processors/CAR/CAR.h new file mode 100644 index 0000000000000000000000000000000000000000..97bdaaba6ee9095d1825cccbeec927bc22498d09 --- /dev/null +++ b/Source/Processors/CAR/CAR.h @@ -0,0 +1,98 @@ +/* + ------------------------------------------------------------------ + + This file is part of the Open Ephys GUI + Copyright (C) 2014 Open Ephys + + ------------------------------------------------------------------ + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#ifndef CAR_H_INCLUDED +#define CAR_H_INCLUDED + + +#ifdef _WIN32 +#include <Windows.h> +#endif + +#include "../../JuceLibraryCode/JuceHeader.h" +#include "../GenericProcessor/GenericProcessor.h" + +/** + + 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 + + +*/ + +class CAR : public GenericProcessor + +{ +public: + + /** The class constructor, used to initialize any members. */ + CAR(); + + /** The class destructor, used to deallocate memory */ + ~CAR(); + + /** Determines whether the processor is treated as a source. */ + bool isSource() + { + return false; + } + + /** Determines whether the processor is treated as a sink. */ + bool isSink() + { + return false; + } + + /** Defines the functionality of the processor. + + The process method is called every time a new data buffer is available. + + Processors can either use this method to add new data, manipulate existing + data, or send data to an external target (such as a display or other hardware). + + Continuous signals arrive in the "buffer" variable, event data (such as TTLs + and spikes) is contained in the "events" variable, and "nSamples" holds the + number of continous samples in the current buffer (which may differ from the + size of the buffer). + */ + void process(AudioSampleBuffer& buffer, MidiBuffer& events, int& nSamples); + + /** 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); + +private: + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CAR); + +}; + + + + +#endif // CAR_H_INCLUDED