From 2b50044ad0a256edeae38d735b507474f27ca768 Mon Sep 17 00:00:00 2001 From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es> Date: Mon, 3 Nov 2014 04:15:33 +0100 Subject: [PATCH] Make FileSources able to report multiple channel info --- Source/Processors/FileReader/FileSource.cpp | 13 +++- Source/Processors/FileReader/FileSource.h | 72 ++++++++++--------- .../Processors/FileReader/KwikFileSource.cpp | 24 +++++-- 3 files changed, 70 insertions(+), 39 deletions(-) diff --git a/Source/Processors/FileReader/FileSource.cpp b/Source/Processors/FileReader/FileSource.cpp index b09d4aba3..ce721a6ee 100644 --- a/Source/Processors/FileReader/FileSource.cpp +++ b/Source/Processors/FileReader/FileSource.cpp @@ -43,7 +43,7 @@ String FileSource::getRecordName(int index) int FileSource::getRecordNumChannels(int index) { - return infoArray[index].numChannels; + return infoArray[index].channels.size(); } int FileSource::getActiveNumChannels() @@ -76,6 +76,17 @@ int FileSource::getActiveRecord() return activeRecord; } +RecordedChannelInfo FileSource::getChannelInfo(int recordIndex, int channel) +{ + return infoArray[recordIndex].channels[channel]; +} + +RecordedChannelInfo FileSource::getChannelInfo(int channel) +{ + return getChannelInfo(activeRecord, channel); +} + + void FileSource::setActiveRecord(int index) { activeRecord = index; diff --git a/Source/Processors/FileReader/FileSource.h b/Source/Processors/FileReader/FileSource.h index 2b6f62e0f..1e3e5e7a1 100644 --- a/Source/Processors/FileReader/FileSource.h +++ b/Source/Processors/FileReader/FileSource.h @@ -26,52 +26,60 @@ #include "../../../JuceLibraryCode/JuceHeader.h" +struct RecordedChannelInfo +{ + String name; + float bitVolts; +}; + class FileSource { public: - FileSource(); - ~FileSource(); + FileSource(); + ~FileSource(); + + int getNumRecords(); + String getRecordName(int index); - int getNumRecords(); - String getRecordName(int index); + int getActiveRecord(); + void setActiveRecord(int index); - int getActiveRecord(); - void setActiveRecord(int index); + float getRecordSampleRate(int index); + int getRecordNumChannels(int index); + int64 getRecordNumSamples(int index); - float getRecordSampleRate(int index); - int getRecordNumChannels(int index); - int64 getRecordNumSamples(int index); + float getActiveSampleRate(); + int getActiveNumChannels(); + int64 getActiveNumSamples(); - float getActiveSampleRate(); - int getActiveNumChannels(); - int64 getActiveNumSamples(); + RecordedChannelInfo getChannelInfo(int recordIndex, int channel); + RecordedChannelInfo getChannelInfo(int channel); + bool OpenFile(File file); + bool fileIsOpened(); - bool OpenFile(File file); - bool fileIsOpened(); - - virtual int readData(int16* buffer, int nSamples) =0; + virtual int readData(int16* buffer, int nSamples) =0; - virtual void seekTo(int64 sample) =0; + virtual void seekTo(int64 sample) =0; protected: - struct RecordInfo - { - String name; - int numChannels; - int64 numSamples; - float sampleRate; - }; - Array<RecordInfo> infoArray; - - bool fileOpened; - int numRecords; - int activeRecord; + struct RecordInfo + { + String name; + Array<RecordedChannelInfo> channels; + int64 numSamples; + float sampleRate; + }; + Array<RecordInfo> infoArray; + + bool fileOpened; + int numRecords; + int activeRecord; private: - virtual bool Open(File file)=0; - virtual void fillRecordInfo()=0; - virtual void updateActiveRecord()=0; + virtual bool Open(File file)=0; + virtual void fillRecordInfo()=0; + virtual void updateActiveRecord()=0; }; diff --git a/Source/Processors/FileReader/KwikFileSource.cpp b/Source/Processors/FileReader/KwikFileSource.cpp index aadc36892..71231e514 100644 --- a/Source/Processors/FileReader/KwikFileSource.cpp +++ b/Source/Processors/FileReader/KwikFileSource.cpp @@ -20,10 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ - +#include <h5cpp.h> #include "KwikFileSource.h" -#include <h5cpp.h> + using namespace H5; @@ -90,7 +90,7 @@ void KWIKFileSource::fillRecordInfo() try { Group recordN; DataSet data; - Attribute samp; + Attribute attr; DataSpace dSpace; float sampleRate; hsize_t dims[3]; @@ -98,15 +98,27 @@ void KWIKFileSource::fillRecordInfo() recordN = recordings.openGroup(String(i).toUTF8()); data = recordN.openDataSet("data"); - samp = recordN.openAttribute("sample_rate"); - samp.read(PredType::NATIVE_FLOAT,&sampleRate); + attr = recordN.openAttribute("sample_rate"); + attr.read(PredType::NATIVE_FLOAT,&sampleRate); dSpace = data.getSpace(); dSpace.getSimpleExtentDims(dims); info.name="Record "+String(i); - info.numChannels = dims[1]; info.numSamples = dims[0]; info.sampleRate = sampleRate; + + recordN = recordings.openGroup((String(i) + "/application_data").toUTF8()); + attr=recordN.openAttribute("channel_bit_volts"); + HeapBlock<float> bitVoltArray(dims[1]); + attr.read(ArrayType(PredType::NATIVE_FLOAT,1,&dims[1]),bitVoltArray); + + for (int i=0; i < dims[1]; i++) + { + RecordedChannelInfo c; + c.name = "CH" + i; + c.bitVolts = bitVoltArray[i]; + info.channels.add(c); + } infoArray.add(info); availableDataSets.add(i); numRecords++; -- GitLab