MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / ConsumeData

Method ConsumeData

Source/Sample.cpp:203–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201}
202
203bool Sample::ConsumeData(double time, ChannelBuffer* out, int size, bool replace)
204{
205 assert(size <= out->BufferSize());
206
207 mPlayMutex.lock();
208 float end = mNumSamples;
209 if (mStopPoint != -1)
210 end = mStopPoint;
211
212 if (mLooping && mOffset >= mNumSamples)
213 mOffset -= mNumSamples;
214
215 if (mOffset >= end || std::isnan(mOffset))
216 {
217 mPlayMutex.unlock();
218 return false;
219 }
220
221 LockDataMutex(true);
222 for (int i = 0; i < size; ++i)
223 {
224 if (time < mStartTime)
225 {
226 if (replace)
227 {
228 for (int ch = 0; ch < out->NumActiveChannels(); ++ch)
229 out->GetChannel(ch)[i] = 0;
230 }
231 }
232 else
233 {
234 for (int ch = 0; ch < out->NumActiveChannels(); ++ch)
235 {
236 int dataChannel = MIN(ch, mData.NumActiveChannels() - 1);
237
238 float sample = 0;
239 if (mOffset < end || mLooping)
240 sample = GetInterpolatedSample(mOffset, mData.GetChannel(dataChannel), mNumSamples) * mVolume;
241
242 if (replace)
243 out->GetChannel(ch)[i] = sample;
244 else
245 out->GetChannel(ch)[i] += sample;
246 }
247
248 mOffset += mRate * mSampleRateRatio;
249 }
250 time += gInvSampleRateMs;
251 }
252 LockDataMutex(false);
253 mPlayMutex.unlock();
254
255 return true;
256}
257
258void Sample::PadBack(int amount)
259{

Callers 7

ProcessMethod · 0.80
ProcessMethod · 0.80
ProcessMethod · 0.80
CheckboxUpdatedMethod · 0.80
ProcessMethod · 0.80
ProcessMethod · 0.80
ProcessMethod · 0.80

Calls 4

GetInterpolatedSampleFunction · 0.85
BufferSizeMethod · 0.80
NumActiveChannelsMethod · 0.80
GetChannelMethod · 0.80

Tested by

no test coverage detected