Multiple Matrix Streams per Box Algorithm

Making & changing box plugins and external apps
Post Reply
jbrumberg
Posts: 5
Joined: Mon Jul 12, 2010 7:02 pm

Multiple Matrix Streams per Box Algorithm

Post by jbrumberg »

Hi all,

I am attempting to write input processing code to handle multiple streamed matrix inputs but don't know how to appropriately read from each input stream. I am using the Graz Visualizer as my starting point because I would like my first stream to be Stimulations, and my second and third inputs to be Streamed Matrix. In my modified box, I have added the third input, Streamed Matrix and am currently using the Sinus generator with sampling rate = 30, channels =4 and block = 1. When I check the setMatrixDimmensionSize() and setMatrixDimmensionLabel() I find that input index 0 has 4 items but that index 1 has only 1 item. Any thoughts as to my problem here?

Thanks
-Jon

bpayan
Posts: 46
Joined: Fri Jan 08, 2010 4:02 pm

Re: Multiple Matrix Streams per Box Algorithm

Post by bpayan »

Dear Jon,

Thank you for your interest in OpenViBE.

I am attempting to write input processing code to handle multiple streamed matrix inputs but don't know how to appropriately read from each input stream.
First you need a buffer for each inputs and outputs and connects them to the appropriate algorithm decoder or encoder. This operation is made in the “initialize” method.

Code: Select all

//Create a decoder for your input ( for this example I have a “streamed matrix” input)
OpenViBE::Kernel::IAlgorithmProxy* m_pStreamDecoder=&getAlgorithmManager().getAlgorithm(getAlgorithmManager().createAlgorithm(OVP_GD_ClassId_Algorithm_StreamedMatrixStreamDecoder));
m_pStreamDecoder->initialize();

//create a "memory buffer" for your input stream
TParameterHandler < const IMemoryBuffer* > ip_pMemoryBuffer(m_pStreamDecoder->getInputParameter(OVP_GD_Algorithm_StreamedMatrixStreamDecoder_InputParameterId_MemoryBufferToDecode));
//and create a matrix will contains your decode input stream 
TParameterHandler < IMatrix* > op_pMatrix(m_pStreamDecoder->getOutputParameter(OVP_GD_Algorithm_StreamedMatrixStreamDecoder_OutputParameterId_Matrix));
in the method "process"

Code: Select all

//put data from your input stream in the memory buffer
//i correspond to the number of your input
//j correspond to the number of the chunk where you work
ip_pMemoryBuffer=l_rDynamicBoxContext.getInputChunk(i, j);
//and decode it
m_pStreamDecoder->process();
you can find more details on the openvibe site: http://openvibe.inria.fr/documentation/ ... ssing.html
In my modified box, I have added the third input, Streamed Matrix and am currently using the Sinus generator with sampling rate = 30, channels =4 and block = 1. When I check the setMatrixDimmensionSize() and setMatrixDimmensionLabel() I find that input index 0 has 4 items but that index 1 has only 1 item. Any thoughts as to my problem here?
A signal can be convert in a matrix with 2 dimensions. The first correspond to channels of your signal and the second correspond to samples of each channels. That's why, you have this values.

For the dimension 1 : op_pMatrix->getDimensionSize(0)= 4, because you had 4 channels.
For the dimension 2 : op_Matrix->getDimensionSize(1)=1, because your "sinus oscillator" sent 1 sample by chunk. On the "sinus oscillator" box, parameter: "Generated epoch sample count = 1".

I hope this help you.

Best regards,

Baptiste

lbonnet
Site Admin
Posts: 417
Joined: Wed Oct 07, 2009 12:11 pm

Re: Multiple Matrix Streams per Box Algorithm

Post by lbonnet »

Hi Jon welcome on board !
I am attempting to write input processing code to handle multiple streamed matrix inputs but don't know how to appropriately read from each input stream.
First, I suggest you look at the tutorial for developer : writing an algorithm and use it in a box. It shows how you can read a streamed matrix input, and output another streamed matrix.

I am using the Graz Visualizer as my starting point because I would like my first stream to be Stimulations, and my second and third inputs to be Streamed Matrix.
In my opinion, the graz visualisation box is quiet complex for a first try... You should definitely look at the simple box given in the tutorial. It is easy to add one more streamed matrix as input. If you need an example of stimulation processing, you can look at the Run command box : this box reads stimulation stream, and run a specific system command if a specific stim is coming.
When I check the setMatrixDimmensionSize() and setMatrixDimmensionLabel() I find that input index 0 has 4 items but that index 1 has only 1 item.
As Baptiste said, these values seem ok :)

Then you can access the data using the getBuffer function.
Example :

Code: Select all

buffer[i*matrix->getDimensionSize(1)+j]
will give you the j-th sample on the i-th channel. In your case i goes from 0 to 3 and j can only be 0 (and getDimensionSize(1) returns 1).

I hope this helps.

Laurent
Follow us on twitter >> openvibebci

Checkout my (old) blog for some OpenViBE tips & tricks : here !

jbrumberg
Posts: 5
Joined: Mon Jul 12, 2010 7:02 pm

Re: Multiple Matrix Streams per Box Algorithm

Post by jbrumberg »

Thanks for the code pointers. I have successfully enabled a new box-algorithm to read from input Streamed Matrix types. I have enabled two input streams - should I use two memory buffers and two different matrices since each input stream can be a different size? In that case, how can I dynamically ensure the right input stream goes to the right buffer? That is, the current method:

Code: Select all

buffer=IBoxIO->getInputChunk(input,chunk)
(note: I use a variable for IBoxIO, but used the data type for illustration)

Makes no assumptions about the incoming data. If I were to use two different buffers I would have to hard-code the expected order, as in:

Code: Select all

buffer0 = IBoxIO->getInputChunk(0,chunk);
buffer1 = IBoxIO->getInputChunk(1,chunk);
Is this the best/only way to achieve my desired result?

Thanks,
Jon

yrenard
Site Admin
Posts: 645
Joined: Fri Sep 01, 2006 3:39 pm
Contact:

Re: Multiple Matrix Streams per Box Algorithm

Post by yrenard »

Dear jbrumberg,

indeed, you should probably take care of using different IMemoryBuffer parameter handlers (as for decoder inputs) and IMatrix parameter handlers (as for decoder outputs).

This will lead you to something quite similar to the code you proposed :

Code: Select all

buffer0 = IBoxIO->getInputChunk(0,chunk);
buffer1 = IBoxIO->getInputChunk(1,chunk);
Hope this helps,
Yann

Post Reply