You need to be looking further up:
unsigned int xcorr(float *inl, float *inr)
{
//cross-correlation routine
//returns number of samples delay between inl and inr
return delay;
}
void xcorrelation_task()
{
gXcorIsBusy = true;
gDelay = xcorr(gProcessBuff_l, gProcessBuff_r);
gXcorIsBusy = false;
//one refinement would be to save results from several runs
//and compute statistics on returned delay time values
//and then only update the delay time when you have a certain
//level of confidence.
}
It functions like this:
First you make a decision about when to execute cross-correlation and then load the arrays (buffers) that cross-correlation function uses:
for(int i = 0; i<DELAY_BUFFER_SIZE; i++)
{
if(++wr>=DELAY_BUFFER_SIZE)
wr = 0;
gProcessBuf_l[i] = gDelayBuffer_l[wr];
gProcessBuf_r[i] = gDelayBuffer_r[wr];
}
Then you tell Bela to schedule a background task to process cross-correlation. Since gProcessBuf_l and gProcessBuff_r are global arrays, they will be in scope for any function defined in render.cpp. When you do this:
Bela_scheduleAuxiliaryTask(gXcorrTask);
It tells Bela to call a function that gXcorrTask points to. You will need to define the association by looking at the example linked. In this case that function you need to associate is this:
void xcorrelation_task()
{
.
.
.
}
Then the xcorrelation_task() calls the function
unsigned int xcorr(float *inl, float *inr)
{
//cross-correlation routine
//returns number of samples delay between inl and inr
return delay;
}
The xcorrelation_task() passes the pointers to gProcessBuff_l and gProcessBuff_r. Within the xcorr function you access them as "inl" and "inr". Should actually name these to "a" and "b" instead of l&r because you aren't cross-correlating left vs right, but rather right_a vs right_b...so sorry for the naming confustion.
Anyway the sequence you want to follow is define and initialize the Bela auxiliary task and make sure Bela is calling it for you:
void xcorrelation_task()
{
gXcorIsBusy = true;
gDelay = xcorr(gProcessBuff_l, gProcessBuff_r);
//temporarily add a print statement so you see something in the console when the auxiliary task is called:
printf("AUX TASK IS RUNNING\n");
gXcorIsBusy = false;
}
Once you see that it can print "AUX TASK IS RUNNING" to the console then you can insert the cross-correlation code into this function:
unsigned int xcorr(float *inl, float *inr)
{
//Insert the cross-correlation routine here
//returns number of samples delay between inl and inr
return delay;
}
In summary, here's what happens:
Bela_scheduleAuxiliaryTask(gXcorrTask);
Tells Bela to call a function in a non-realtime thread. If you associate gXcorrTask correctly, then Bela will call this function:
void xcorrelation_task()
Then that function makes a call to this function and uses its output to set the global delay variable:
unsigned int xcorr(float *inl, float *inr)
This final function is where you put the actual cross-correlation code for processing the 2 buffers.
It will certainly be to your benefit to study the code until you understand it. I learned to program in that way. I wanted to contribute to some open source projects, so I just started opening files and looking at how things were organized until it started to "click". When I ran into concepts or syntax I didn't understand, then this was of great help to me:
http://www.learncpp.com/
and this is a good reference once you are more comfortable with the general concepts:
http://www.cplusplus.com/reference/
and they also have good tutorials:
http://www.cplusplus.com/doc/tutorial/
Unfortunately it does take time but having learned how to program has been a huge benefit. Useful for much more than a one-time school project.
What you are doing right now is the best kind of tutorial as you will get because completing the tutorial means you get something you want in the end 🙂