]> git.sesse.net Git - nageru/blob - nageru/delay_analyzer.h
Make an automated delay estimate, by way of cross-correlation.
[nageru] / nageru / delay_analyzer.h
1 #ifndef _DELAY_ANALYZER_H
2 #define _DELAY_ANALYZER_H 1
3
4 #include <QMainWindow>
5
6 #include <atomic>
7 #include <string>
8
9 #include "audio_clip.h"
10 #include "delay_analyzer_interface.h"
11 #include "input_mapping.h"
12
13 namespace bmusb {
14 struct AudioFormat;
15 }  // namespace bmusb
16
17 namespace Ui {
18 class DelayAnalyzer;
19 }  // namespace Ui
20
21 class QComboBox;
22 class QTimer;
23
24 class DelayAnalyzer : public QMainWindow, public DelayAnalyzerInterface
25 {
26         Q_OBJECT
27
28 public:
29         DelayAnalyzer();
30         ~DelayAnalyzer();
31
32         bool is_grabbing() const override { return grabbing; }
33         void add_audio(DeviceSpec device_spec, const uint8_t *data, unsigned num_samples, bmusb::AudioFormat audio_format, std::chrono::steady_clock::time_point frame_time) override;
34
35 private:
36         void grab_timed_out();
37         void estimate_delay();
38
39         Ui::DelayAnalyzer *ui;
40         AudioClip clip1, clip2;
41
42         void grab_clicked();
43         void card_selected(QComboBox *card_combo, int selected_index);
44         void channel_selected(QComboBox *channel_combo);
45         DeviceSpec get_selected_device(QComboBox *card_combo);
46
47         std::atomic<bool> grabbing{false};
48         std::map<DeviceSpec, DeviceInfo> devices;
49         QTimer *grab_timeout;
50 };
51
52 #endif  // !defined(_DELAY_ANALYZER_H)