| 99 | } |
| 100 | |
| 101 | void BeatBloks::Process(double time) |
| 102 | { |
| 103 | PROFILER(BeatBloks); |
| 104 | |
| 105 | IAudioReceiver* target = GetTarget(); |
| 106 | if (!mEnabled || target == nullptr || mSample == nullptr || mLoading) |
| 107 | return; |
| 108 | |
| 109 | ComputeSliders(0); |
| 110 | |
| 111 | if (mWantWrite) |
| 112 | { |
| 113 | DoWrite(); |
| 114 | mWantWrite = false; |
| 115 | } |
| 116 | |
| 117 | int bufferSize = target->GetBuffer()->BufferSize(); |
| 118 | float* out = target->GetBuffer()->GetChannel(0); |
| 119 | assert(bufferSize == gBufferSize); |
| 120 | |
| 121 | float volSq = mVolume * mVolume; |
| 122 | |
| 123 | float clipStart = mClipStart; |
| 124 | float clipEnd = mClipEnd; |
| 125 | if (mPlay && (clipStart < clipEnd)) |
| 126 | { |
| 127 | float speed = float(clipEnd - clipStart) * gInvSampleRateMs / TheTransport->MsPerBar() / mNumBars; |
| 128 | |
| 129 | const float* data = mSample->Data()->GetChannel(0); |
| 130 | int numSamples = mSample->LengthInSamples(); |
| 131 | float sampleRateRatio = mSample->GetSampleRateRatio(); |
| 132 | |
| 133 | mPlayheadRemainder = TheTransport->GetMeasurePos(time) + (TheTransport->GetMeasure(time) % mNumBars); |
| 134 | mPlayheadRemainder /= mNumBars; |
| 135 | mPlayheadRemainder *= clipEnd - clipStart; |
| 136 | mPlayheadWhole = int(mPlayheadRemainder); |
| 137 | mPlayheadRemainder -= mPlayheadWhole; |
| 138 | mPlayheadWhole += int(clipStart); |
| 139 | mPlayheadRemainder += clipStart - int(clipStart); |
| 140 | mPlayheadWhole = MAX(0, mPlayheadWhole); |
| 141 | mPlayheadRemainder = MAX(0.0f, mPlayheadRemainder); |
| 142 | |
| 143 | for (int i = 0; i < bufferSize; ++i) |
| 144 | { |
| 145 | if (mPlayheadWhole >= clipEnd) |
| 146 | mPlayheadWhole -= (clipEnd - clipStart); |
| 147 | if (mPlayheadWhole < clipStart) |
| 148 | mPlayheadWhole += (clipEnd - clipStart); |
| 149 | |
| 150 | out[i] = GetInterpolatedSample(mPlayheadRemainder + 1, data + mPlayheadWhole - 1, numSamples) * volSq; |
| 151 | |
| 152 | mPlayheadRemainder += speed * sampleRateRatio; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | Blok* heldBlok = mHeldBlok; //hold onto it in case it gets nulled in the main thread |
| 157 | if (mPlayBlokPreview && heldBlok) |
| 158 | { |
nothing calls this directly
no test coverage detected