Simple or modifiable delay box ?

Making & changing box plugins and external apps
Post Reply
Jeff_B
Posts: 37
Joined: Wed Apr 11, 2012 1:31 pm
Location: Nice - Alpes Maritimes

Simple or modifiable delay box ?

Post by Jeff_B »

Hi there
Is there a way to delay signals (by a number of samples or ms) or is there a way to implement it (via a FIR filter ?) in the designer ? I am looking for a way to implement easily a CSSP or CSSSP method.
Jeff

Jeff_B
Posts: 37
Joined: Wed Apr 11, 2012 1:31 pm
Location: Nice - Alpes Maritimes

Re: Simple or modifiable delay box ?

Post by Jeff_B »

Hi Openvibers,
I am not an experimented user of OV (just managed to compile it with an exotic driver) but I guess I will have to make a basic signal processing box to augment the regular (current or non delayed) signal flow with delayed versions of it. It would have two parameters (order and base_delay) and would augment the signal flow buffer this way:

channel 0 samples - channel 1 samples - .... - channel N samples - channel 0 samples delayed by base_delay - ..... - channel N samples delayed by base_delay - channel 0 samples delayed by 2*base_delay - ..... - channel N samples delayed by 2*base_delay - .............. - channel 0 samples delayed by order*base_delay - ..... - channel N samples delayed by order*base_delay

My original intend is to build a classifier for cursor control using a bank of spatio frequential filters built via CSP followed by a SVM. To include this frequential dimension in the CSP (FIR filtering), I was thinking to create new (virtual) channels with time delayed versions of the existing ones, and to deal with them in the same way we process the spatial samples using the regularized version of the CSP. A CSP filtered signal would thus be a linear combination of both spatial samples (spatial filtering) and their time delayed versions (temporal/frequential filtering). This brings a question about this regularized CSP: is there a way to apply a different amount of regularization /whitenning for the varied channels (enabling me to apply a different amount of regularization accross spatial (0-lagged) or temporal/frequential (lagged) dimensions ?). Or should I have to modify it ? o.O
Have a pleasing solstice and a gratifying ew year of research,
Jean-François B.

Jeff_B
Posts: 37
Joined: Wed Apr 11, 2012 1:31 pm
Location: Nice - Alpes Maritimes

Re: Simple or modifiable delay box ?

Post by Jeff_B »

Hi there,
I have implemented this DelayLines as a basic signal processing box (see attached files).

It compiles but keep crashing if played under the designer with a sinus generator as input, ending in a C0000005 error code.

The problem seems linked to fifo_buffer, since when I comment out the lines where I use the fifo_buffer in the implementation of CBoxAlgorithmDelayLines::process():

Code: Select all

for(uint32 i = 0 ; i < m_ui64channel_count ; i++)
{
	for(uint32 j = 0 ; j < m_ui64max_sample ; j++)
	{
		fifo_buffer[j + m_ui64sample_count + i*m_ui64sample_fifo] = fifo_buffer[j + i*m_ui64sample_fifo];
		if(j < m_ui64sample_count)
			fifo_buffer[j + i*m_ui64sample_fifo] = l_pBuffer[m_ui64sample_count - 1 - j + i*m_ui64sample_count];
	}
}
... the box can be played without any crash/unhandled exception (even if it does not produce any meaninful values).

I can write into fifo_buffer using for exemple: fifo_buffer[m_ui64sample_fifo]=1.0; but I cannot use for exemple:

Code: Select all

for(int i=0; i<m_ui64sample_fifo; i++)
{
      fifo_buffer[i]=1.0;
}
fifo_buffer is a private attribute of the CBoxAlgorithmDelayLines class, and declared as:
OpenViBE::float64 *fifo_buffer;
I have tried to dynamically allocate it in the CBoxAlgorithmDelayLines::initialize() via:

Code: Select all

fifo_buffer = new OpenViBE::float64[m_ui64channel_count*m_ui64sample_fifo];
or
	  std::vector<OpenViBE::float64> fifo_buffer(m_ui64channel_count*m_ui64sample_fifo, 0);
or
	  fifo_buffer = (OpenViBE::float64 *) calloc(m_ui64channel_count*m_ui64sample_fifo, sizeof(OpenViBE::float64));
followed (not in the case of std::vector) by

Code: Select all

memset(fifo_buffer, 0, sizeof(OpenViBE::float64)*m_ui64channel_count*m_ui64sample_fifo);
... without much success (always this C0000005 error code).

Any idea guys ? I am really stuck with this !
Best,
Jeff
Attachments
ovpCBoxAlgorithmDelayLines.cpp
(7.32 KiB) Downloaded 280 times
ovpCBoxAlgorithmDelayLines.h
(6.25 KiB) Downloaded 303 times

Jeff_B
Posts: 37
Joined: Wed Apr 11, 2012 1:31 pm
Location: Nice - Alpes Maritimes

Re: Simple or modifiable delay box ?

Post by Jeff_B »

The box works properly with a fixed (large) size array for fifo_buffer. Any clue about the reason why the dynamic allocation fails ?
Jeff

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

Re: Simple or modifiable delay box ?

Post by jtlindgren »

Hello Jeff,

welcome on board and thanks for the detailed report! The reason for the crash is clear from the source code. The thing is that the size of the matrix is information that is passed from box to another *during* the processing, in a specific 'header' segment, usually sent as the very first chunk of the stream. You need to allocate your buffer inside this block in process(),

Code: Select all

if(m_oInput0Decoder.isHeaderReceived())
{
   // ...
}
if you do it in initialize(), the decoder does not yet know what the actual sizes are.

About the other things, I think you're right, there's no explicit delay box in OV at the moment. About the CSP, you can't do per-channel regularization without modifying the box, but you might try learning two differently regularized CSP filters altogether by splitting the signal with Channel Selector -- although this might hamper your original purpose. :)

Good luck,
Jussi

Jeff_B
Posts: 37
Joined: Wed Apr 11, 2012 1:31 pm
Location: Nice - Alpes Maritimes

Re: Simple or modifiable delay box ?

Post by Jeff_B »

Hum... after the 1st header is received is far better... of course, thank you Jussi :mrgreen: :arrow:

Post Reply