-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced_eq_harmonics.h
More file actions
123 lines (104 loc) · 4.69 KB
/
advanced_eq_harmonics.h
File metadata and controls
123 lines (104 loc) · 4.69 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// ./advanced_eq_harmonics.h
// Header for Harmonic Enhancer and Linear Phase EQ (Final Corrected Version)
#pragma once
#include "SimpleBiquad.h"
#include "AudioEffect.h"
#include <vector>
#include <cmath>
#include <complex>
#include <string>
#include <nlohmann/json.hpp>
#include <fftw3.h>
// ◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️↓修正開始◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️
// パラメトリックEQ (IIRフィルタベース)
class ParametricEQ : public AudioEffect {
public:
void setup(double sr, const json& params) override;
void process(std::vector<float>& block, int channels) override;
void reset() override;
const std::string& getName() const override { return name_; }
private:
std::string name_ = "parametric_eq";
bool enabled_ = true;
double sample_rate_ = 48000.0;
// 2チャンネル分のフィルターを保持
std::vector<SimpleBiquad> filters_l_;
std::vector<SimpleBiquad> filters_r_;
};
// ◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️↑修正終わり◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️
// 線形位相EQ(FFTベース)
class LinearPhaseEQ : public AudioEffect {
public:
LinearPhaseEQ();
~LinearPhaseEQ() override;
void setup(double sr, const json& params) override;
void process(std::vector<float>& block, int channels) override;
void reset() override;
const std::string& getName() const override { return name_; }
private:
// ◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️↓修正開始◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️
std::string name_ = "linear_phase_eq";
// ◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️↑修正終わり◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️
double sample_rate_ = 44100.0;
size_t fft_size_ = 2048;
size_t hop_size_ = 512;
bool enabled_ = true;
int channels_ = 0;
// 左右チャンネル用のFFTプランとバッファ
fftwf_plan fft_plan_fwd_L_, fft_plan_fwd_R_;
fftwf_plan fft_plan_bwd_L_, fft_plan_bwd_R_;
std::vector<float> window_;
// 処理に使用するバッファ
std::vector<float> time_domain_buffer_L_, time_domain_buffer_R_;
std::vector<std::complex<float>> freq_domain_buffer_L_, freq_domain_buffer_R_;
// EQカーブ
std::vector<std::complex<float>> eq_curve_;
// Overlap-Add法のための入出力バッファ
std::vector<float> input_buffer_L_, input_buffer_R_;
std::vector<float> output_buffer_L_, output_buffer_R_;
size_t input_buffer_write_pos_ = 0;
void setupEQCurve(const json& bands);
void applyEQBand(double freq, double gain_db, double q, const std::string& type);
};
// ハーモニックエンハンサー
class HarmonicEnhancer : public AudioEffect {
public:
void setup(double sr, const json& params) override;
void process(std::vector<float>& block, int channels) override;
void reset() override;
const std::string& getName() const override { return name_; }
private:
// ◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️↓修正開始◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️
std::string name_ = "harmonic_enhancer";
// ◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️↑修正終わり◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️
double sample_rate_ = 44100.0;
bool enabled_ = true;
double drive_ = 0.3;
double even_harmonics_ = 0.2;
double odd_harmonics_ = 0.3;
double mix_ = 0.25;
SimpleBiquad dc_blocker_, lowpass_;
float generateHarmonics(float input);
float processSample(float sample);
};
// スペクトラルゲート(ノイズ除去)
class SpectralGate : public AudioEffect {
public:
void setup(double sr, const json& params) override;
void process(std::vector<float>& block, int channels) override;
void reset() override;
const std::string& getName() const override { return name_; }
private:
// ◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️↓修正開始◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️
std::string name_ = "spectral_gate";
// ◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️↑修正終わり◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️◾️
double sample_rate_ = 44100.0;
bool enabled_ = false;
double threshold_db_ = -60.0;
double attack_ms_ = 5.0;
double release_ms_ = 100.0;
float current_gain_ = 0.0f;
double attack_coeff_ = 0.0;
double release_coeff_ = 0.0;
float processSample(float sample);
};