Deluge Firmware 1.4.0
Build date: 2026.11.30
Loading...
Searching...
No Matches
delay_finder.h
1/*
2 * Copyright © 2026 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <array>
21#include <cstdint>
22
30
32public:
34 static constexpr int32_t kMaxLag = 352;
37 static constexpr float kMinCorrelation = 0.1f;
38 static constexpr float kMinStandOut = 4.f;
39 static constexpr int32_t kNeighbourhood = 16;
40
41 void reset();
42
44 void process(float mic, float sent);
45
46 struct Result {
47 int32_t delay;
49 float standOut;
50 };
51 [[nodiscard]] Result result() const;
52
53private:
54 static constexpr int32_t kHistory = kMaxLag + 1;
55 // Sent samples, newest first, twice over so the newest kHistory are always contiguous
56 std::array<float, kHistory * 2> sent_{};
57 int32_t pos_ = 0;
58 std::array<float, kMaxLag> correlation_{};
59 float micPower_ = 0;
60 float sentPower_ = 0;
61 float previousMic_ = 0;
62};
63
64} // namespace deluge::dsp::mic_velocity
Definition delay_finder.h:31
static constexpr int32_t kMaxLag
The longest delay looked for, in decimated samples (5.5 kHz): 64 ms.
Definition delay_finder.h:34
void process(float mic, float sent)
One decimated sample: what the mic heard, and what was sent to the codec for the same moment.
Definition delay_finder.cpp:31
static constexpr float kMinCorrelation
Definition delay_finder.h:37
Definition delay_finder.cpp:21
int32_t delay
Decimated samples from sent to heard, or -1 if none stood out.
Definition delay_finder.h:47
float correlation
At the delay, normalised.
Definition delay_finder.h:48
float standOut
How many times the average away from it.
Definition delay_finder.h:49