Skip to content

Commit

Permalink
Merge pull request #1 from PridaLab/working
Browse files Browse the repository at this point in the history
channel numbering now starts with 1
  • Loading branch information
JulioEI authored May 31, 2022
2 parents a97fb58 + c91b4d5 commit e3251ab
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 51 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ For Windows:
The plugin receives N channels as input (2<=N<=7), and interpolate the missing ones with a weighted linear approximation.

![CNN-ripple](ch-interp-plugin.png)
- **Source Channels:** indicates the channels used as a source (>=0) and the desired interpolated ones (-1). Source channels (>=0) will be indicated in orange, whereas the ones that need to be interpolated must be indicated with a -1 (the box will turn grey).
- **Source Channels:** indicates the channels used as a source (>=1) and the desired interpolated ones (-1). Source channels (>=1) will be indicated in orange, whereas the ones that need to be interpolated must be indicated with a -1 (the box will turn grey). Note that channel numbering starts at 1.
- **Recipient Channels:** indicates the channels where the source channels will be saved (one to one mapping).

For instance, in the image provided, the plugin takes channels (0,4,12) and uses them to interpolate the missing 5 channels (2 interpolations between 0&4, 3 interpolations between 4&12). The resulting 8 channels (3 provided, 5 interpolated) are saved in the 0-8 channels.
For instance, in the image provided, the plugin takes channels (1,5,12) and uses them to interpolate the missing 5 channels (2 interpolations between 1&5, 3 interpolations between 5&12). The resulting 8 channels (3 provided, 5 interpolated) are saved in the 1-8 channels.

Note that channels index refers to the practical order. If a Channel Map plugin is used to rearrange the channels, the new order is passed down to this plugin. That is, if a channel map is used to place channel 18 into the first (1) position, then if we want to access that channel for interpolation, we must refer to it in the source channels with index 1.

## Compiling the plugin from source

