diff options
| author | pepper <peppersclothescult@gmail.com> | 2015-01-10 21:32:32 -0800 |
|---|---|---|
| committer | pepper <peppersclothescult@gmail.com> | 2015-01-10 21:32:32 -0800 |
| commit | d53fa8a169832563c62262078b8d2ffe5cab8473 (patch) | |
| tree | b911d06d357d009c976709780f10e92ce915228a /test/analysis/AnalysisDistortion.c | |
first
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; +} |
