Skip to content

Commit e31f6f5

Browse files
committed
Add Binary file source to binary format plugin
1 parent 5139062 commit e31f6f5

5 files changed

Lines changed: 235 additions & 3 deletions

File tree

Builds/VisualStudio2013/Plugins/BinaryFormat/BinaryFormat.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
</ProjectConfiguration>
2020
</ItemGroup>
2121
<ItemGroup>
22+
<ClCompile Include="..\..\..\..\Source\Plugins\BinaryFormat\FileSource\BinaryFileSource.cpp" />
2223
<ClCompile Include="..\..\..\..\Source\Plugins\BinaryFormat\OpenEphysLib.cpp" />
2324
<ClCompile Include="..\..\..\..\Source\Plugins\BinaryFormat\RecordEngine\BinaryRecording.cpp" />
2425
<ClCompile Include="..\..\..\..\Source\Plugins\BinaryFormat\RecordEngine\NpyFile.cpp" />
2526
<ClCompile Include="..\..\..\..\Source\Plugins\BinaryFormat\RecordEngine\SequentialBlockFile.cpp" />
2627
</ItemGroup>
2728
<ItemGroup>
29+
<ClInclude Include="..\..\..\..\Source\Plugins\BinaryFormat\FileSource\BinaryFileSource.h" />
2830
<ClInclude Include="..\..\..\..\Source\Plugins\BinaryFormat\RecordEngine\BinaryRecording.h" />
2931
<ClInclude Include="..\..\..\..\Source\Plugins\BinaryFormat\RecordEngine\FileMemoryBlock.h" />
3032
<ClInclude Include="..\..\..\..\Source\Plugins\BinaryFormat\RecordEngine\NpyFile.h" />

