23 filter_type(filter_type),
24 frequency(frequency), gain(gain), q_factor(q_factor)
27 init_effect_details();
31 void ParametricEQ::init_effect_details()
39 info.
description =
"Filter that allows you to adjust the volume level of a frequency in the audio track.";
47 std::shared_ptr<openshot::Frame>
ParametricEQ::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
53 for (
int i = 0; i < frame->audio->getNumChannels(); ++i) {
61 const int num_input_channels = frame->audio->getNumChannels();
62 const int num_output_channels = frame->audio->getNumChannels();
63 const int num_samples = frame->audio->getNumSamples();
66 for (
int channel = 0; channel < frame->audio->getNumChannels(); channel++)
68 auto *channel_data = frame->audio->getWritePointer(channel);
69 filters[channel]->processSamples(channel_data, num_samples);
72 for (
int channel = num_input_channels; channel < num_output_channels; ++channel)
74 frame->audio->clear(channel, 0, num_samples);
82 const double discrete_frequency,
83 const double q_factor,
85 const int filter_type)
87 double bandwidth = jmin (discrete_frequency /
q_factor, M_PI * 0.99);
88 double two_cos_wc = -2.0 * cos (discrete_frequency);
89 double tan_half_bw = tan (bandwidth / 2.0);
90 double tan_half_wc = tan (discrete_frequency / 2.0);
91 double sqrt_gain = sqrt (
gain);
95 coefficients = IIRCoefficients ( tan_half_wc,
104 coefficients = IIRCoefficients ( 1.0,
113 coefficients = IIRCoefficients (
gain * tan_half_wc + sqrt_gain,
114 gain * tan_half_wc - sqrt_gain,
116 tan_half_wc + sqrt_gain,
117 tan_half_wc - sqrt_gain,
122 coefficients = IIRCoefficients ( sqrt_gain * tan_half_wc +
gain,
123 sqrt_gain * tan_half_wc -
gain,
125 sqrt_gain * tan_half_wc + 1.0,
126 sqrt_gain * tan_half_wc - 1.0,
131 coefficients = IIRCoefficients ( tan_half_bw,
140 coefficients = IIRCoefficients ( 1.0,
149 coefficients = IIRCoefficients ( sqrt_gain +
gain * tan_half_bw,
150 sqrt_gain * two_cos_wc,
151 sqrt_gain -
gain * tan_half_bw,
152 sqrt_gain + tan_half_bw,
153 sqrt_gain * two_cos_wc,
154 sqrt_gain - tan_half_bw);
159 setCoefficients(coefficients);
164 double discrete_frequency = 2.0 * M_PI * (double)
frequency.
GetValue(frame_number) / sample_rate;
166 double gain_value = pow(10.0, (
double)
gain.
GetValue(frame_number) * 0.05);
169 for (
int i = 0; i <
filters.size(); ++i)
170 filters[i]->updateCoefficients(discrete_frequency, q_value, gain_value, filter_type_value);
205 catch (
const std::exception& e)
208 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
219 if (!root[
"filter_type"].isNull())
222 if (!root[
"frequency"].isNull())
225 if (!root[
"gain"].isNull())
228 if (!root[
"q_factor"].isNull())
254 return root.toStyledString();