init
This commit is contained in:
+78
@@ -0,0 +1,78 @@
|
||||
#include "ovpCBoxAlgorithmTimeSignalGenerator.h"
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Plugins {
|
||||
namespace DataGeneration {
|
||||
|
||||
bool CBoxAlgorithmTimeSignalGenerator::initialize()
|
||||
{
|
||||
m_encoder.initialize(*this, 0);
|
||||
|
||||
// Parses box settings to try connecting to server
|
||||
m_sampling = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
|
||||
m_nGeneratedEpochSample = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
|
||||
m_headerSent = false;
|
||||
|
||||
m_nSentSample = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBoxAlgorithmTimeSignalGenerator::uninitialize()
|
||||
{
|
||||
m_encoder.uninitialize();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBoxAlgorithmTimeSignalGenerator::processClock(Kernel::CMessageClock& /*msg*/)
|
||||
{
|
||||
this->getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBoxAlgorithmTimeSignalGenerator::process()
|
||||
{
|
||||
Kernel::IBoxIO* boxContext = getBoxAlgorithmContext()->getDynamicBoxContext();
|
||||
|
||||
if (!m_headerSent)
|
||||
{
|
||||
m_encoder.getInputSamplingRate() = m_sampling;
|
||||
|
||||
CMatrix* matrix = m_encoder.getInputMatrix();
|
||||
|
||||
matrix->resize(1, m_nGeneratedEpochSample);
|
||||
matrix->setDimensionLabel(0, 0, "Time signal");
|
||||
|
||||
m_encoder.encodeHeader();
|
||||
|
||||
m_headerSent = true;
|
||||
|
||||
boxContext->markOutputAsReadyToSend(0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create sample chunks up until the next step (current time + 1/128) but do not overshoot it
|
||||
// This way we will always create the correct number of samples for frequencies that are above 128Hz
|
||||
const uint64_t nextStepDate = CTime(uint64_t(this->getPlayerContext().getCurrentTime() + (1ULL << 25))).toSampleCount(m_sampling);
|
||||
while (m_nSentSample + m_nGeneratedEpochSample < nextStepDate)
|
||||
{
|
||||
double* buffer = m_encoder.getInputMatrix()->getBuffer();
|
||||
|
||||
for (size_t i = 0; i < m_nGeneratedEpochSample; ++i) { buffer[i] = (i + m_nSentSample) / double(m_sampling); }
|
||||
|
||||
m_encoder.encodeBuffer();
|
||||
|
||||
const uint64_t tStart = CTime(m_sampling, m_nSentSample).time();
|
||||
m_nSentSample += m_nGeneratedEpochSample;
|
||||
const uint64_t tEnd = CTime(m_sampling, m_nSentSample).time();
|
||||
|
||||
boxContext->markOutputAsReadyToSend(0, tStart, tEnd);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace DataGeneration
|
||||
} // namespace Plugins
|
||||
} // namespace OpenViBE
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovp_defines.h"
|
||||
|
||||
#include <toolkit/ovtk_all.h>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Plugins {
|
||||
namespace DataGeneration {
|
||||
class CBoxAlgorithmTimeSignalGenerator final : public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
|
||||
{
|
||||
public:
|
||||
|
||||
CBoxAlgorithmTimeSignalGenerator() {}
|
||||
void release() override { delete this; }
|
||||
|
||||
uint64_t getClockFrequency() override { return 128LL << 32; }
|
||||
|
||||
bool initialize() override;
|
||||
bool uninitialize() override;
|
||||
|
||||
bool processClock(Kernel::CMessageClock& msg) override;
|
||||
bool process() override;
|
||||
|
||||
_IsDerivedFromClass_Final_(Toolkit::TBoxAlgorithm<IBoxAlgorithm>, OVP_ClassId_BoxAlgorithm_TimeSignalGenerator)
|
||||
|
||||
protected:
|
||||
|
||||
Toolkit::TSignalEncoder<CBoxAlgorithmTimeSignalGenerator> m_encoder;
|
||||
|
||||
bool m_headerSent = false;
|
||||
size_t m_sampling = 0;
|
||||
size_t m_nGeneratedEpochSample = 0;
|
||||
size_t m_nSentSample = 0;
|
||||
};
|
||||
|
||||
class CBoxAlgorithmTimeSignalGeneratorDesc final : public IBoxAlgorithmDesc
|
||||
{
|
||||
public:
|
||||
|
||||
void release() override { }
|
||||
CString getName() const override { return CString("Time signal"); }
|
||||
CString getAuthorName() const override { return CString("Yann Renard"); }
|
||||
CString getAuthorCompanyName() const override { return CString("INRIA/IRISA"); }
|
||||
CString getShortDescription() const override { return CString("Simple time signal generator (for use with DSP)"); }
|
||||
CString getDetailedDescription() const override { return CString(""); }
|
||||
CString getCategory() const override { return CString("Data generation"); }
|
||||
CString getVersion() const override { return CString("1.1"); }
|
||||
CString getSoftwareComponent() const override { return CString("openvibe-sdk"); }
|
||||
CString getAddedSoftwareVersion() const override { return CString("0.0.0"); }
|
||||
CString getUpdatedSoftwareVersion() const override { return CString("0.4.0"); }
|
||||
|
||||
CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_TimeSignalGenerator; }
|
||||
IPluginObject* create() override { return new CBoxAlgorithmTimeSignalGenerator(); }
|
||||
|
||||
bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
|
||||
{
|
||||
prototype.addOutput("Generated signal", OV_TypeId_Signal);
|
||||
|
||||
prototype.addSetting("Sampling frequency", OV_TypeId_Integer, "512");
|
||||
prototype.addSetting("Generated epoch sample count", OV_TypeId_Integer, "32");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_IsDerivedFromClass_Final_(IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_TimeSignalGeneratorDesc)
|
||||
};
|
||||
} // namespace DataGeneration
|
||||
} // namespace Plugins
|
||||
} // namespace OpenViBE
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
// Global defines
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
#ifdef TARGET_HAS_ThirdPartyOpenViBEPluginsGlobalDefines
|
||||
#include "ovp_global_defines.h"
|
||||
#endif // TARGET_HAS_ThirdPartyOpenViBEPluginsGlobalDefines
|
||||
|
||||
|
||||
#define OVP_ClassId_BoxAlgorithm_TimeSignalGenerator OpenViBE::CIdentifier(0x28A5E7FF, 0x530095DE)
|
||||
#define OVP_ClassId_BoxAlgorithm_TimeSignalGeneratorDesc OpenViBE::CIdentifier(0x57AD8655, 0x1966B4DC)
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "ovp_defines.h"
|
||||
|
||||
#include "box-algorithms/ovpCBoxAlgorithmTimeSignalGenerator.h"
|
||||
|
||||
OVP_Declare_Begin()
|
||||
OVP_Declare_New(OpenViBE::Plugins::DataGeneration::CBoxAlgorithmTimeSignalGeneratorDesc);
|
||||
OVP_Declare_End()
|
||||
Reference in New Issue
Block a user