32constexpr int32_t kInputRate = 44100;
33constexpr int32_t kDecimation = 8;
34constexpr float kRate =
static_cast<float>(kInputRate) / kDecimation;
44 std::optional<float>
push(int32_t sample);
48 std::array<int32_t, kDecimation> first_{};
49 std::array<int64_t, kDecimation> second_{};
50 int64_t sumFirst_ = 0;
51 int64_t sumSecond_ = 0;
57 float b0 = 1, b1 = 0, b2 = 0, a1 = 0, a2 = 0;
60 float process(
float x) {
61 float const y = b0 * x + z1;
62 z1 = b1 * x - a1 * y + z2;
66 void reset() { z1 = z2 = 0; }
90 static constexpr int32_t kNumThumps = 16;
99 [[nodiscard]]
float noiseFloor()
const {
return floor_; }
104 [[nodiscard]]
Thump const*
recent(int32_t index)
const;
107 [[nodiscard]]
bool rising()
const {
return inThump_ && !thumps_[newest_].settled; }
109 [[nodiscard]]
bool inThump()
const {
return inThump_; }
115 std::array<Thump, kNumThumps> thumps_{};
118 bool inThump_ =
false;
119 float thumpPeak_ = 0;
127 int32_t blockSamples_ = 0;
128 bool blockHadThump_ =
false;
129 bool floorStarted_ =
false;
130 int32_t sustainedBlocks_ = 0;
Definition thump_detector.h:41
std::optional< float > push(int32_t sample)
Returns a decimated sample every kDecimation inputs.
Definition thump_detector.cpp:54
static constexpr float kOnsetOverFloor
Rising this far over the noise floor starts a thump (12 dB).
Definition thump_detector.h:87
bool inThump() const
Whether a thump is going on (from its onset until it has died away).
Definition thump_detector.h:109
bool rising() const
Whether a thump is in progress (started, not yet settled).
Definition thump_detector.h:107
float noiseFloor() const
The noise floor: a typical 10 ms peak of the band-limited mic with no thump.
Definition thump_detector.h:99
void process(float sample, Frame frame)
One decimated sample of the mic (after any echo cancelling); frame is the input frame it ends at.
Definition thump_detector.cpp:139
static constexpr float kMinOnsetLevel
Never start a thump below this, however quiet the noise (-90 dBFS).
Definition thump_detector.h:89
static constexpr Frame kSettleFrames
How long after onset the level is measured for.
Definition thump_detector.h:83
Thump const * recent(int32_t index) const
The most recent thumps, newest first (0: the newest). nullptr past the ones there are.
Definition thump_detector.cpp:132
float onsetLevel() const
The level a thump has to reach to be found.
Definition thump_detector.cpp:128
static constexpr Frame kMinGapFrames
A thump lasts at least this long.
Definition thump_detector.h:85
Definition delay_finder.cpp:21
constexpr float kRate
5512.5 Hz
Definition thump_detector.h:34
uint32_t Frame
Input frames (at 44.1 kHz) on the mic reader's clock.
Definition thump_detector.h:37
A second-order section, direct form II transposed.
Definition thump_detector.h:56
static Biquad highPass1(float cutoff, float rate)
First order (b2 = a2 = 0).
Definition thump_detector.cpp:73
static Biquad lowPass2(float cutoff, float rate)
Butterworth.
Definition thump_detector.cpp:95
static Biquad lowPass1(float cutoff, float rate)
First order.
Definition thump_detector.cpp:84
A thump: where it rose out of the noise, and how loud it got in the 4 ms after.
Definition thump_detector.h:74
bool settled
Its 4 ms have passed, so level won't change.
Definition thump_detector.h:77
float level
Peak of the band-limited mic, full scale 1.
Definition thump_detector.h:76