39 init_effect_details();
47 init_effect_details();
51 void Distortion::init_effect_details()
67 std::shared_ptr<openshot::Frame>
Distortion::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
71 for (
int i = 0; i < frame->audio->getNumChannels(); ++i) {
79 for (
int channel = 0; channel < frame->audio->getNumChannels(); channel++)
81 auto *channel_data = frame->audio->getWritePointer(channel);
84 for (
auto sample = 0; sample < frame->audio->getNumSamples(); ++sample)
89 const float in = channel_data[sample]*powf(10.0f, input_gain_value * 0.05f);
95 float threshold = 0.5f;
98 else if (in < -threshold)
106 float threshold1 = 1.0f / 3.0f;
107 float threshold2 = 2.0f / 3.0f;
110 else if (in > threshold1)
111 out = 1.0f - powf (2.0f - 3.0f * in, 2.0f) / 3.0f;
112 else if (in < -threshold2)
114 else if (in < -threshold1)
115 out = -1.0f + powf (2.0f + 3.0f * in, 2.0f) / 3.0f;
124 out = 1.0f - expf (-in);
126 out = -1.0f + expf (in);
144 float filtered =
filters[channel]->processSingleSampleRaw(out);
145 channel_data[sample] = filtered*powf(10.0f, output_gain_value * 0.05f);
155 double discrete_frequency = M_PI * 0.01;
156 double gain = pow(10.0, (
float)
tone.
GetValue(frame_number) * 0.05);
158 for (
int i = 0; i <
filters.size(); ++i)
159 filters[i]->updateCoefficients(discrete_frequency, gain);
171 double tan_half_wc = tan(discrete_frequency / 2.0);
172 double sqrt_gain = sqrt(gain);
174 coefficients = juce::IIRCoefficients( sqrt_gain * tan_half_wc + gain,
175 sqrt_gain * tan_half_wc - gain,
177 sqrt_gain * tan_half_wc + 1.0,
178 sqrt_gain * tan_half_wc - 1.0,
180 setCoefficients(coefficients);
208 catch (
const std::exception& e)
211 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
222 if (!root[
"distortion_type"].isNull())
225 if (!root[
"input_gain"].isNull())
228 if (!root[
"output_gain"].isNull())
231 if (!root[
"tone"].isNull())
240 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
242 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
243 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
244 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
260 return root.toStyledString();
openshot::DistortionType distortion_type
juce::OwnedArray< Filter > filters
std::string Id() const
Get the Id of this clip object.
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.
const Json::Value stringToJson(const std::string value)
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
std::string Json() const override
Generate JSON string of this object.
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for all Exception classes.
void updateFilters(int64_t frame_number)
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
void SetJson(const std::string value) override
Load JSON string into this object.
Header file for Distortion audio effect class.
std::string class_name
The class name of the effect.
std::string name
The name of the effect.
DistortionType
This enumeration determines the distortion type of Distortion Effect.
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...
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.
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.
Distortion()
Blank constructor, useful when using Json to load the effect properties.
void updateCoefficients(const double discrete_frequency, const double gain)
float End() const
Get end position (in seconds) of clip (trim end of video)
std::string PropertiesJSON(int64_t requested_frame) const override
Json::Value JsonValue() const override
Generate Json::Value for this object.
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.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
EffectInfoStruct info
Information about the current effect.