This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame object
| 59 | // This method is required for all derived classes of EffectBase, and returns a |
| 60 | // modified openshot::Frame object |
| 61 | std::shared_ptr<openshot::Frame> Delay::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) |
| 62 | { |
| 63 | const float delay_time_value = (float)delay_time.GetValue(frame_number)*(float)frame->SampleRate(); |
| 64 | int local_write_position; |
| 65 | |
| 66 | setup(frame); |
| 67 | |
| 68 | for (int channel = 0; channel < frame->audio->getNumChannels(); channel++) |
| 69 | { |
| 70 | float *channel_data = frame->audio->getWritePointer(channel); |
| 71 | float *delay_data = delay_buffer.getWritePointer(channel); |
| 72 | local_write_position = delay_write_position; |
| 73 | |
| 74 | for (auto sample = 0; sample < frame->audio->getNumSamples(); ++sample) |
| 75 | { |
| 76 | const float in = (float)(channel_data[sample]); |
| 77 | float out = 0.0f; |
| 78 | |
| 79 | float read_position = fmodf((float)local_write_position - delay_time_value + (float)delay_buffer_samples, delay_buffer_samples); |
| 80 | int local_read_position = floorf(read_position); |
| 81 | |
| 82 | if (local_read_position != local_write_position) |
| 83 | { |
| 84 | float fraction = read_position - (float)local_read_position; |
| 85 | float delayed1 = delay_data[(local_read_position + 0)]; |
| 86 | float delayed2 = delay_data[(local_read_position + 1) % delay_buffer_samples]; |
| 87 | out = (float)(delayed1 + fraction * (delayed2 - delayed1)); |
| 88 | |
| 89 | channel_data[sample] = in + (out - in); |
| 90 | delay_data[local_write_position] = in; |
| 91 | } |
| 92 | |
| 93 | if (++local_write_position >= delay_buffer_samples) |
| 94 | local_write_position -= delay_buffer_samples; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | delay_write_position = local_write_position; |
| 99 | |
| 100 | // return the modified frame |
| 101 | return frame; |
| 102 | } |
| 103 | |
| 104 | // Generate JSON string of this object |
| 105 | std::string Delay::Json() const { |
nothing calls this directly
no test coverage detected