Getting the sampling frequency in a box

Come here to discuss about OpenViBE in general!
Post Reply
toncho11
Posts: 124
Joined: Tue Apr 19, 2011 7:58 pm

Getting the sampling frequency in a box

Post by toncho11 »

Hi,

I am having problems with getting the sampling frequency. I am working on the CBoxAlgorithmErpPlot class/box.
I have a box with several inputs of type: streamed matrix. For each one of them I have a decoder in m_vDecoders:

Code: Select all

std::vector< OpenViBEToolkit::TStreamedMatrixDecoder<CBoxAlgorithmErpPlot>* > m_vDecoders;
Unfortunately the Sampling Rate is still not supplied when executing my code in: ::process(void)

Code: Select all

OpenViBE::Kernel::TParameterHandler < OpenViBE::uint64 >& l_pSamplingRate = ( (TSignalDecoder <CBoxAlgorithmErpPlot> *) m_vDecoders[i] )->getOutputSamplingRate();
The value is uninitialized. Can somebody provide me a hint on why is this not working?

jtlindgren
Posts: 775
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: Getting the sampling frequency in a box

Post by jtlindgren »

Hi Toncho,

the sampling rate is passed in the header chunk of a signal stream, so you won't have a frequency before the header chunk has been decoded. Matrix streams do not have a sampling rate at all, and the decoder should not even have such a getter. You'd need

Code: Select all

// Header
std::vector< OpenViBEToolkit::TSignalDecoder<CBoxAlgorithmErpPlot>* > m_vDecoders;

// Code
for(uint32 j=0; j<l_pDynamicBoxContext->getInputChunkCount(i); j++)
{
  m_vDecoders[i].decode(j);

  if(m_oSignalDecoder.isHeaderReceived())
  {
      l_ui64SamplingRate = m_vDecoders[i] ->getOutputSamplingRate();
  }
  //
}
Hope this helps!


Cheers,
Jussi

toncho11
Posts: 124
Joined: Tue Apr 19, 2011 7:58 pm

Re: Getting the sampling frequency in a box

Post by toncho11 »

Yes, but the inputs of the box are "Streamed Matrix", so I can not use the code that is for Signal inputs.

Can I get the frequency from another box and send it to my box somehow? Otherwise the frequency must be always hard-coded in the box, which is not nice.

Anton

jtlindgren
Posts: 775
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: Getting the sampling frequency in a box

Post by jtlindgren »

If you have a signal stream, why not upgrade the box to support signal inputs? Or, if you have matrixes but with
a known sampling rate, it sounds like you lost the sampling frequency somehow along the way, otherwise you'd
still have a signal stream. One option would be to develop a box that upgrades a matrix to a signal, getting the sampling
rate from somewhere (where?) but we don't have one at the moment.

Alternatively, if the matrix stream is continuous, you can guess the sampling rate from the chunk timestamps and
the matrix size. See Signal Display box code for an example calculation.


Cheers,
Jussi

Post Reply