1. Clone this repository in the same directory where [`plugin-GUI`](https://github.com/open-ephys/plugin-GUI) is located.
1. Clone this repository inside a folder `OEPlugins` in the same directory where [`plugin-GUI`](https://github.com/open-ephys/plugin-GUI) is located.
3. Go to the `Build` directory (<ch_interp_path>/Build/) and execute to create the CMake project:

For Linux:
Expand All @@ -35,7 +37,7 @@ make install

For Windows:
```
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_CXX_FLAGS="/EHsc /utf-8" ..
cmake -G "Visual Studio 16 2019" -A x64 ..
```
Open Visual Studio 16 2019 and compile and install the solution (see notes below on how to install Visual Studio).

Expand Down
20 changes: 10 additions & 10 deletions Source/ChInterp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ using namespace ChInterpSpace;
//Change all names for the relevant ones, including "Processor Name"
ChInterp::ChInterp() : GenericProcessor("Ch-interp")
{
int og_channelArray[8] = {0,-1,-1,3,-1,-1,-1,7};
int to_channelArray[8] = {0,1,2,3,4,5,6,7};
int og_channelArray[8] = {1,-1,-1,4,-1,-1,-1,8};
int to_channelArray[8] = {1,2,3,4,5,6,7,8};

}

Expand Down Expand Up @@ -69,29 +69,29 @@ void ChInterp::process(AudioSampleBuffer& buffer)

for (int ch=0; ch<8; ++ch)
{
if (og_channelArray[ch]> -1) //if channel provided then just reallocate on new place
if (og_channelArray[ch]> 0) //if channel provided then just reallocate on new place
{
int nSamples = getNumSamples(og_channelArray[ch]);
float* toPtr = buffer.getWritePointer(to_channelArray[ch]); //get pointer to new location
int nSamples = getNumSamples(og_channelArray[ch]-1);
float* toPtr = buffer.getWritePointer(to_channelArray[ch]-1); //get pointer to new location
for (int n = 0; n < nSamples; ++n)
{
const float sample = *channelBuffer.getReadPointer (og_channelArray[ch], n); //get value from old location
const float sample = *channelBuffer.getReadPointer (og_channelArray[ch]-1, n); //get value from old location
*(toPtr + n) = sample; //save value to new location
}
}
else //if channel not provided then interpolate
{
int nSamples = getNumSamples(to_channelArray[ch]);
float* toPtr = buffer.getWritePointer(to_channelArray[ch]); //get pointer to memory space to save the interpolated channel
int nSamples = getNumSamples(to_channelArray[ch]-1);
float* toPtr = buffer.getWritePointer(to_channelArray[ch]-1); //get pointer to memory space to save the interpolated channel

int left_ch = leftIndex(og_channelArray, ch); //get closest provided channel on the left
int right_ch = rightIndex(og_channelArray, ch); //get closest provided channel on the right
float dist_ch = right_ch - left_ch; //get distance to do a weighted linear interpolation

for (int n=0; n<nSamples; ++n)
{
const float leftVal = *channelBuffer.getReadPointer (og_channelArray[left_ch], n); //get value of left channel
const float rightVal = *channelBuffer.getReadPointer (og_channelArray[right_ch], n); //get value of right channel
const float leftVal = *channelBuffer.getReadPointer (og_channelArray[left_ch]-1, n); //get value of left channel
const float rightVal = *channelBuffer.getReadPointer (og_channelArray[right_ch]-1, n); //get value of right channel
*(toPtr + n) = leftVal + ((ch - left_ch)/dist_ch)*(rightVal - leftVal); //compute weighted linear interpolation
}

Expand Down
4 changes: 2 additions & 2 deletions Source/ChInterp.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ namespace ChInterpSpace
int left_ch;
int right_ch;
float dist_ch;
int og_channelArray[8] = {0,-1,-1,3,-1,-1,-1,7};;
int to_channelArray[8] = {0,1,2,3,4,5,6,7};;
int og_channelArray[8] = {1,-1,-1,4,-1,-1,-1,8};;
int to_channelArray[8] = {1,2,3,4,5,6,7,8};;
AudioSampleBuffer channelBuffer;
};
}
Expand Down
70 changes: 35 additions & 35 deletions Source/ChInterpEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,84 +13,84 @@ ChInterpEditor::ChInterpEditor(GenericProcessor* parentNode, bool useDefaultPara
ogChannel_label->setColour(Label::textColourId, Colours::white);
addAndMakeVisible(ogChannel_label);

ogChannel_0 = new Label("Og Channel 0", "0");
ogChannel_0 = new Label("Og Channel 1", "1");
ogChannel_0->setBounds(10,45,20,15);
ogChannel_0->setFont(Font("Default", 8, Font::plain));
ogChannel_0->setColour(Label::textColourId, Colours::white);
ogChannel_0->setColour(Label::backgroundColourId, Colours::orange);
ogChannel_0->setEditable(true);
ogChannel_0->addListener(this);
ogChannel_0->setTooltip("Set the source channel 0 for interpolation");
ogChannel_0->setTooltip("Set the source channel 1 for interpolation");
addAndMakeVisible(ogChannel_0);

ogChannel_1 = new Label("Og Channel 1", "-1");
ogChannel_1 = new Label("Og Channel 2", "-1");
ogChannel_1->setBounds(32,45,20,15);
ogChannel_1->setFont(Font("Default", 8, Font::plain));
ogChannel_1->setColour(Label::textColourId, Colours::black);
ogChannel_1->setColour(Label::backgroundColourId, Colours::grey);
ogChannel_1->setEditable(true);
ogChannel_1->addListener(this);
ogChannel_1->setTooltip("Set the source channel 1 for interpolation");
ogChannel_1->setTooltip("Set the source channel 2 for interpolation");
addAndMakeVisible(ogChannel_1);

ogChannel_2 = new Label("Og Channel 2", "-1");
ogChannel_2 = new Label("Og Channel 3", "-1");
ogChannel_2->setBounds(54,45,20,15);
ogChannel_2->setFont(Font("Default", 8, Font::plain));
ogChannel_2->setColour(Label::textColourId, Colours::black);
ogChannel_2->setColour(Label::backgroundColourId, Colours::grey);
ogChannel_2->setEditable(true);
ogChannel_2->addListener(this);
ogChannel_2->setTooltip("Set the source channel 2 for interpolation");
ogChannel_2->setTooltip("Set the source channel 3 for interpolation");
addAndMakeVisible(ogChannel_2);

ogChannel_3 = new Label("Og Channel 3", "3");
ogChannel_3 = new Label("Og Channel 4", "4");
ogChannel_3->setBounds(76,45,20,15);
ogChannel_3->setFont(Font("Default", 8, Font::plain));
ogChannel_3->setColour(Label::textColourId, Colours::white);
ogChannel_3->setColour(Label::backgroundColourId, Colours::orange);
ogChannel_3->setEditable(true);
ogChannel_3->addListener(this);
ogChannel_3->setTooltip("Set the source channel 1 for interpolation");
ogChannel_3->setTooltip("Set the source channel 4 for interpolation");
addAndMakeVisible(ogChannel_3);

ogChannel_4 = new Label("Og Channel 4", "-1");
ogChannel_4 = new Label("Og Channel 5", "-1");
ogChannel_4->setBounds(98,45,20,15);
ogChannel_4->setFont(Font("Default", 8, Font::plain));
ogChannel_4->setColour(Label::textColourId, Colours::black);
ogChannel_4->setColour(Label::backgroundColourId, Colours::grey);
ogChannel_4->setEditable(true);
ogChannel_4->addListener(this);
ogChannel_4->setTooltip("Set the source channel 4 for interpolation");
ogChannel_4->setTooltip("Set the source channel 5 for interpolation");
addAndMakeVisible(ogChannel_4);

ogChannel_5 = new Label("Og Channel 5", "-1");
ogChannel_5 = new Label("Og Channel 6", "-1");
ogChannel_5->setBounds(120,45,20,15);
ogChannel_5->setFont(Font("Default", 8, Font::plain));
ogChannel_5->setColour(Label::textColourId, Colours::black);
ogChannel_5->setColour(Label::backgroundColourId, Colours::grey);
ogChannel_5->setEditable(true);
ogChannel_5->addListener(this);
ogChannel_5->setTooltip("Set the source channel 5 for interpolation");
ogChannel_5->setTooltip("Set the source channel 6 for interpolation");
addAndMakeVisible(ogChannel_5);

ogChannel_6 = new Label("Og Channel 6", "-1");
ogChannel_6 = new Label("Og Channel 7", "-1");
ogChannel_6->setBounds(142,45,20,15);
ogChannel_6->setFont(Font("Default", 8, Font::plain));
ogChannel_6->setColour(Label::textColourId, Colours::black);
ogChannel_6->setColour(Label::backgroundColourId, Colours::grey);
ogChannel_6->setEditable(true);
ogChannel_6->addListener(this);
ogChannel_6->setTooltip("Set the source channel 6 for interpolation");
ogChannel_6->setTooltip("Set the source channel 7 for interpolation");
addAndMakeVisible(ogChannel_6);

ogChannel_7 = new Label("Og Channel 7", "7");
ogChannel_7 = new Label("Og Channel 8", "8");
ogChannel_7->setBounds(164,45,20,15);
ogChannel_7->setFont(Font("Default", 8, Font::plain));
ogChannel_7->setColour(Label::textColourId, Colours::white);
ogChannel_7->setColour(Label::backgroundColourId, Colours::orange);
ogChannel_7->setEditable(true);
ogChannel_7->addListener(this);
ogChannel_7->setTooltip("Set the source channel 7 for interpolation");
ogChannel_7->setTooltip("Set the source channel 8 for interpolation");
addAndMakeVisible(ogChannel_7);


Expand All @@ -100,84 +100,84 @@ ChInterpEditor::ChInterpEditor(GenericProcessor* parentNode, bool useDefaultPara
toChannel_label->setColour(Label::textColourId, Colours::white);
addAndMakeVisible(toChannel_label);

toChannel_0 = new Label("To Channel 0", "0");
toChannel_0 = new Label("To Channel 1", "1");
toChannel_0->setBounds(10,100,20,15);
toChannel_0->setFont(Font("Default", 8, Font::plain));
toChannel_0->setColour(Label::textColourId, Colours::white);
toChannel_0->setColour(Label::backgroundColourId, Colours::orange);
toChannel_0->setEditable(true);
toChannel_0->addListener(this);
toChannel_0->setTooltip("Set the recipient channel 0 for interpolation");
toChannel_0->setTooltip("Set the recipient channel 1 for interpolation");
addAndMakeVisible(toChannel_0);

toChannel_1 = new Label("To Channel 1", "1");
toChannel_1 = new Label("To Channel 2", "2");
toChannel_1->setBounds(32,100,20,15);
toChannel_1->setFont(Font("Default", 8, Font::plain));
toChannel_1->setColour(Label::textColourId, Colours::white);
toChannel_1->setColour(Label::backgroundColourId, Colours::orange);
toChannel_1->setEditable(true);
toChannel_1->addListener(this);
toChannel_1->setTooltip("Set the recipient channel 1 for interpolation");
toChannel_1->setTooltip("Set the recipient channel 2 for interpolation");
addAndMakeVisible(toChannel_1);

toChannel_2 = new Label("To Channel 2", "2");
toChannel_2 = new Label("To Channel 3", "3");
toChannel_2->setBounds(54,100,20,15);
toChannel_2->setFont(Font("Default", 8, Font::plain));
toChannel_2->setColour(Label::textColourId, Colours::white);
toChannel_2->setColour(Label::backgroundColourId, Colours::orange);
toChannel_2->setEditable(true);
toChannel_2->addListener(this);
toChannel_2->setTooltip("Set the recipient channel 2 for interpolation");
toChannel_2->setTooltip("Set the recipient channel 3 for interpolation");
addAndMakeVisible(toChannel_2);

toChannel_3 = new Label("To Channel 3", "3");
toChannel_3 = new Label("To Channel 4", "4");
toChannel_3->setBounds(76,100,20,15);
toChannel_3->setFont(Font("Default", 8, Font::plain));
toChannel_3->setColour(Label::textColourId, Colours::white);
toChannel_3->setColour(Label::backgroundColourId, Colours::orange);
toChannel_3->setEditable(true);
toChannel_3->addListener(this);
toChannel_3->setTooltip("Set the recipient channel 1 for interpolation");
toChannel_3->setTooltip("Set the recipient channel 4 for interpolation");
addAndMakeVisible(toChannel_3);

toChannel_4 = new Label("To Channel 4", "4");
toChannel_4 = new Label("To Channel 5", "5");
toChannel_4->setBounds(98,100,20,15);
toChannel_4->setFont(Font("Default", 8, Font::plain));
toChannel_4->setColour(Label::textColourId, Colours::white);
toChannel_4->setColour(Label::backgroundColourId, Colours::orange);
toChannel_4->setEditable(true);
toChannel_4->addListener(this);
toChannel_4->setTooltip("Set the recipient channel 4 for interpolation");
toChannel_4->setTooltip("Set the recipient channel 5 for interpolation");
addAndMakeVisible(toChannel_4);

toChannel_5 = new Label("To Channel 5", "5");
toChannel_5 = new Label("To Channel 6", "6");
toChannel_5->setBounds(120,100,20,15);
toChannel_5->setFont(Font("Default", 8, Font::plain));
toChannel_5->setColour(Label::textColourId, Colours::white);
toChannel_5->setColour(Label::backgroundColourId, Colours::orange);
toChannel_5->setEditable(true);
toChannel_5->addListener(this);
toChannel_5->setTooltip("Set the recipient channel 5 for interpolation");
toChannel_5->setTooltip("Set the recipient channel 6 for interpolation");
addAndMakeVisible(toChannel_5);

toChannel_6 = new Label("To Channel 6", "6");
toChannel_6 = new Label("To Channel 7", "7");
toChannel_6->setBounds(142,100,20,15);
toChannel_6->setFont(Font("Default", 8, Font::plain));
toChannel_6->setColour(Label::textColourId, Colours::white);
toChannel_6->setColour(Label::backgroundColourId, Colours::orange);
toChannel_6->setEditable(true);
toChannel_6->addListener(this);
toChannel_6->setTooltip("Set the recipient channel 6 for interpolation");
toChannel_6->setTooltip("Set the recipient channel 7 for interpolation");
addAndMakeVisible(toChannel_6);

toChannel_7 = new Label("To Channel 7", "7");
toChannel_7 = new Label("To Channel 8", "8");
toChannel_7->setBounds(164,100,20,15);
toChannel_7->setFont(Font("Default", 8, Font::plain));
toChannel_7->setColour(Label::textColourId, Colours::white);
toChannel_7->setColour(Label::backgroundColourId, Colours::orange);
toChannel_7->setEditable(true);
toChannel_7->addListener(this);
toChannel_7->setTooltip("Set the recipient channel 7 for interpolation");
toChannel_7->setTooltip("Set the recipient channel 8 for interpolation");
addAndMakeVisible(toChannel_7);

}
Expand All @@ -201,7 +201,7 @@ void ChInterpEditor::labelTextChanged(Label* label)
//if change ogChannel
if (label == ogChannel_0)
{
if (requestedValue<0)
if (requestedValue<=0)
{
CoreServices::sendStatusMessage("Left most channel must be provided.");
return;
Expand Down Expand Up @@ -234,7 +234,7 @@ void ChInterpEditor::labelTextChanged(Label* label)
}
else if (label == ogChannel_7)
{
if (requestedValue<0)
if (requestedValue<=0)
{
CoreServices::sendStatusMessage("Right most channel must be provided.");
return;
Expand All @@ -244,7 +244,7 @@ void ChInterpEditor::labelTextChanged(Label* label)
else
{
Array<int> chans = getActiveChannels();
if (requestedValue<0)
if (requestedValue<=0)
{
CoreServices::sendStatusMessage("Recipient channel must be a valid number.");
return;
Expand Down
Binary file modified ch-interp-plugin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e3251ab

Please sign in to comment.