This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame object
| 50 | // This method is required for all derived classes of EffectBase, and returns a |
| 51 | // modified openshot::Frame object |
| 52 | std::shared_ptr<openshot::Frame> Expander::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) |
| 53 | { |
| 54 | // Adding Expander |
| 55 | const int num_input_channels = frame->audio->getNumChannels(); |
| 56 | const int num_output_channels = frame->audio->getNumChannels(); |
| 57 | const int num_samples = frame->audio->getNumSamples(); |
| 58 | |
| 59 | mixed_down_input.setSize(1, num_samples); |
| 60 | inverse_sample_rate = 1.0f / frame->SampleRate(); |
| 61 | inverseE = 1.0f / M_E; |
| 62 | |
| 63 | if ((bool)bypass.GetValue(frame_number)) |
| 64 | return frame; |
| 65 | |
| 66 | mixed_down_input.clear(); |
| 67 | |
| 68 | for (int channel = 0; channel < num_input_channels; ++channel) |
| 69 | mixed_down_input.addFrom(0, 0, *frame->audio, channel, 0, num_samples, 1.0f / num_input_channels); |
| 70 | |
| 71 | for (int sample = 0; sample < num_samples; ++sample) { |
| 72 | float T = threshold.GetValue(frame_number); |
| 73 | float R = ratio.GetValue(frame_number); |
| 74 | float alphaA = calculateAttackOrRelease(attack.GetValue(frame_number)); |
| 75 | float alphaR = calculateAttackOrRelease(release.GetValue(frame_number)); |
| 76 | float gain = makeup_gain.GetValue(frame_number); |
| 77 | float input_squared = powf(mixed_down_input.getSample(0, sample), 2.0f); |
| 78 | |
| 79 | const float average_factor = 0.9999f; |
| 80 | input_level = average_factor * input_level + (1.0f - average_factor) * input_squared; |
| 81 | |
| 82 | xg = (input_level <= 1e-6f) ? -60.0f : 10.0f * log10f(input_level); |
| 83 | |
| 84 | if (xg > T) |
| 85 | yg = xg; |
| 86 | else |
| 87 | yg = T + (xg - T) * R; |
| 88 | |
| 89 | xl = xg - yg; |
| 90 | |
| 91 | if (xl < yl_prev) |
| 92 | yl = alphaA * yl_prev + (1.0f - alphaA) * xl; |
| 93 | else |
| 94 | yl = alphaR * yl_prev + (1.0f - alphaR) * xl; |
| 95 | |
| 96 | |
| 97 | control = powf (10.0f, (gain - yl) * 0.05f); |
| 98 | yl_prev = yl; |
| 99 | |
| 100 | for (int channel = 0; channel < num_input_channels; ++channel) { |
| 101 | float new_value = frame->audio->getSample(channel, sample)*control; |
| 102 | frame->audio->setSample(channel, sample, new_value); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | for (int channel = num_input_channels; channel < num_output_channels; ++channel) |
| 107 | frame->audio->clear(channel, 0, num_samples); |
| 108 | |
| 109 | // return the modified frame |
nothing calls this directly
no test coverage detected