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,
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);
93 switch (filter_type) {
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();
void updateFilters(int64_t frame_number, double sample_rate)
std::string Id() const
Get the Id of this clip object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Header file for Parametric EQ audio effect class.
float Start() const
Get start position (in seconds) of clip (trim start of video)
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void SetJson(const std::string value) override
Load JSON string into this object.
virtual float End() const
Get end position (in seconds) of clip (trim end of video)
const Json::Value stringToJson(const std::string value)
FilterType
This enumeration determines the filter type of ParametricEQ Effect.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
bool has_audio
Determines if this effect manipulates the audio of a frame.
std::string PropertiesJSON(int64_t requested_frame) const override
Header file for all Exception classes.
Json::Value JsonValue() const override
Generate Json::Value for this object.
juce::OwnedArray< Filter > filters
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
ParametricEQ()
Blank constructor, useful when using Json to load the effect properties.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
float Duration() const
Get the length of this clip (in seconds)
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
This namespace is the default namespace for all code in the openshot library.
Json::Value JsonValue() const
Generate Json::Value for this object.
std::string description
The description of this effect and what it does.
This class adds a equalization into the audio.
openshot::FilterType filter_type
bool has_video
Determines if this effect manipulates the image of a frame.
Exception for invalid JSON.
double GetValue(int64_t index) const
Get the value at a specific index.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time...
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.
std::string Json() const override
Generate JSON string of this object.
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...
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
EffectInfoStruct info
Information about the current effect.
void updateCoefficients(const double discrete_frequency, const double q_factor, const double gain, const int filter_type)