]> git.sesse.net Git - nageru/blob - nageru/audio_clip.h
Begin working on a delay analyzer.
[nageru] / nageru / audio_clip.h
1 #ifndef AUDIO_CLIP_H
2 #define AUDIO_CLIP_H
3
4 // A short single-channel recording of an audio clip, for the delay analyzer.
5 // Thread safe.
6
7 #include <chrono>
8 #include <memory>
9 #include <mutex>
10 #include <utility>
11 #include <vector>
12
13 class AudioClip
14 {
15 public:
16         void clear();
17         void add_audio(const float *samples, size_t num_samples, double sample_rate, std::chrono::steady_clock::time_point frame_time);
18         double get_length_seconds() const;
19
20         std::unique_ptr<std::pair<float, float>[]> get_min_max_peaks(unsigned width) const;
21
22 private:
23         mutable std::mutex mu;
24         std::vector<float> vals;  // Under <mutex>.
25         double sample_rate;  // Under <mutex>.
26         std::chrono::steady_clock::time_point first_sample;  // Under <mutex>.
27 };
28
29 #endif