-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequalizer.h
103 lines (70 loc) · 2.49 KB
/
equalizer.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
This file is part of Waver
Copyright (C) 2021 Peter Papp
Please visit https://launchpad.net/waver for details
*/
#ifndef EQUALIZER_H
#define EQUALIZER_H
#include <QAudioFormat>
#include <QByteArray>
#include <QMutex>
#include <QObject>
#include <QtGlobal>
#include <QVector>
#include <iirfilter.h>
#include <iirfilterchain.h>
#include <iirfiltercallback.h>
#include "globals.h"
#define BANDS_3 { 62, 750, 5000 }
#define BANDS_4 { 62, 500, 2500, 7500 }
#define BANDS_5 { 62, 250, 750, 2500, 7500 }
#define BANDS_6 { 31, 62, 125, 250, 2500, 7500 }
#define BANDS_7 { 31, 62, 125, 250, 2500, 5000, 12500 }
#define BANDS_8 { 31, 62, 125, 250, 750, 2500, 5000, 12500 }
#define BANDS_9 { 31, 62, 125, 250, 500, 1000, 2500, 5000, 12500 }
#define BANDS_10 { 31, 62, 125, 250, 500, 1000, 2500, 5000, 10000, 16000 }
class Equalizer : public QObject, IIRFilterCallback {
Q_OBJECT
public:
struct Band {
double centerFrequency;
double bandwidth;
};
typedef QVector<Band> Bands;
static Bands calculateBands(QVector<double> centerFrequencies);
static Bands calculateBands(std::initializer_list<double> centerFrequencies);
Equalizer(QAudioFormat format);
~Equalizer();
void setChunkQueue(TimedChunkQueue *chunkQueue, QMutex *chunkQueueMutex);
void setGains(bool on, QVector<double> gains, double preAmp);
void filterCallback(double *sample, int channelIndex) override;
QVector<double> getBandCenterFrequencies();
private:
QAudioFormat format;
bool on;
Bands bands;
QVector<double> gains;
double preAmp;
QMutex filtersMutex;
TimedChunkQueue *chunkQueue;
QMutex *chunkQueueMutex;
IIRFilter::SampleTypes sampleType;
int sampleRate;
double replayGain;
double currentReplayGain;
IIRFilterChain *equalizerFilters;
double eqOffMinValue;
double eqOffMaxValue;
int eqOffCurrentChannel;
void createFilters();
public slots:
void run();
void chunkAvailable(int maxToProcess);
void playBegins();
void setReplayGain(double replayGain);
void requestForReplayGainInfo();
signals:
void chunkEqualized(TimedChunk chunk);
void replayGainChanged(double current);
};
#endif // EQUALIZER_H