37 Expander::Expander() : threshold(-10), ratio(1), attack(1), release(1), makeup_gain(1), bypass(false) {
39 init_effect_details();
47 init_effect_details();
51 void Expander::init_effect_details()
59 info.
description =
"Louder parts of audio becomes relatively louder and quieter parts becomes quieter.";
71 std::shared_ptr<openshot::Frame>
Expander::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
74 const int num_input_channels = frame->audio->getNumChannels();
75 const int num_output_channels = frame->audio->getNumChannels();
76 const int num_samples = frame->audio->getNumSamples();
87 for (
int channel = 0; channel < num_input_channels; ++channel)
88 mixed_down_input.addFrom(0, 0, *frame->audio, channel, 0, num_samples, 1.0f / num_input_channels);
90 for (
int sample = 0; sample < num_samples; ++sample) {
98 const float average_factor = 0.9999f;
106 yg = T + (xg - T) * R;
111 yl = alphaA *
yl_prev + (1.0f - alphaA) * xl;
113 yl = alphaR *
yl_prev + (1.0f - alphaR) * xl;
116 control = powf (10.0f, (gain - yl) * 0.05f);
119 for (
int channel = 0; channel < num_input_channels; ++channel) {
120 float new_value = frame->audio->getSample(channel, sample)*
control;
121 frame->audio->setSample(channel, sample, new_value);
125 for (
int channel = num_input_channels; channel < num_output_channels; ++channel)
126 frame->audio->clear(channel, 0, num_samples);
174 catch (
const std::exception& e)
177 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
188 if (!root[
"threshold"].isNull())
191 if (!root[
"ratio"].isNull())
194 if (!root[
"attack"].isNull())
197 if (!root[
"release"].isNull())
200 if (!root[
"makeup_gain"].isNull())
203 if (!root[
"bypass"].isNull())
212 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
214 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
215 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
216 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
227 return root.toStyledString();
Expander()
Blank constructor, useful when using Json to load the effect properties.
float inverse_sample_rate
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.
std::string PropertiesJSON(int64_t requested_frame) const override
std::string Json() const override
Generate JSON string of this object.
const Json::Value stringToJson(const std::string value)
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for Expander audio effect class.
Header file for all Exception classes.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
float calculateAttackOrRelease(float value)
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.
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.
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 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.
juce::AudioSampleBuffer mixed_down_input
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
Json::Value JsonValue() const override
Generate Json::Value for this object.
void SetJson(const std::string value) override
Load JSON string into this object.
EffectInfoStruct info
Information about the current effect.