Commit b9c50a62 authored by ANDRADE-BARROSO Guillermo's avatar ANDRADE-BARROSO Guillermo
parents fcd8dd15 3840d2d0
......@@ -24,6 +24,7 @@ ENDFUNCTION(OV_ADD_CONTRIB_DRIVER)
OV_ADD_CONTRIB_DRIVER("${CMAKE_SOURCE_DIR}/contrib/plugins/server-drivers/brainmaster-discovery")
OV_ADD_CONTRIB_DRIVER("${CMAKE_SOURCE_DIR}/contrib/plugins/server-drivers/brainproducts-actichamp")
OV_ADD_CONTRIB_DRIVER("${CMAKE_SOURCE_DIR}/contrib/plugins/server-drivers/brainproducts-brainvisionrecorder")
OV_ADD_CONTRIB_DRIVER("${CMAKE_SOURCE_DIR}/contrib/plugins/server-drivers/cognionics")
OV_ADD_CONTRIB_DRIVER("${CMAKE_SOURCE_DIR}/contrib/plugins/server-drivers/ctfvsm-meg")
OV_ADD_CONTRIB_DRIVER("${CMAKE_SOURCE_DIR}/contrib/plugins/server-drivers/field-trip-protocol")
OV_ADD_CONTRIB_DRIVER("${CMAKE_SOURCE_DIR}/contrib/plugins/server-drivers/gtec-gipsa")
......
......@@ -9,6 +9,7 @@
#include "ovasCDriverBrainmasterDiscovery.h"
#include "ovasCDriverBrainProductsActiCHamp.h"
#include "ovasCDriverBrainProductsBrainVisionRecorder.h"
#include "ovasCDriverCognionics.h"
#include "ovasCDriverCtfVsmMeg.h"
#include "ovasCDriverGTecGUSBamp.h"
#include "ovasCDriverGTecGUSBampLegacy.h"
......@@ -27,6 +28,9 @@ namespace OpenViBEContributions {
void initiateContributions(OpenViBEAcquisitionServer::CAcquisitionServerGUI* pGUI, OpenViBEAcquisitionServer::CAcquisitionServer* pAcquisitionServer, const OpenViBE::Kernel::IKernelContext& rKernelContext, std::vector<OpenViBEAcquisitionServer::IDriver*>* vDriver)
{
vDriver->push_back(new OpenViBEAcquisitionServer::CDriverBrainProductsBrainVisionRecorder(pAcquisitionServer->getDriverContext()));
#if defined WIN32
vDriver->push_back(new OpenViBEAcquisitionServer::CDriverCognionics(pAcquisitionServer->getDriverContext()));
#endif
vDriver->push_back(new OpenViBEAcquisitionServer::CDriverCtfVsmMeg(pAcquisitionServer->getDriverContext()));
#if defined TARGET_HAS_ThirdPartyGUSBampCAPI
vDriver->push_back(new OpenViBEAcquisitionServer::CDriverGTecGUSBamp(pAcquisitionServer->getDriverContext()));
......
#if defined(WIN32)
#include "ovasCConfigurationCognionics.h"
using namespace OpenViBE;
using namespace OpenViBE::Kernel;
using namespace OpenViBEAcquisitionServer;
using namespace std;
/*_________________________________________________
Insert callback to specific widget here
Example with a button that launch a calibration of the device:
//Callback connected to a dedicated gtk button:
static void button_calibrate_pressed_cb(::GtkButton* pButton, void* pUserData)
{
CConfigurationCognionics* l_pConfig=static_cast<CConfigurationCognionics*>(pUserData);
l_pConfig->buttonCalibratePressedCB();
}
//Callback actually called:
void CConfigurationGTecGUSBamp::buttonCalibratePressedCB(void)
{
// Connect to the hardware, ask for calibration, verify the return code, etc.
}
_________________________________________________*/
// If you added more reference attribute, initialize them here
CConfigurationCognionics::CConfigurationCognionics(IDriverContext& rDriverContext, const char* sGtkBuilderFileName,
uint32& rCOMPORT)
:CConfigurationBuilder(sGtkBuilderFileName)
,m_rDriverContext(rDriverContext)
,m_rCOMPORT(rCOMPORT)
{
}
boolean CConfigurationCognionics::preConfigure(void)
{
if(! CConfigurationBuilder::preConfigure())
{
return false;
}
::GtkSpinButton* l_pSpinButtonCOMPORT=GTK_SPIN_BUTTON(gtk_builder_get_object(m_pBuilderConfigureInterface, "spinbutton_comport"));
gtk_spin_button_set_value(l_pSpinButtonCOMPORT, m_rCOMPORT);
// Connect here all callbacks
// Example:
// g_signal_connect(gtk_builder_get_object(m_pBuilderConfigureInterface, "button_calibrate"), "pressed", G_CALLBACK(button_calibrate_pressed_cb), this);
// Insert here the pre-configure code.
// For example, you may want to check if a device is currently connected
// and if more than one are connected. Then you can list in a dedicated combo-box
// the device currently connected so the user can choose which one he wants to acquire from.
return true;
}
boolean CConfigurationCognionics::postConfigure(void)
{
if(m_bApplyConfiguration)
{
::GtkSpinButton* l_pSpinButtonCOMPORT=GTK_SPIN_BUTTON(gtk_builder_get_object(m_pBuilderConfigureInterface, "spinbutton_comport"));
m_rCOMPORT=(uint32)::gtk_spin_button_get_value(l_pSpinButtonCOMPORT);
//printf("Selected COM Port: %d", m_rCOMPORT);
// If the user pressed the "apply" button, you need to save the changes made in the configuration.
// For example, you can save the connection ID of the selected device:
// m_ui32ConnectionID = <value-from-gtk-widget>
}
if(! CConfigurationBuilder::postConfigure()) // normal header is filled (Subject ID, Age, Gender, channels, sampling frequency), ressources are realesed
{
return false;
}
return true;
}
#endif // WIN32
#ifndef __OpenViBE_AcquisitionServer_CConfigurationCognionics_H__
#define __OpenViBE_AcquisitionServer_CConfigurationCognionics_H__
#include "../ovasCConfigurationBuilder.h"
#include "ovasIDriver.h"
#include <gtk/gtk.h>
namespace OpenViBEAcquisitionServer
{
/**
* \class CConfigurationCognionics
* \author Mike Chi (Cognionics, Inc.)
* \copyright AGPL3
* \date Thu Apr 18 21:19:49 2013
* \brief The CConfigurationCognionics handles the configuration dialog specific to the Cognionics device.
*
* TODO: details
*
* \sa CDriverCognionics
*/
class CConfigurationCognionics : public OpenViBEAcquisitionServer::CConfigurationBuilder
{
public:
// you may have to add to your constructor some reference parameters
// for example, a connection ID:
//CConfigurationCognionics(OpenViBEAcquisitionServer::IDriverContext& rDriverContext, const char* sGtkBuilderFileName, OpenViBE::uint32& rConnectionId);
CConfigurationCognionics(OpenViBEAcquisitionServer::IDriverContext& rDriverContext, const char* sGtkBuilderFileName, OpenViBE::uint32& rCOMPORT);
virtual OpenViBE::boolean preConfigure(void);
virtual OpenViBE::boolean postConfigure(void);
OpenViBE::uint32& m_rCOMPORT;
protected:
OpenViBEAcquisitionServer::IDriverContext& m_rDriverContext;
private:
/*
* Insert here all specific attributes, such as a connection ID.
* use references to directly modify the corresponding attribute of the driver
* Example:
*/
};
};
#endif // __OpenViBE_AcquisitionServer_CConfigurationCognionics_H__
#ifndef __OpenViBE_AcquisitionServer_CDriverCognionics_H__
#define __OpenViBE_AcquisitionServer_CDriverCognionics_H__
#include "ovasIDriver.h"
#include "../ovasCHeader.h"
#include <openvibe/ov_all.h>
#include "../ovasCSettingsHelper.h"
#include "../ovasCSettingsHelperOperators.h"
namespace OpenViBEAcquisitionServer
{
/**
* \class CDriverCognionics
* \author Mike Chi (Cognionics, Inc.)
* \copyright AGPL3
* \date Thu Apr 18 21:19:49 2013
* \brief The CDriverCognionics allows the acquisition server to acquire data from a Cognionics device.
*
* TODO: details
*
* \sa CConfigurationCognionics
*/
class CDriverCognionics : public OpenViBEAcquisitionServer::IDriver
{
public:
CDriverCognionics(OpenViBEAcquisitionServer::IDriverContext& rDriverContext);
virtual ~CDriverCognionics(void);
virtual const char* getName(void);
virtual OpenViBE::boolean initialize(
const OpenViBE::uint32 ui32SampleCountPerSentBlock,
OpenViBEAcquisitionServer::IDriverCallback& rCallback);
virtual OpenViBE::boolean uninitialize(void);
virtual OpenViBE::boolean start(void);
virtual OpenViBE::boolean stop(void);
virtual OpenViBE::boolean loop(void);
virtual OpenViBE::boolean isConfigurable(void);
virtual OpenViBE::boolean configure(void);
virtual const OpenViBEAcquisitionServer::IHeader* getHeader(void) { return &m_oHeader; }
virtual OpenViBE::boolean isFlagSet(
const OpenViBEAcquisitionServer::EDriverFlag eFlag) const
{
return eFlag==DriverFlag_IsUnstable;
}
protected:
SettingsHelper m_oSettings;
OpenViBEAcquisitionServer::IDriverCallback* m_pCallback;
// Replace this generic Header with any specific header you might have written
OpenViBEAcquisitionServer::CHeader m_oHeader;
OpenViBE::uint32 m_ui32SampleCountPerSentBlock;
OpenViBE::float32* m_pSample;
private:
/*
* Insert here all specific attributes, such as USB port number or device ID.
* Example :
*/
OpenViBE::uint32 m_ui32ComPort;
};
};
#endif // __OpenViBE_AcquisitionServer_CDriverCognionics_H__
......@@ -22,7 +22,8 @@ namespace OpenViBEAcquisitionServer
OpenViBE::int32& rBandPassFilterIndex,
OpenViBE::boolean& rTriggerInput,
vector<string> rDevicesSerials,
string& rMasterDeviceIndex
string& rMasterDeviceIndex,
OpenViBE::boolean& rBipolar
);
virtual OpenViBE::boolean preConfigure(void);
......@@ -33,6 +34,8 @@ namespace OpenViBEAcquisitionServer
void buttonCommonGndRefPressedCB(void);
void buttonFiltersPressedCB(void);
void setHardwareFiltersDialog();
void buttonFiltersApplyPressedCB(void);
protected:
OpenViBE::uint32& m_rUSBIndex;
......@@ -45,6 +48,7 @@ namespace OpenViBEAcquisitionServer
string& m_rMasterDeviceIndex;
vector<OpenViBE::uint32> m_vComboBoxBandPassFilterIndex;
vector<OpenViBE::uint32> m_vComboBoxNotchFilterIndex;
OpenViBE::boolean& m_rBipolarEnabled;
private:
::GtkWidget* m_pCalibrateDialog;
......
......@@ -45,6 +45,7 @@ CDriverGTecGUSBamp::CDriverGTecGUSBamp(IDriverContext& rDriverContext)
,m_ui32AcquiredChannelCount(GTEC_NUM_CHANNELS)
,m_flagIsFirstLoop(true)
,m_masterSerial("")
,m_bBipolarEnabled(false)
{
m_oHeader.setSamplingFrequency(512);
m_oHeader.setChannelCount(GTEC_NUM_CHANNELS);
......@@ -57,6 +58,7 @@ CDriverGTecGUSBamp::CDriverGTecGUSBamp(IDriverContext& rDriverContext)
m_oSettings.add("TriggerInputEnabled", &m_bTriggerInputEnabled);
m_oSettings.add("DeviceSerials", &m_vDevicesSerials);
m_oSettings.add("MasterSerial", &m_masterSerial);
m_oSettings.add("Bipolar", &m_bBipolarEnabled);
m_oSettings.load();
m_ui32AcquiredChannelCount = m_oHeader.getChannelCount();
......@@ -159,11 +161,11 @@ OpenViBE::boolean CDriverGTecGUSBamp::initialize(
{
if(::GT_SetSlave(m_callSequenceHandles[0], false))
{
char serial[16];
::GT_GetSerial(m_callSequenceHandles[0], serial, 16);
m_masterSerial = serial;
m_rDriverContext.getLogManager() << LogLevel_Info << "Configured as MASTER device: " << m_masterSerial.c_str() << " \n";
m_mastersCnt++;
char serial[16];
::GT_GetSerial(m_callSequenceHandles[0], serial, 16);
m_masterSerial = serial;
m_rDriverContext.getLogManager() << LogLevel_Info << "Configured as MASTER device: " << m_masterSerial.c_str() << " \n";
m_mastersCnt++;
}
else m_rDriverContext.getLogManager() << LogLevel_Error << "Unexpected error while calling GT_SetSlave\n";
}
......@@ -228,13 +230,55 @@ OpenViBE::boolean CDriverGTecGUSBamp::ConfigureDevice(OpenViBE::uint32 deviceNum
if(!::GT_EnableTriggerLine(o_pDevice, TRUE)) m_rDriverContext.getLogManager() << LogLevel_Error << "Unexpected error while calling GT_EnableTriggerLine - the extra input trigger channel is disabled\n";
// GT_EnableSC
// GT_SetBipolar
/* for(uint32 i=0; i<m_ui32AcquiredChannelCount; i++)
{
if(!::GT_SetBandPass(o_pDevice, i+1, m_i32BandPassFilterIndex)) m_rDriverContext.getLogManager() << LogLevel_Error << "Unexpected error while calling GT_SetBandPass for channel " << i << "\n";
if(!::GT_SetNotch(o_pDevice, i+1, m_i32NotchFilterIndex)) m_rDriverContext.getLogManager() << LogLevel_Error << "Unexpected error while calling GT_SetNotch for channel " << i << "\n";
}*/
// GT_SetBipolar
CHANNEL _bipolarSettings;
if (this->m_bBipolarEnabled)
{
//the following configurations produces 8 bipolar: 1,3,5,7,9,11,13,15 and 8 unipolar 2,4,6,8,10,12,14,16
_bipolarSettings.Channel1 = 2;
_bipolarSettings.Channel2 = 0;
_bipolarSettings.Channel3 = 4;
_bipolarSettings.Channel4 = 0;
_bipolarSettings.Channel5 = 6;
_bipolarSettings.Channel6 = 0;
_bipolarSettings.Channel7 = 8;
_bipolarSettings.Channel8 = 0;
_bipolarSettings.Channel9 = 10;
_bipolarSettings.Channel10 = 0;
_bipolarSettings.Channel11 = 12;
_bipolarSettings.Channel12 = 0;
_bipolarSettings.Channel13 = 14;
_bipolarSettings.Channel14 = 0;
_bipolarSettings.Channel15 = 16;
_bipolarSettings.Channel16 = 0;
}
else
{
_bipolarSettings.Channel1 = 0;
_bipolarSettings.Channel2 = 0;
_bipolarSettings.Channel3 = 0;
_bipolarSettings.Channel4 = 0;
_bipolarSettings.Channel5 = 0;
_bipolarSettings.Channel6 = 0;
_bipolarSettings.Channel7 = 0;
_bipolarSettings.Channel8 = 0;
_bipolarSettings.Channel9 = 0;
_bipolarSettings.Channel10 = 0;
_bipolarSettings.Channel11 = 0;
_bipolarSettings.Channel12 = 0;
_bipolarSettings.Channel13 = 0;
_bipolarSettings.Channel14 = 0;
_bipolarSettings.Channel15 = 0;
_bipolarSettings.Channel16 = 0;
}
if (!GT_SetBipolar(o_pDevice, _bipolarSettings))
m_rDriverContext.getLogManager() << LogLevel_Error << "Error on GT_SetBipolar: Couldn't set unipolar derivation for device " << current_serial;
else if (this->m_bBipolarEnabled) m_rDriverContext.getLogManager() << LogLevel_Info << "Bipolar configuration is active.\n";
ConfigFiltering(o_pDevice);
if(!::GT_SetSampleRate(o_pDevice, m_oHeader.getSamplingFrequency())) m_rDriverContext.getLogManager() << LogLevel_Error << "Unexpected error while calling GT_SetSampleRate\n";
......@@ -299,12 +343,12 @@ OpenViBE::boolean CDriverGTecGUSBamp::loop(void)
try
{
if (m_bufferOverrun)
{
m_RingBuffer.Reset();
m_bufferOverrun = false;
m_ui32TotalRingBufferOverruns++;
return true;
}
{
m_RingBuffer.Reset();
m_bufferOverrun = false;
m_ui32TotalRingBufferOverruns++;
return true;
}
m_RingBuffer.Read(m_bufferReceivedData, validPoints);
}
......@@ -581,9 +625,9 @@ OpenViBE::boolean CDriverGTecGUSBamp::stop(void)
m_ThreadPtr->join(); //wait until the thread has stopped data acquisition
m_rDriverContext.getLogManager() << LogLevel_Debug << "Total number of hardware stimulations acquired: " << m_ui32TotalHardwareStimulations << "\n";
m_rDriverContext.getLogManager() << LogLevel_Warning << "Total chunks lost: " << m_ui32TotalDriverChunksLost << "\n";
m_rDriverContext.getLogManager() << LogLevel_Warning << "Total internal ring buffer overruns: " << m_ui32TotalRingBufferOverruns << "\n";
m_rDriverContext.getLogManager() << LogLevel_Warning << "Total times GTEC ring data buffer was empty: " << m_ui32TotalDataUnavailable << "\n";
m_rDriverContext.getLogManager() << LogLevel_Debug << "Total chunks lost: " << m_ui32TotalDriverChunksLost << "\n";
m_rDriverContext.getLogManager() << LogLevel_Debug << "Total internal ring buffer overruns: " << m_ui32TotalRingBufferOverruns << "\n";
m_rDriverContext.getLogManager() << LogLevel_Debug << "Total times GTEC ring data buffer was empty: " << m_ui32TotalDataUnavailable << "\n";
return true;
}
......@@ -745,7 +789,8 @@ OpenViBE::boolean CDriverGTecGUSBamp::configure(void)
m_i32BandPassFilterIndex,
m_bTriggerInputEnabled,
m_vDevicesSerials,
targetMasterSerial);
targetMasterSerial,
m_bBipolarEnabled);
//reduce from number of channels for all devices to the number of channels for one device
m_oHeader.setChannelCount(m_ui32AcquiredChannelCount);
......@@ -808,7 +853,7 @@ void CDriverGTecGUSBamp::ConfigFiltering(HANDLE o_pDevice)
{
OpenViBE::boolean status;
int32 nrOfFilters;
float32 mySamplingRate = m_oHeader.getSamplingFrequency();
float32 mySamplingRate = static_cast<float32>(m_oHeader.getSamplingFrequency());
//Set BandPass
......
......@@ -112,6 +112,7 @@ namespace OpenViBEAcquisitionServer
OpenViBE::int32 m_i32BandPassFilterIndex;
OpenViBE::boolean m_bTriggerInputEnabled;
OpenViBE::boolean m_bBipolarEnabled; //electrodes are substracted in sepecific sequence 1-2=1, ... 15-16=15 which results in 8 instead of 16 electrodes - used for EMG
OpenViBE::uint32 m_ui32AcquiredChannelCount; //number of channels 1..16 specified bu user
......
......@@ -25,6 +25,7 @@ namespace System
static System::int64 randomSInterger64(void);
static System::float32 randomFloat32(void);
static System::float32 randomFloat32BetweenZeroAndOne(void);
static System::float64 randomFloat64(void);
private:
......
......@@ -68,6 +68,11 @@ float32 Math::randomFloat32(void)
return fr;
}
float32 Math::randomFloat32BetweenZeroAndOne(void) {
float32 fr = static_cast<float32>(rand()) / static_cast<float32>(RAND_MAX);
return fr;
}
float64 Math::randomFloat64(void)
{
uint64 r=randomUInteger64();
......@@ -75,3 +80,5 @@ float64 Math::randomFloat64(void)
::memcpy(&fr, &r, sizeof(fr));
return fr;
}
/**
* \page BoxAlgorithm_NoiseGenerator Noise generator
__________________________________________________________________
Detailed description
__________________________________________________________________
* |OVP_DocBegin_BoxAlgorithm_NoiseGenerator_Description|
The Noise Generator outputs random signals on a configurable number of channels. The sampling frequency and epoch size can be configured as well. The data is sampled from a pseudorandom uniform distribution.
* |OVP_DocEnd_BoxAlgorithm_NoiseGenerator_Description|
__________________________________________________________________
Outputs description
__________________________________________________________________
* |OVP_DocBegin_BoxAlgorithm_NoiseGenerator_Outputs|
* |OVP_DocEnd_BoxAlgorithm_NoiseGenerator_Outputs|
* |OVP_DocBegin_BoxAlgorithm_NoiseGenerator_Output1|
Random signal generated.
* |OVP_DocEnd_BoxAlgorithm_NoiseGenerator_Output1|
__________________________________________________________________
Settings description
__________________________________________________________________
* |OVP_DocBegin_BoxAlgorithm_NoiseGenerator_Settings|
* |OVP_DocEnd_BoxAlgorithm_NoiseGenerator_Settings|
* |OVP_DocBegin_BoxAlgorithm_NoiseGenerator_Setting1|
Number of channels generated.
* |OVP_DocEnd_BoxAlgorithm_NoiseGenerator_Setting1|
* |OVP_DocBegin_BoxAlgorithm_NoiseGenerator_Setting2|
Sampling frequency of generated signals.
* |OVP_DocEnd_BoxAlgorithm_NoiseGenerator_Setting2|
* |OVP_DocBegin_BoxAlgorithm_NoiseGenerator_Setting3|
Number of samples per epoch
* |OVP_DocEnd_BoxAlgorithm_NoiseGenerator_Setting3|
__________________________________________________________________
Miscellaneous description
__________________________________________________________________
* |OVP_DocBegin_BoxAlgorithm_NoiseGenerator_Miscellaneous|
* |OVP_DocEnd_BoxAlgorithm_NoiseGenerator_Miscellaneous|
*/
#include "ovpCBoxAlgorithmNoiseGenerator.h"
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <openvibe/ovITimeArithmetics.h>
#include <system/CMath.h>
using namespace OpenViBE;
using namespace OpenViBE::Kernel;
using namespace OpenViBE::Plugins;
using namespace OpenViBEPlugins;
using namespace OpenViBEPlugins::Samples;
using namespace OpenViBEToolkit;
using namespace std;
CNoiseGenerator::CNoiseGenerator(void)
:
m_bHeaderSent(false)
,m_ui64ChannelCount(0)
,m_ui64SamplingFrequency(0)
,m_ui64GeneratedEpochSampleCount(0)
,m_ui64SentSampleCount(0)
{
}
void CNoiseGenerator::release(void)
{
delete this;
}
boolean CNoiseGenerator::initialize(void)
{
m_pStreamEncoder=&getAlgorithmManager().getAlgorithm(getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_SignalStreamEncoder));
if(!m_pStreamEncoder) {
this->getLogManager() << LogLevel_Error << "Unable to get stream encoder.\n";
return false;
}
m_pStreamEncoder->initialize();
m_ui64ChannelCount=FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
m_ui64SamplingFrequency=FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
m_ui64GeneratedEpochSampleCount=FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 2);
m_bHeaderSent=false;
if(m_ui64ChannelCount == 0)
{
this->getLogManager() << LogLevel_Error << "Channel count is 0. At least 1 channel required. Check box settings.\n";
return false;
}
if(m_ui64SamplingFrequency == 0)
{
this->getLogManager() << LogLevel_Error << "Sampling rate of 0 is not supported. Check box settings.\n";
return false;
}
if(m_ui64GeneratedEpochSampleCount == 0)
{
this->getLogManager() << LogLevel_Error << "Epoch sample count is 0. An epoch must have at least 1 sample. Check box settings.\n";
return false;
}
ip_ui64SignalSamplingRate.initialize(m_pStreamEncoder->getInputParameter(OVP_GD_Algorithm_SignalStreamEncoder_InputParameterId_SamplingRate));
ip_pSignalMatrix.initialize(m_pStreamEncoder->getInputParameter(OVP_GD_Algorithm_SignalStreamEncoder_InputParameterId_Matrix));
ip_ui64SignalSamplingRate = m_ui64SamplingFrequency;
IMatrix &l_rSampleMatrix = *ip_pSignalMatrix;
l_rSampleMatrix.setDimensionCount(2);
l_rSampleMatrix.setDimensionSize(0,(uint32)m_ui64ChannelCount);
l_rSampleMatrix.setDimensionSize(1,(uint32)m_ui64GeneratedEpochSampleCount);
return true;
}
boolean CNoiseGenerator::uninitialize(void)
{
m_pStreamEncoder->uninitialize();
getAlgorithmManager().releaseAlgorithm(*m_pStreamEncoder);
return true;
}
boolean CNoiseGenerator::processClock(CMessageClock& rMessageClock)
{
getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
return true;
}
boolean CNoiseGenerator::process(void)
{
IBoxIO* l_pDynamicBoxContext=getBoxAlgorithmContext()->getDynamicBoxContext();
TParameterHandler < IMemoryBuffer* > l_oOutputMemoryBufferHandle(m_pStreamEncoder->getOutputParameter(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_OutputParameterId_EncodedMemoryBuffer));
l_oOutputMemoryBufferHandle=l_pDynamicBoxContext->getOutputChunk(0);
if(!m_bHeaderSent)
{
m_pStreamEncoder->process(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputTriggerId_EncodeHeader);
uint64 l_ui64Time=ITimeArithmetics::sampleCountToTime(m_ui64SamplingFrequency, m_ui64SentSampleCount);
l_pDynamicBoxContext->markOutputAsReadyToSend(0, l_ui64Time, l_ui64Time);
m_bHeaderSent=true;
}
else
{
IMatrix &l_rSampleMatrix = *ip_pSignalMatrix;
float64* l_pSampleBuffer = l_rSampleMatrix.getBuffer();
uint32 l_ui32SentSampleCount=(uint32)m_ui64SentSampleCount;
for(uint32 i=0; i<(uint32)m_ui64ChannelCount; i++)
{
for(uint32 j=0; j<(uint32)m_ui64GeneratedEpochSampleCount; j++)
{
l_pSampleBuffer[i*m_ui64GeneratedEpochSampleCount+j]=(float64)System::Math::randomFloat32BetweenZeroAndOne();
}
}
m_ui64SentSampleCount+=m_ui64GeneratedEpochSampleCount;
uint64 l_ui64StartTime = ITimeArithmetics::sampleCountToTime(m_ui64SamplingFrequency, l_ui32SentSampleCount);
uint64 l_ui64EndTime = ITimeArithmetics::sampleCountToTime(m_ui64SamplingFrequency, m_ui64SentSampleCount);
m_pStreamEncoder->process(OVP_GD_Algorithm_StreamedMatrixStreamEncoder_InputTriggerId_EncodeBuffer);
l_pDynamicBoxContext->markOutputAsReadyToSend(0, l_ui64StartTime, l_ui64EndTime);
}
return true;
}
OpenViBE::uint64 CNoiseGenerator::getClockFrequency(void)
{
// Intentional parameter swap to get the frequency
return ITimeArithmetics::sampleCountToTime(m_ui64GeneratedEpochSampleCount, m_ui64SamplingFrequency);
}
#ifndef __SamplePlugin_CNoiseGenerator_H__
#define __SamplePlugin_CNoiseGenerator_H__
#include "../ovp_defines.h"
#include <toolkit/ovtk_all.h>
namespace OpenViBEPlugins
{
namespace Samples
{
class CNoiseGenerator : public OpenViBEToolkit::TBoxAlgorithm<OpenViBE::Plugins::IBoxAlgorithm>
{
public:
CNoiseGenerator(void);
virtual void release(void);
virtual OpenViBE::uint64 getClockFrequency(void);
virtual OpenViBE::boolean initialize(void);
virtual OpenViBE::boolean uninitialize(void);
virtual OpenViBE::boolean processClock(OpenViBE::Kernel::IMessageClock& rMessageClock);
virtual OpenViBE::boolean process(void);
_IsDerivedFromClass_Final_(OpenViBEToolkit::TBoxAlgorithm<OpenViBE::Plugins::IBoxAlgorithm>, OVP_ClassId_NoiseGenerator)
protected:
OpenViBE::Kernel::IAlgorithmProxy* m_pStreamEncoder;
OpenViBE::Kernel::TParameterHandler < OpenViBE::IMatrix* > ip_pSignalMatrix;
OpenViBE::Kernel::TParameterHandler < OpenViBE::uint64 > ip_ui64SignalSamplingRate;
OpenViBE::boolean m_bHeaderSent;
OpenViBE::uint64 m_ui64ChannelCount;
OpenViBE::uint64 m_ui64SamplingFrequency;
OpenViBE::uint64 m_ui64GeneratedEpochSampleCount;