37Echo::Echo() : echo_time(0.1), feedback(0.5), mix(0.5) {
39 init_effect_details();
44 echo_time(new_echo_time), feedback(new_feedback), mix(new_mix)
47 init_effect_details();
51void Echo::init_effect_details()
59 info.
description =
"Reflection of sound with a delay after the direct sound.";
69 const float max_echo_time = 5;
85std::shared_ptr<openshot::Frame>
Echo::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
87 const float echo_time_value = (float)
echo_time.
GetValue(frame_number)*(float)frame->SampleRate();
90 int local_write_position;
94 for (
int channel = 0; channel < frame->audio->getNumChannels(); channel++)
96 float *channel_data = frame->audio->getWritePointer(channel);
97 float *echo_data =
echo_buffer.getWritePointer(channel);
100 for (
auto sample = 0; sample < frame->audio->getNumSamples(); ++sample)
102 const float in = (float)(channel_data[sample]);
106 int local_read_position = floorf(read_position);
108 if (local_read_position != local_write_position)
110 float fraction = read_position - (float)local_read_position;
111 float echoed1 = echo_data[(local_read_position + 0)];
113 out = (float)(echoed1 + fraction * (echoed2 - echoed1));
114 channel_data[sample] = in + mix_value*(out - in);
115 echo_data[local_write_position] = in + out*feedback_value;
160 catch (
const std::exception& e)
163 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
174 if (!root[
"echo_time"].isNull())
176 if (!root[
"feedback"].isNull())
178 if (!root[
"mix"].isNull())
187 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
189 root[
"start"] =
add_property_json(
"Start",
Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
190 root[
"end"] =
add_property_json(
"End",
End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
191 root[
"duration"] =
add_property_json(
"Duration",
Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
199 return root.toStyledString();
Header file for Echo audio effect class.
Header file for all Exception classes.
float End() const
Get end position (in seconds) of clip (trim end of video)
float Start() const
Get start position (in seconds) of clip (trim start of video)
float Duration() const
Get the length of this clip (in seconds)
std::string Id() const
Get the Id of this clip object.
int Layer() const
Get layer of clip on timeline (lower number is covered by higher numbers)
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.
void SetJson(const std::string value) override
Load JSON string into this object.
std::string Json() const override
Generate JSON string of this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
juce::AudioSampleBuffer echo_buffer
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 override
Generate Json::Value for this object.
Echo()
Blank constructor, useful when using Json to load the effect properties.
std::string PropertiesJSON(int64_t requested_frame) const override
void setup(std::shared_ptr< openshot::Frame > frame)
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
EffectInfoStruct info
Information about the current effect.
Exception for invalid JSON.
A Keyframe is a collection of Point instances, which is used to vary a number or property over time.
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.
Json::Value JsonValue() const
Generate Json::Value for this object.
This namespace is the default namespace for all code in the openshot library.
const Json::Value stringToJson(const std::string value)
bool has_video
Determines if this effect manipulates the image of a frame.
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 name
The name of the effect.
std::string description
The description of this effect and what it does.