OpenShot Library | libopenshot
0.3.3
|
Go to the documentation of this file.
23 init_effect_details();
27 void Delay::init_effect_details()
35 info.
description =
"Adjust the synchronism between the audio and video track.";
45 const float max_delay_time = 5;
61 std::shared_ptr<openshot::Frame>
Delay::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
63 const float delay_time_value = (float)
delay_time.
GetValue(frame_number)*(float)frame->SampleRate();
64 int local_write_position;
68 for (
int channel = 0; channel < frame->audio->getNumChannels(); channel++)
70 float *channel_data = frame->audio->getWritePointer(channel);
71 float *delay_data =
delay_buffer.getWritePointer(channel);
74 for (
auto sample = 0; sample < frame->audio->getNumSamples(); ++sample)
76 const float in = (float)(channel_data[sample]);
80 int local_read_position = floorf(read_position);
82 if (local_read_position != local_write_position)
84 float fraction = read_position - (float)local_read_position;
85 float delayed1 = delay_data[(local_read_position + 0)];
87 out = (float)(delayed1 + fraction * (delayed2 - delayed1));
89 channel_data[sample] = in + (out - in);
90 delay_data[local_write_position] = in;
133 catch (
const std::exception& e)
136 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
147 if (!root[
"delay_time"].isNull())
161 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 setup(std::shared_ptr< openshot::Frame > frame)
EffectInfoStruct info
Information about the current effect.
Delay()
Default constructor.
This namespace is the default namespace for all code in the openshot library.
This class adds a delay into the audio.
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into 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...
Json::Value JsonValue() const
Generate Json::Value for this object.
std::string Json() const override
Generate JSON string of this object.
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
void SetJson(const std::string value) override
Load JSON string into this object.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Exception for invalid JSON.
std::string PropertiesJSON(int64_t requested_frame) const override
bool has_audio
Determines if this effect manipulates the audio of a frame.
Header file for Delay audio effect class.
Header file for Frame class.
juce::AudioBuffer< float > delay_buffer
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.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
std::string name
The name of the effect.
Header file for all Exception classes.
int delay_buffer_channels
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.