Commit 0c1a5ab0 authored by Jussi Lindgren's avatar Jussi Lindgren

Plugins: Fixed BrainAmp file reader for non-integer sampling intervals

Partly addresses Mantis #155

Thanks to Anton Andreev for bug report.
parent 26548d02
#include "ovpCAlgorithmBrainampFileReader.h"
#include <system/Memory.h>
#include <sstream>
#include <cstdlib>
#include <openvibe/ovITimeArithmetics.h>
using namespace OpenViBE;
using namespace OpenViBE::Kernel;
using namespace OpenViBE::Plugins;
......@@ -60,11 +61,9 @@ boolean CAlgorithmBrainampFileReader::process(void)
{
std::string l_sMarkerFilename;
std::string l_sDataFilename;
uint64 l_ui64SamplingInterval;
m_ui32BinaryFormat=BinaryFormat_Integer16;
m_ui32ChannelCount=0;
m_ui64SamplingInterval=0;
m_ui64StartSampleIndex=0;
m_ui64EndSampleIndex=0;
m_ui64SampleCountPerBuffer=0;
......@@ -195,16 +194,15 @@ boolean CAlgorithmBrainampFileReader::process(void)
}
else if(l_sOptionName=="SamplingInterval")
{
l_ui64SamplingInterval=atoi(l_sOptionValue.c_str());
float64 l_f64SamplingInterval=atof(l_sOptionValue.c_str());
op_ui64SamplingRate=static_cast<uint64>(0.5+1000000.0/l_f64SamplingInterval); // +0.5 for rounding
m_ui64SampleCountPerBuffer=((int64)((ip_f64EpochDuration*1000000.)/l_ui64SamplingInterval)); // $$$ Casted in (int64) because of Ubuntu 7.10 crash !
op_pSignalMatrix->setDimensionSize(1, (uint32)m_ui64SampleCountPerBuffer);
op_ui64SamplingRate=1000000/l_ui64SamplingInterval;
m_ui64SampleCountPerBuffer=static_cast<int64>(ip_f64EpochDuration*op_ui64SamplingRate); // $$$ Casted in (int64) because of Ubuntu 7.10 crash !
op_pSignalMatrix->setDimensionSize(1, static_cast<uint32>(m_ui64SampleCountPerBuffer));
// TODO warn if approximated sampling rate
getLogManager() << LogLevel_Trace << "| -> Calculated sampling frequency " << op_ui64SamplingRate << "Hz\n";
m_ui64SamplingInterval=(l_ui64SamplingInterval<<32)/1000000;
}
else
{
......@@ -494,8 +492,8 @@ boolean CAlgorithmBrainampFileReader::process(void)
m_ui64StartSampleIndex=m_ui64EndSampleIndex;
m_ui64EndSampleIndex+=m_ui64SampleCountPerBuffer;
op_ui64CurrentStartTime=m_ui64StartSampleIndex*m_ui64SamplingInterval;
op_ui64CurrentEndTime=m_ui64EndSampleIndex*m_ui64SamplingInterval;
op_ui64CurrentStartTime=ITimeArithmetics::sampleCountToTime(op_ui64SamplingRate,m_ui64StartSampleIndex);
op_ui64CurrentEndTime=ITimeArithmetics::sampleCountToTime(op_ui64SamplingRate,m_ui64EndSampleIndex);
// find stimulations in this range
uint64 l_ui64StimulationCount=0;
......@@ -514,9 +512,12 @@ boolean CAlgorithmBrainampFileReader::process(void)
{
if(m_ui64StartSampleIndex <= itStimulation->m_ui64StartIndex && itStimulation->m_ui64StartIndex < m_ui64EndSampleIndex)
{
uint64 l_ui64Date = ITimeArithmetics::sampleCountToTime(op_ui64SamplingRate,itStimulation->m_ui64StartIndex);
uint64 l_ui64Duration = ITimeArithmetics::sampleCountToTime(op_ui64SamplingRate,itStimulation->m_ui64Duration);
op_pStimulations->setStimulationIdentifier(l_ui64StimulationCount, itStimulation->m_ui64Identifier);
op_pStimulations->setStimulationDate(l_ui64StimulationCount, itStimulation->m_ui64StartIndex*m_ui64SamplingInterval);
op_pStimulations->setStimulationDuration(l_ui64StimulationCount, itStimulation->m_ui64Duration*m_ui64SamplingInterval);
op_pStimulations->setStimulationDate(l_ui64StimulationCount, l_ui64Date);
op_pStimulations->setStimulationDuration(l_ui64StimulationCount, l_ui64Duration);
l_ui64StimulationCount++;
}
}
......
......@@ -72,7 +72,6 @@ namespace OpenViBEPlugins
OpenViBE::uint32 m_ui32BinaryFormat;
OpenViBE::uint32 m_ui32Endianness;
OpenViBE::uint32 m_ui32ChannelCount;
OpenViBE::uint64 m_ui64SamplingInterval;
OpenViBE::uint64 m_ui64StartSampleIndex;
OpenViBE::uint64 m_ui64EndSampleIndex;
OpenViBE::uint64 m_ui64SampleCountPerBuffer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment