You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovpCBoxAlgorithmTactileStimulator.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file ovpCBoxAlgorithmTactileStimulator.cpp
  4. /// \brief Functions of the Box Tactile Stimulator.
  5. /// \author Tobias Baumann (TH-Nürnberg).
  6. /// \version 1.0.
  7. /// \date Mon Feb 21 14:59:56 2022.
  8. /// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
  9. ///
  10. ///-------------------------------------------------------------------------------------------------
  11. //includes
  12. #include "ovpCBoxAlgorithmTactileStimulation.h"
  13. using namespace OpenViBE;
  14. using namespace /*OpenViBE::*/Kernel;
  15. using namespace /*OpenViBE::*/Plugins;
  16. using namespace /*OpenViBE::Plugins::*/Tactilebci;
  17. bool CBoxAlgorithmTactileStimulation::initialize()
  18. {
  19. m_input0Decoder.initialize(*this, 0);
  20. m_output0Encoder.initialize(*this, 0);
  21. // If you need to retrieve setting values, use the FSettingValueAutoCast function.
  22. // For example :
  23. // - CString setting at index 0 in the setting list :
  24. // CString sSettingValue = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
  25. // - unsigned int64 setting at index 1 in the setting list :
  26. // uint64_t uiSettingValue = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
  27. // - double setting at index 2 in the setting list :
  28. // double doubleSettingValue = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 2);
  29. // ...
  30. return true;
  31. }
  32. /*******************************************************************************/
  33. bool CBoxAlgorithmTactileStimulation::uninitialize()
  34. {
  35. m_input0Decoder.uninitialize();
  36. m_output0Encoder.uninitialize();
  37. return true;
  38. }
  39. /*******************************************************************************/
  40. bool CBoxAlgorithmTactileStimulation::process()
  41. {
  42. // the static box context describes the box inputs, outputs, settings structures
  43. const IBox& staticBoxContext=this->getStaticBoxContext();
  44. // the dynamic box context describes the current state of the box inputs and outputs (i.e. the chunks)
  45. IBoxIO& boxContext = this->getDynamicBoxContext();
  46. // here is some useful functions:
  47. // - To get input/output/setting count:
  48. // staticBoxContext.getInputCount();
  49. // staticBoxContext.getOutputCount();
  50. // - To get the number of chunks currently available on a particular input :
  51. // boxContext.getInputChunkCount(input_index)
  52. // - To send an output chunk :
  53. // boxContext.markOutputAsReadyToSend(output_index, chunk_start_time, chunk_end_time);
  54. // A typical process iteration may look like this.
  55. // This example only iterate over the first input of type Signal, and output a modified Signal.
  56. // thus, the box uses 1 decoder (m_signalDecoder) and 1 encoder (m_signalEncoder)
  57. /*
  58. IBoxIO& boxContext = this->getDynamicBoxContext();
  59. //iterate over all chunk on input 0
  60. for (size_t i = 0; i < boxContext.getInputChunkCount(0); ++i)
  61. {
  62. // decode the chunk i
  63. m_signalDecoder.decode(i);
  64. // the decoder may have decoded 3 different parts : the header, a buffer or the end of stream.
  65. if(m_signalDecoder.isHeaderReceived())
  66. {
  67. // Header received. This happens only once when pressing "play". For example with a StreamedMatrix input, you now know the dimension count, sizes, and labels of the matrix
  68. // ... maybe do some process ...
  69. // Pass the header to the next boxes, by encoding a header on the output 0:
  70. m_signalEncoder.encodeHeader(0);
  71. // send the output chunk containing the header. The dates are the same as the input chunk:
  72. boxContext.markOutputAsReadyToSend(0, boxContext.getInputChunkStartTime(0, i), boxContext.getInputChunkEndTime(0, i));
  73. }
  74. if(m_signalDecoder.isBufferReceived())
  75. {
  76. // Buffer received. For example the signal values
  77. // Access to the buffer can be done thanks to :
  78. CMatrix* matrix = m_signalDecoder.getOutputMatrix(); // the StreamedMatrix of samples.
  79. uint64_t frequency = m_signalDecoder.getOutputSamplingRate(); // the sampling rate of the signal
  80. // ... do some process on the matrix ...
  81. // Encode the output buffer :
  82. m_signalEncoder.encodeBuffer(0);
  83. // and send it to the next boxes :
  84. boxContext.markOutputAsReadyToSend(0, boxContext.getInputChunkStartTime(0, i), boxContext.getInputChunkEndTime(0, i));
  85. }
  86. if(m_signalDecoder.isEndReceived())
  87. {
  88. // End of stream received. This happens only once when pressing "stop". Just pass it to the next boxes so they receive the message :
  89. m_signalEncoder.encodeEnd(0);
  90. boxContext.markOutputAsReadyToSend(0, boxContext.getInputChunkStartTime(0, i), boxContext.getInputChunkEndTime(0, i));
  91. }
  92. // The current input chunk has been processed, and automaticcaly discarded.
  93. // you don't need to call "boxContext.markInputAsDeprecated(0, i);"
  94. }
  95. */
  96. // check the official developer documentation webpage for more example and information :
  97. // Tutorials:
  98. // http://openvibe.inria.fr/documentation/#Developer+Documentation
  99. // Codec Toolkit page :
  100. // http://openvibe.inria.fr/codec-toolkit-references/
  101. // Feel free to ask experienced developers on the forum (http://openvibe.inria.fr/forum) and IRC (#openvibe on irc.freenode.net).
  102. return true;
  103. }