| 51 | } |
| 52 | |
| 53 | void tick(float * out_buffer, const int num_frames) |
| 54 | { |
| 55 | const float * windowSamples = window->channel(0)->data(); |
| 56 | |
| 57 | for (int i = 0; i < num_frames; ++i) |
| 58 | { |
| 59 | double result = 0.f; |
| 60 | |
| 61 | if (in_use) |
| 62 | { |
| 63 | sample_accurate_time += sample_increment; |
| 64 | |
| 65 | // Looping behavior |
| 66 | if (sample_accurate_time >= grain_end) |
| 67 | { |
| 68 | sample_accurate_time = static_cast<double>(grain_start); |
| 69 | } |
| 70 | |
| 71 | const uint64_t approximate_sample_index = static_cast<uint64_t>(std::floor(sample_accurate_time)); |
| 72 | const double remainder = sample_accurate_time - approximate_sample_index; |
| 73 | |
| 74 | uint64_t left = approximate_sample_index; |
| 75 | uint64_t right = approximate_sample_index + 1; |
| 76 | if (right >= sample->length()) right = 0; |
| 77 | |
| 78 | // interpolate sample positions (primarily for speed alterations, can be more sophisticated with this later) |
| 79 | result = (double) ((1.0 - remainder) * sample->channel(0)->data()[left] + remainder * sample->channel(0)->data()[right]); |
| 80 | } |
| 81 | |
| 82 | envelope_index++; |
| 83 | |
| 84 | if (envelope_index == grain_duration) |
| 85 | { |
| 86 | //in_use = false; |
| 87 | envelope_index = 0; |
| 88 | } |
| 89 | |
| 90 | // Apply envelope |
| 91 | out_buffer[i] += static_cast<float>(result * windowSamples[envelope_index]); |
| 92 | } |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | virtual bool propagatesSilence(ContextRenderLock & r) const override; |
no test coverage detected