Krotos Modules 3
Loading...
Searching...
No Matches
KrotosAudioBufferDSPCorrelation.cpp
Go to the documentation of this file.
1/*
2==============================================================================
3
4KrotosAudioBufferDSP.cpp
5Created: 13 June 2019 12:22:00am
6Author: sandyw
7
8==============================================================================
9*/
10
11namespace krotos
12{
13
14 // Comparison of IPP version of crossCorrelate with software reference version
15 // Typical result, IPP = 0.156485021, reference = 0.156484197
16 // Very close, but not identical - doesn't matter in practice
17
18 float KrotosAudioBufferDSP::crossCorrelate(const float* referencePointer, const float* candidatePointer,
19 const int testSize)
20 {
21 float cross{0}; // Accumulator
22 static const int GANGWIDTH{4};
23 int testSizeForGangs = testSize - testSize % GANGWIDTH;
24
25 // TODO: Investigate pragmas to force SIMD use, or equivalent
26
27 // Iterate as much as possible gang wide ...
28 int i = 0;
29 for (; i < testSizeForGangs; i += GANGWIDTH)
30 {
31 if (threadShouldExit())
32 {
33 return 0.0f;
34 }
35 cross = cross + candidatePointer[i] * referencePointer[i];
36 cross = cross + candidatePointer[i + 1] * referencePointer[i + 1];
37 cross = cross + candidatePointer[i + 2] * referencePointer[i + 2];
38 cross = cross + candidatePointer[i + 3] * referencePointer[i + 3];
39 }
40 // ... then iterate though the remainder
41 for (; i < testSize; i++)
42 {
43 if (threadShouldExit())
44 {
45 return 0.0f;
46 }
47 cross = cross + candidatePointer[i] * referencePointer[i];
48 }
49 return cross / static_cast<float>(testSize);
50 }
51
52 float KrotosAudioBufferDSP::autoCorrelateCentred(int centerIndex, int testSize)
53 {
54 if (testSize <= 0)
55 {
56 return 0.0f;
57 }
58 const float* candidatePointer = getReadPointer(0) + centerIndex;
59 int indexMin = centerIndex - testSize;
60 if (indexMin < 0)
61 {
62 return 0.0f;
63 }
64 int indexMax = centerIndex + testSize;
65 if (indexMax >= getNumSamples())
66 {
67 return 0.0f;
68 }
69 const float* referencePointer = getReadPointer(0) + indexMin;
70
71 return crossCorrelate(referencePointer, candidatePointer, testSize);
72 }
73
74} // namespace krotos
float crossCorrelate(const float *referencePointer, const float *candidatePointer, const int testSize)
crossCorrelate - Perform a cross-correlation function
Definition KrotosAudioBufferDSPCorrelation.cpp:18
float autoCorrelateCentred(int centerIndex, int testSize)
autoCorrelateCentred - Autocorrelate both sides of supplied index
Definition KrotosAudioBufferDSPCorrelation.cpp:52
Definition AirAbsorptionFilter.cpp:2