OpenShot Library | libopenshot
0.4.0
|
Go to the documentation of this file.
23 distortion_type(distortion_type), input_gain(input_gain),
24 output_gain(output_gain), tone(tone)
27 init_effect_details();
31 void Distortion::init_effect_details()
47 std::shared_ptr<openshot::Frame>
Distortion::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
51 for (
int i = 0; i < frame->audio->getNumChannels(); ++i) {
59 for (
int channel = 0; channel < frame->audio->getNumChannels(); channel++)
61 auto *channel_data = frame->audio->getWritePointer(channel);
64 for (
auto sample = 0; sample < frame->audio->getNumSamples(); ++sample)
69 const float in = channel_data[sample]*powf(10.0f, input_gain_value * 0.05f);
75 float threshold = 0.5f;
78 else if (in < -threshold)
86 float threshold1 = 1.0f / 3.0f;
87 float threshold2 = 2.0f / 3.0f;
90 else if (in > threshold1)
91 out = 1.0f - powf (2.0f - 3.0f * in, 2.0f) / 3.0f;
92 else if (in < -threshold2)
94 else if (in < -threshold1)
95 out = -1.0f + powf (2.0f + 3.0f * in, 2.0f) / 3.0f;
104 out = 1.0f - expf (-in);
106 out = -1.0f + expf (in);
124 float filtered =
filters[channel]->processSingleSampleRaw(out);
125 channel_data[sample] = filtered*powf(10.0f, output_gain_value * 0.05f);
135 double discrete_frequency = M_PI * 0.01;
136 double gain = pow(10.0, (
float)
tone.
GetValue(frame_number) * 0.05);
138 for (
int i = 0; i <
filters.size(); ++i)
139 filters[i]->updateCoefficients(discrete_frequency, gain);
151 double tan_half_wc = tan(discrete_frequency / 2.0);
152 double sqrt_gain = sqrt(gain);
154 coefficients = juce::IIRCoefficients( sqrt_gain * tan_half_wc + gain,
155 sqrt_gain * tan_half_wc - gain,
157 sqrt_gain * tan_half_wc + 1.0,
158 sqrt_gain * tan_half_wc - 1.0,
160 setCoefficients(coefficients);
188 catch (
const std::exception& e)
191 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
202 if (!root[
"distortion_type"].isNull())
205 if (!root[
"input_gain"].isNull())
208 if (!root[
"output_gain"].isNull())
211 if (!root[
"tone"].isNull())
235 return root.toStyledString();
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.
const Json::Value stringToJson(const std::string value)
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
EffectInfoStruct info
Information about the current effect.
void updateFilters(int64_t frame_number)
Header file for Distortion audio effect class.
This namespace is the default namespace for all code in the openshot library.
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...
void SetJson(const std::string value) override
Load JSON string into this object.
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Distortion()
Default constructor.
This class adds a distortion into the audio.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
std::string PropertiesJSON(int64_t requested_frame) const override
Json::Value JsonValue() const
Generate Json::Value for this object.
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
openshot::DistortionType distortion_type
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
juce::OwnedArray< Filter > filters
Exception for invalid JSON.
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 description
The description of this effect and what it does.
bool has_video
Determines if this effect manipulates the image of a frame.
std::string name
The name of the effect.
std::string Json() const override
Generate JSON string of this object.
void updateCoefficients(const double discrete_frequency, const double gain)
DistortionType
This enumeration determines the distortion type of Distortion Effect.
Header file for all Exception classes.
virtual 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.