diff options
Diffstat (limited to 'test/analysis/AnalysisDistortion.c')
| -rw-r--r-- | test/analysis/AnalysisDistortion.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/analysis/AnalysisDistortion.c b/test/analysis/AnalysisDistortion.c new file mode 100644 index 0000000..27b8492 --- /dev/null +++ b/test/analysis/AnalysisDistortion.c @@ -0,0 +1,33 @@ +#include <stdlib.h> +#include "AnalysisDistortion.h" + +// If two samples differ by more than this amount, then we call it distortion +static const Sample kAnalysisDistortionTolerance = 0.5f; + +boolByte analysisDistortion(const SampleBuffer sampleBuffer, AnalysisFunctionData data) +{ + Sample difference; + + for (ChannelCount channelIndex = 0; channelIndex < sampleBuffer->numChannels; channelIndex++) { + for (SampleCount sampleIndex = 0; sampleIndex < sampleBuffer->blocksize; sampleIndex++) { + if (sampleBuffer->samples[channelIndex][sampleIndex] > data->lastSample[channelIndex]) { + difference = sampleBuffer->samples[channelIndex][sampleIndex] - data->lastSample[channelIndex]; + } else { + difference = data->lastSample[channelIndex] - sampleBuffer->samples[channelIndex][sampleIndex]; + } + + if (difference >= kAnalysisDistortionTolerance) { + // In this test, we don't care about the consecutive sample count. That is because + // we also want to detect harsh clicks which occur by a jump in the amplitude, which + // is a common error in many plugins. + data->failedChannel = channelIndex; + data->failedSample = sampleIndex; + return false; + } + + data->lastSample[channelIndex] = sampleBuffer->samples[channelIndex][sampleIndex]; + } + } + + return true; +} |