Builds/VisualStudio2013/Plugins/BinaryFormat/BinaryFormat.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<Filter Include="Source Files\RecordEngine">
1717
<UniqueIdentifier>{1b16254b-e802-4d23-bd3f-1796871b55e8}</UniqueIdentifier>
1818
</Filter>
19+
<Filter Include="Source Files\FileSource">
20+
<UniqueIdentifier>{9ccccbc4-5f08-4b60-a6fd-0a727df0bbb8}</UniqueIdentifier>
21+
</Filter>
1922
</ItemGroup>
2023
<ItemGroup>
2124
<ClCompile Include="..\..\..\..\Source\Plugins\BinaryFormat\OpenEphysLib.cpp">
@@ -30,6 +33,9 @@
3033
<ClCompile Include="..\..\..\..\Source\Plugins\BinaryFormat\RecordEngine\SequentialBlockFile.cpp">
3134
<Filter>Source Files\RecordEngine</Filter>
3235
</ClCompile>
36+
<ClCompile Include="..\..\..\..\Source\Plugins\BinaryFormat\FileSource\BinaryFileSource.cpp">
37+
<Filter>Source Files\FileSource</Filter>
38+
</ClCompile>
3339
</ItemGroup>
3440
<ItemGroup>
3541
<ClInclude Include="..\..\..\..\Source\Plugins\BinaryFormat\RecordEngine\BinaryRecording.h">
@@ -44,5 +50,8 @@
4450
<ClInclude Include="..\..\..\..\Source\Plugins\BinaryFormat\RecordEngine\SequentialBlockFile.h">
4551
<Filter>Source Files\RecordEngine</Filter>
4652
</ClInclude>
53+
<ClInclude Include="..\..\..\..\Source\Plugins\BinaryFormat\FileSource\BinaryFileSource.h">
54+
<Filter>Source Files\FileSource</Filter>
55+
</ClInclude>
4756
</ItemGroup>
4857
</Project>
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
------------------------------------------------------------------
3+
4+
This file is part of the Open Ephys GUI
5+
Copyright (C) 2018 Open Ephys
6+
7+
------------------------------------------------------------------
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
*/
23+
24+
#include "BinaryFileSource.h"
25+
26+
using namespace BinarySource;
27+
28+
BinaryFileSource::BinaryFileSource() : m_samplePos(0)
29+
{}
30+
31+
BinaryFileSource::~BinaryFileSource()
32+
{}
33+
34+
bool BinaryFileSource::Open(File file)
35+
{
36+
m_jsonData = JSON::parse(file);
37+
if (m_jsonData.isVoid())
38+
return false;
39+
40+
if (m_jsonData["GUI version"].isVoid())
41+
return false;
42+
43+
var cont = m_jsonData["continuous"];
44+
if (cont.isVoid() || cont.size() <= 0)
45+
return false;
46+
47+
m_rootPath = file.getParentDirectory();
48+
49+
return true;
50+
}
51+
52+
void BinaryFileSource::fillRecordInfo()
53+
{
54+
var continuousData = m_jsonData["continuous"];
55+
56+
//create identifiers to speed up stuff
57+
Identifier idFolder("folder_name");
58+
Identifier idSampleRate("sample_rate");
59+
Identifier idNumChannels("num_channels");
60+
Identifier idChannels("channels");
61+
Identifier idChannelName("channel_name");
62+
Identifier idBitVolts("bit_volts");
63+
64+
int numProcessors = continuousData.size();
65+
66+
for (int i = 0; i < numProcessors; i++)
67+
{
68+
var record = continuousData[i];
69+
if (record.isVoid()) continue;
70+
71+
var channels = record[idChannels];
72+
if (channels.isVoid() || channels.size() <= 0) continue;
73+
74+
RecordInfo info;
75+
76+
String folderName = record[idFolder];
77+
folderName = folderName.trimCharactersAtEnd("/");
78+
79+
File dataFile = m_rootPath.getChildFile("continuous").getChildFile(folderName).getChildFile("continuous.dat");
80+
if (!dataFile.existsAsFile()) continue;
81+
82+
int numChannels = record[idNumChannels];
83+
int64 numSamples = (dataFile.getSize() / numChannels) / sizeof(int16);
84+
85+
info.name = folderName;
86+
info.sampleRate = record[idSampleRate];
87+
info.numSamples = numSamples;
88+
89+
for (int c = 0; c < numChannels; c++)
90+
{
91+
var chan = channels[c];
92+
RecordedChannelInfo cInfo;
93+
94+
cInfo.name = chan[idChannelName];
95+
cInfo.bitVolts = chan[idBitVolts];
96+
97+
info.channels.add(cInfo);
98+
}
99+
100+
infoArray.add(info);
101+
numRecords++;
102+
103+
m_dataFileArray.add(dataFile);
104+
105+
}
106+
107+
}
108+
109+
void BinaryFileSource::updateActiveRecord()
110+
{
111+
m_dataFile = new MemoryMappedFile(m_dataFileArray[activeRecord.get()], MemoryMappedFile::readOnly);
112+
m_samplePos = 0;
113+
}
114+
115+
void BinaryFileSource::seekTo(int64 sample)
116+
{
117+
m_samplePos = sample % getActiveNumSamples();
118+
}
119+
120+
int BinaryFileSource::readData(int16* buffer, int nSamples)
121+
{
122+
int nChans = getActiveNumChannels();
123+
int64 samplesToRead;
124+
125+
if (m_samplePos + nSamples > getActiveNumSamples())
126+
{
127+
samplesToRead = getActiveNumSamples() - m_samplePos;
128+
}
129+
else
130+
{
131+
samplesToRead = nSamples;
132+
}
133+
134+
int16* data = static_cast<int16*>(m_dataFile->getData()) + (m_samplePos * nChans);
135+
136+
memcpy(buffer, data, samplesToRead*nChans*sizeof(int16));
137+
return samplesToRead;
138+
}
139+
140+
void BinaryFileSource::processChannelData(int16* inBuffer, float* outBuffer, int channel, int64 numSamples)
141+
{
142+
int n = getActiveNumChannels();
143+
float bitVolts = getChannelInfo(channel).bitVolts;
144+
145+
for (int i = 0; i < numSamples; i++)
146+
{
147+
*(outBuffer + i) = *(inBuffer + (n*i) + channel) * bitVolts;
148+
}
149+
}
150+
151+
bool BinaryFileSource::isReady()
152+
{
153+
return true;
154+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
------------------------------------------------------------------
3+
4+
This file is part of the Open Ephys GUI
5+
Copyright (C) 2018 Open Ephys
6+
7+
------------------------------------------------------------------
8+
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+
*/
23+
24+
#ifndef BINARYFILESOURCE_H_INCLUDED
25+
#define BINARYFILESOURCE_H_INCLUDED
26+
27+
#include <FileSourceHeaders.h>
28+
29+
namespace BinarySource
30+
{
31+
class BinaryFileSource : public FileSource
32+
{
33+
public:
34+
BinaryFileSource();
35+
~BinaryFileSource();
36+
37+
int readData(int16* buffer, int nSamples) override;
38+
39+
void seekTo(int64 sample) override;
40+
41+
void processChannelData(int16* inBuffer, float* outBuffer, int channel, int64 numSamples) override;
42+
43+
bool isReady() override;
44+
45+
private:
46+
bool Open(File file) override;
47+
void fillRecordInfo() override;
48+
void updateActiveRecord() override;
49+
50+
ScopedPointer<MemoryMappedFile> m_dataFile;
51+
var m_jsonData;
52+
Array<File> m_dataFileArray;
53+
54+
File m_rootPath;
55+
int64 m_samplePos;
56+
57+
};
58+
}
59+
60+
#endif

Source/Plugins/BinaryFormat/OpenEphysLib.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2323

2424
#include <PluginInfo.h>
2525
#include "RecordEngine/BinaryRecording.h"
26+
#include "FileSource/BinaryFileSource.h"
2627
#include <string>
2728
#ifdef WIN32
2829
#include <Windows.h>
@@ -33,13 +34,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3334

3435

3536
using namespace Plugin;
36-
#define NUM_PLUGINS 1
37+
#define NUM_PLUGINS 2
3738

3839
extern "C" EXPORT void getLibInfo(Plugin::LibraryInfo* info)
3940
{
4041
info->apiVersion = PLUGIN_API_VER;
41-
info->name = "Binary recording";
42-
info->libVersion = 1;
42+
info->name = "Binary format";
43+
info->libVersion = 2;
4344
info->numPlugins = NUM_PLUGINS;
4445
}
4546

@@ -52,6 +53,12 @@ extern "C" EXPORT int getPluginInfo(int index, Plugin::PluginInfo* info)
5253
info->recordEngine.name = "Binary";
5354
info->recordEngine.creator = &(Plugin::createRecordEngine<BinaryRecordingEngine::BinaryRecording>);
5455
break;
56+
case 1:
57+
info->type = Plugin::PLUGIN_TYPE_FILE_SOURCE;
58+
info->fileSource.name = "Binary";
59+
info->fileSource.extensions = "oebin";
60+
info->fileSource.creator = &(Plugin::createFileSource<BinarySource::BinaryFileSource>);
61+
break;
5562
default:
5663
return -1;
5764
}

0 commit comments

Comments
 (0)