MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / GetFrame

Method GetFrame

src/audio_effects/Echo.cpp:63–105  ·  view source on GitHub ↗

This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame object

Source from the content-addressed store, hash-verified

61// This method is required for all derived classes of EffectBase, and returns a
62// modified openshot::Frame object
63std::shared_ptr<openshot::Frame> Echo::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
64{
65 const float echo_time_value = (float)echo_time.GetValue(frame_number)*(float)frame->SampleRate();
66 const float feedback_value = feedback.GetValue(frame_number);
67 const float mix_value = mix.GetValue(frame_number);
68 int local_write_position;
69
70 setup(frame);
71
72 for (int channel = 0; channel < frame->audio->getNumChannels(); channel++)
73 {
74 float *channel_data = frame->audio->getWritePointer(channel);
75 float *echo_data = echo_buffer.getWritePointer(channel);
76 local_write_position = echo_write_position;
77
78 for (auto sample = 0; sample < frame->audio->getNumSamples(); ++sample)
79 {
80 const float in = (float)(channel_data[sample]);
81 float out = 0.0f;
82
83 float read_position = fmodf((float)local_write_position - echo_time_value + (float)echo_buffer_samples, echo_buffer_samples);
84 int local_read_position = floorf(read_position);
85
86 if (local_read_position != local_write_position)
87 {
88 float fraction = read_position - (float)local_read_position;
89 float echoed1 = echo_data[(local_read_position + 0)];
90 float echoed2 = echo_data[(local_read_position + 1) % echo_buffer_samples];
91 out = (float)(echoed1 + fraction * (echoed2 - echoed1));
92 channel_data[sample] = in + mix_value*(out - in);
93 echo_data[local_write_position] = in + out*feedback_value;
94 }
95
96 if (++local_write_position >= echo_buffer_samples)
97 local_write_position -= echo_buffer_samples;
98 }
99 }
100
101 echo_write_position = local_write_position;
102
103 // return the modified frame
104 return frame;
105}
106
107// Generate JSON string of this object
108std::string Echo::Json() const {

Callers

nothing calls this directly

Calls 2

GetValueMethod · 0.80
SampleRateMethod · 0.45

Tested by

no test coverage detected