1

I want to perform a cross-correlation of two audio files (which are actually NSData objects). I found a vDSP_convD function in accelerate framework. NSData has a property bytes which returns a pointer to an array of voids - that is the parameter of the filter and signal vector.

I struggled with other parameters. What is the length of these vectors or the length of the result vectors?

I guess:

it's the sum of the filter and signal vector.

Could anyone give me an example of using the vDSP_convD function?

Apple reference to the function is here

Thanks

ChenYilong
  • 8,543
  • 9
  • 56
  • 84
Patrik Vaberer
  • 646
  • 6
  • 15

2 Answers2

0

a call would look like this:

vDSP_conv ( signal *, signalStride, filter *, filterStride, result*, resultStride, resultLenght, filterLength );

where we have:

  • signal*: a pointer to the first element of your signal array
  • signalStride: the lets call it "step size" throug your signal array. 1 is every element, 2 is every second ...
  • same for filter and result array
  • length for result and filter array

How long do the arrays have to be?:

As stated in the docs you linked our signal array has to be lenResult + lenFilter - 1 which it is where it gets a little messy. You can find a demonstration of this by Apple here or a shorter answer by SO user Rasman here. You have to do the zero padding of the signal array by yourself so the vector functions can apply the sliding window without preparation.

Note: You might consider using the Fast-Fourier-Transformation for this, because when you work with audio files i assume, that you have quite some data and there is a significant performance increase from a certain point onwards when using:

FFT -> complex multiplication in frequency domain (which results in a correlation in time domain) -> reverse FFT

here you can find a useful piece of code for this!

Community
  • 1
  • 1
Maximilian Körner
  • 846
  • 11
  • 31
0

After reading a book - Learning Core Audio, I have made a demo which demonstrates delay between two audio files. I used new iOS 8 API to get samples from the audio files and a good performance optimization.

Github Project.

Community
  • 1
  • 1
Patrik Vaberer
  • 646
  • 6
  • 15