39 init_effect_details();
48 init_effect_details();
52 void ParametricEQ::init_effect_details()
60 info.
description =
"Filter that allows you to adjust the volume level of a frequency in the audio track.";
68 std::shared_ptr<openshot::Frame>
ParametricEQ::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
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,
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);
114 switch (filter_type) {
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();
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.
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.
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.
float End() const
Get end position (in seconds) of clip (trim end of video)
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)