Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsinewavevalidator_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSINEWAVEVALIDATOR_H
5#define QSINEWAVEVALIDATOR_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <array>
19
20#include <QtCore/qtconfigmacros.h>
21
22QT_BEGIN_NAMESPACE
23
24// sine wave validator: accumulating peak value and result of passing the signal through a notch
25// filter. A sine wave of that frequency should not pass the notch filter, so if the peak exceeds a
26// small threshold, it we can detect discontinuities for example.
27struct QSineWaveValidator
28{
29 QSineWaveValidator(const QSineWaveValidator &) = delete;
30 QSineWaveValidator(QSineWaveValidator &&) = delete;
31 QSineWaveValidator &operator=(const QSineWaveValidator &) = delete;
32 QSineWaveValidator &operator=(QSineWaveValidator &&) = delete;
33
34 QSineWaveValidator(float notchFrequency, float sampleRate);
35
36 void feedSample(float sample);
37
38 float peak() const { return accumPeak; }
39 float notchPeak() const;
40
41private:
42 float a0, a1, a2;
43 float b0, b1, b2;
44
45 std::array<float, 3> x{}, y{};
46 int framesBeforeAnalysis = 128; // unscientific estimate, larger than the transient response
47 // time for the IIR filter
48 int pendingFramesBeforeAnalysis = framesBeforeAnalysis;
49
50 float accumPeak{};
51 float accumNotchPeak{};
52};
53
55
56#endif // QSINEWAVEVALIDATOR_H