37ParametricEQ::ParametricEQ() : filter_type(
LOW_PASS), frequency(500), gain(0), q_factor(0) {
39 init_effect_details();
45 filter_type(new_filter_type), frequency(new_frequency), gain(new_gain), q_factor(new_q_factor)
48 init_effect_details();
52void ParametricEQ::init_effect_details()
60 info.
description =
"Filter that allows you to adjust the volume level of a frequency in the audio track.";
74 for (
int i = 0; i < frame->audio->getNumChannels(); ++i) {
82 const int num_input_channels = frame->audio->getNumChannels();
83 const int num_output_channels = frame->audio->getNumChannels();
84 const int num_samples = frame->audio->getNumSamples();
87 for (
int channel = 0; channel < frame->audio->getNumChannels(); channel++)
89 auto *channel_data = frame->audio->getWritePointer(channel);
90 filters[channel]->processSamples(channel_data, num_samples);
93 for (
int channel = num_input_channels; channel < num_output_channels; ++channel)
95 frame->audio->clear(channel, 0, num_samples);
103 const double discrete_frequency,
104 const double q_factor,
106 const int filter_type)
108 double bandwidth = jmin (discrete_frequency /
q_factor, M_PI * 0.99);
109 double two_cos_wc = -2.0 * cos (discrete_frequency);
110 double tan_half_bw = tan (bandwidth / 2.0);
111 double tan_half_wc = tan (discrete_frequency / 2.0);
112 double sqrt_gain = sqrt (
gain);
116 coefficients = IIRCoefficients ( tan_half_wc,
125 coefficients = IIRCoefficients ( 1.0,
134 coefficients = IIRCoefficients (
gain * tan_half_wc + sqrt_gain,
135 gain * tan_half_wc - sqrt_gain,
137 tan_half_wc + sqrt_gain,
138 tan_half_wc - sqrt_gain,
143 coefficients = IIRCoefficients ( sqrt_gain * tan_half_wc +
gain,
144 sqrt_gain * tan_half_wc -
gain,
146 sqrt_gain * tan_half_wc + 1.0,
147 sqrt_gain * tan_half_wc - 1.0,
152 coefficients = IIRCoefficients ( tan_half_bw,
161 coefficients = IIRCoefficients ( 1.0,
170 coefficients = IIRCoefficients ( sqrt_gain +
gain * tan_half_bw,
171 sqrt_gain * two_cos_wc,
172 sqrt_gain -
gain * tan_half_bw,
173 sqrt_gain + tan_half_bw,
174 sqrt_gain * two_cos_wc,
175 sqrt_gain - tan_half_bw);
180 setCoefficients(coefficients);
185 double discrete_frequency = 2.0 * M_PI * (double)
frequency.
GetValue(frame_number) / sample_rate;
187 double gain_value = pow(10.0, (
double)
gain.
GetValue(frame_number) * 0.05);
190 for (
int i = 0; i <
filters.size(); ++i)
191 filters[i]->updateCoefficients(discrete_frequency, q_value, gain_value, filter_type_value);
226 catch (
const std::exception& e)
229 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
240 if (!root[
"filter_type"].isNull())
243 if (!root[
"frequency"].isNull())
246 if (!root[
"gain"].isNull())
249 if (!root[
"q_factor"].isNull())
258 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
260 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
261 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
262 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
280 return root.toStyledString();
Header file for all Exception classes.
Header file for Parametric EQ audio effect class.
float End() const
Get end position (in seconds) of clip (trim end of video)
float Start() const
Get start position (in seconds) of clip (trim start of video)
float Duration() const
Get the length of this clip (in seconds)
std::string Id() const
Get the Id of this clip object.
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const
Generate JSON for a property.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
EffectInfoStruct info
Information about the current effect.
Exception for invalid JSON.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
double GetValue(int64_t index) const
Get the value at a specific index.
Json::Value JsonValue() const
Generate Json::Value for this object.
void updateCoefficients(const double discrete_frequency, const double q_factor, const double gain, const int filter_type)
std::string PropertiesJSON(int64_t requested_frame) const override
void SetJson(const std::string value) override
Load JSON string into this object.
ParametricEQ()
Blank constructor, useful when using Json to load the effect properties.
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
std::string Json() const override
Generate JSON string of this object.
void updateFilters(int64_t frame_number, double sample_rate)
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
openshot::FilterType filter_type
juce::OwnedArray< Filter > filters
This namespace is the default namespace for all code in the openshot library.
FilterType
This enumeration determines the filter type of ParametricEQ Effect.
const Json::Value stringToJson(const std::string value)
bool has_video
Determines if this effect manipulates the image of a frame.
bool has_audio
Determines if this effect manipulates the audio of a frame.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
std::string description
The description of this effect and what it does.