OpenShot Library | libopenshot
0.3.3
|
Go to the documentation of this file.
24 threshold(threshold), ratio(ratio), attack(attack),
25 release(release), makeup_gain(makeup_gain), bypass(bypass),
26 input_level(0.0), yl_prev(0.0)
29 init_effect_details();
33 void Compressor::init_effect_details()
41 info.
description =
"Reduce the volume of loud sounds or amplify quiet sounds.";
48 std::shared_ptr<openshot::Frame>
Compressor::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
51 const int num_input_channels = frame->audio->getNumChannels();
52 const int num_output_channels = frame->audio->getNumChannels();
53 const int num_samples = frame->audio->getNumSamples();
64 for (
int channel = 0; channel < num_input_channels; ++channel)
65 mixed_down_input.addFrom(0, 0, *frame->audio, channel, 0, num_samples, 1.0f / num_input_channels);
67 for (
int sample = 0; sample < num_samples; ++sample) {
82 yg = T + (
xg - T) / R;
91 control = powf (10.0f, (gain -
yl) * 0.05f);
94 for (
int channel = 0; channel < num_input_channels; ++channel) {
95 float new_value = frame->audio->getSample(channel, sample)*
control;
96 frame->audio->setSample(channel, sample, new_value);
100 for (
int channel = num_input_channels; channel < num_output_channels; ++channel)
101 frame->audio->clear(channel, 0, num_samples);
149 catch (
const std::exception& e)
152 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
163 if (!root[
"threshold"].isNull())
166 if (!root[
"ratio"].isNull())
169 if (!root[
"attack"].isNull())
172 if (!root[
"release"].isNull())
175 if (!root[
"makeup_gain"].isNull())
178 if (!root[
"bypass"].isNull())
197 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)
EffectInfoStruct info
Information about the current effect.
Compressor()
Default constructor.
This namespace is the default namespace for all code in the openshot library.
std::string Json() const override
Generate JSON string of this object.
void SetJson(const std::string value) override
Load JSON string into this object.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
float calculateAttackOrRelease(float value)
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)
Header file for Compressor audio effect class.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Exception for invalid JSON.
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for Frame class.
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...
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.
float inverse_sample_rate
std::string name
The name of the effect.
std::string PropertiesJSON(int64_t requested_frame) const override
juce::AudioBuffer< float > mixed_down_input
This class adds a compressor into the audio.
Header file for all Exception classes.
Json::Value JsonValue() const override
Generate Json::Value for this object.
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.