23 filter_type(filter_type),
24 frequency(frequency), gain(gain), q_factor(q_factor)
27 init_effect_details();
31void ParametricEQ::init_effect_details()
39 info.
description =
"Filter that allows you to adjust the volume level of a frequency in the audio track.";
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())
237 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
239 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
240 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
241 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
259 return root.toStyledString();
Header file for all Exception classes.
Header file for Parametric EQ audio effect class.
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)
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
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)
This class adds a equalization into the audio.
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.