Box code snippet : construct a signal stream

  • NB: Document updated for OpenViBE 1.0.0 (05.Jun.2015).

What ?

We want a box to send a signal in its output, but there is no signal input to base our stream on.



We assume:

  • m_oSignalEncoder is a Stimulation encoder from the codec toolkit
  • m_bHeaderSent is a boolean member indicating if the stream header has been sent already or not (set to false in initialize())
  • The signal output is at index 0 in the box and the encoder has been initialized to this output.
  • l_ui64LastChunkEndTime is the last end time of the previous chunk.
  • The box implements processClock, and the box clock frequency is 128Hz.

In the process() function of your box:

 IMatrix *l_pInputMatrix = m_oAlgo0_SignalEncoder.getInputMatrix();
    m_oAlgo0_SignalEncoder.getInputSamplingRate() = 512; // we build a 512Hz signal.
    l_pInputMatrix->setDimensionCount(2); // 2 dimensions : channels X samples
    l_pInputMatrix->setDimensionSize(0,2); // 1st dimension is the channel count, let's say 2
    l_pInputMatrix->setDimensionSize(1,4); // 2nd dimension is the number of samples per block. 
    // As we want a 512Hz signal if the box clock frequency is 128Hz, we need 4 samples per block.
    l_pInputMatrix->setDimensionLabel(0,1,"channel 1"); // on the first dimension
    l_pInputMatrix->setDimensionLabel(0,2,"channel 2"); // the channels can be named

    m_bHeaderSent = true;
    for(uint32 i = 0; i < l_pInputMatrix->getBufferElementCount(); i++)
       l_pInputMatrix->getBuffer()[i] = i; // for example...


 // we send the new chunk anyway
 uint64 l_ui64ChunkEndTime = this->getPlayerContext().getCurrentTime();
 this->getDynamicBoxContext().markOutputAsReadyToSend(0, m_ui64LastChunkEndTime, l_ui64ChunkEndTime);
 m_ui64LastChunkEndTime = l_ui64ChunkEndTime;

This entry was posted in Code snippet. Bookmark the permalink.