forked from mika314/melonix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.hpp
39 lines (34 loc) · 831 Bytes
/
spec.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include "range.hpp"
#include <deque>
#include <fftw3.h>
#include <list>
#include <span>
#include <thread>
#include <unordered_set>
#include <vector>
class Spec
{
public:
Spec(std::span<float> wav);
~Spec();
auto getSpec(int start, int end) const -> std::vector<float>;
private:
std::span<float> wav;
mutable fftw_plan plan;
mutable fftw_complex *input;
mutable fftw_complex *output;
std::atomic<bool> running{false};
mutable std::mutex mutex;
mutable std::unordered_set<Range, pair_hash> jobs;
std::thread thread;
struct S
{
std::vector<float> spec;
std::list<Range>::iterator age;
};
mutable std::unordered_map<Range, S, pair_hash> range2Spec;
mutable std::list<Range> age;
auto run() -> void;
auto internalGetSpec(int start, int end) const -> std::vector<float>;
};