Skip to content

Commit

Permalink
More reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
cannam committed Jul 5, 2024
1 parent 22c606d commit 666b5e4
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/test/TestLiveShifter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,45 @@ static void check_sinusoid_shifted(int n, int rate, float freq, float shift,

int reportedDelay = shifter.getStartDelay();

int lastCrossing = -1;
int nCrossings = 0;
int accWavelength = 0;
int minWavelength = 0;
int maxWavelength = 0;
for (int i = reportedDelay; i < endpoint; ++i) {
if (out[i-1] < 0.f && out[i] >= 0.f) {
if (lastCrossing >= 0) {
int wavelength = i - lastCrossing;
accWavelength += wavelength;
if (minWavelength == 0 || wavelength < minWavelength) {
minWavelength = wavelength;
}
if (maxWavelength == 0 || wavelength > maxWavelength) {
maxWavelength = wavelength;
}
cerr << wavelength << " ";
nCrossings ++;
}
lastCrossing = i;
}
}
cerr << endl;

int avgWavelength = 1;
if (nCrossings > 0) {
avgWavelength = accWavelength / nCrossings;
}
double detectedFreq = double(rate) / double(avgWavelength);
cerr << "nCrossings = " << nCrossings << ", minWavelength = " << minWavelength << ", maxWavelength = " << maxWavelength << ", avgWavelength = " << avgWavelength << ", detectedFreq = " << detectedFreq << " (expected " << freq * shift << ")" << endl;

int slackpart = 2048;
int delay = reportedDelay + slackpart;

// Align to the next zero-crossing in output, as phase may differ

for (int i = delay; i < endpoint; ++i) {
if (out[i] < 0.f && out[i+1] >= 0.f) {
cerr << "zc: at " << i << " we have " << out[i] << ", " << out[i+1] << endl;
delay = i+1;
break;
}
Expand All @@ -216,9 +248,9 @@ static void check_sinusoid_shifted(int n, int rate, float freq, float shift,
cerr << "Adjusted delay from reported value of " << reportedDelay
<< " by adding slack of " << slackpart
<< " and moving to next positive zero crossing at " << delay << endl;

float eps = 1.0e-3f;

float eps = 1.0e-3f;

#ifdef USE_BQRESAMPLER
eps = 1.0e-2f;
#endif
Expand Down

0 comments on commit 666b5e4

Please sign in to comment.