MCPcopy Create free account
hub / github.com/davy7125/polyphone / getDataWithLoop

Method getDataWithLoop

sources/sound_engine/voice.cpp:385–429  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383}
384
385void Voice::getDataWithLoop(quint32 goOn, quint32 loopStart, quint32 loopEnd, qint16 * &srcData16, quint8 * &srcData24)
386{
387 // New sample position
388 _currentSmplPos += goOn;
389
390 // Possibly go back to the beginning of the loop
391 while (_currentSmplPos >= loopEnd)
392 _currentSmplPos += loopStart - loopEnd;
393
394 // If at least RESAMPLING_ORDER points are available after the current position, use a pointer to the data directly
395 if ((_moreAvailable = loopEnd - _currentSmplPos - RESAMPLING_ORDER) >= 0)
396 {
397 srcData16 = &_dataSmpl16[_currentSmplPos];
398 srcData24 = &_dataSmpl24[_currentSmplPos];
399 return;
400 }
401
402 if (loopEnd >= RESAMPLING_ORDER + loopStart)
403 {
404 // Or take the end + the beginning of the loop
405 quint32 remainingSamples = loopEnd - _currentSmplPos;
406 memcpy(_srcData16, &_dataSmpl16[_currentSmplPos], remainingSamples * sizeof(qint16));
407 memcpy(&_srcData16[remainingSamples], &_dataSmpl16[loopStart], (RESAMPLING_ORDER - remainingSamples) * sizeof(qint16));
408 memcpy(_srcData24, &_dataSmpl24[_currentSmplPos], remainingSamples * sizeof(quint8));
409 memcpy(&_srcData24[remainingSamples], &_dataSmpl24[loopStart], (RESAMPLING_ORDER - remainingSamples) * sizeof(quint8));
410 }
411 else
412 {
413 // Or, if the loop is too short, use the loop several times
414 quint32 total = 0;
415 while (total < RESAMPLING_ORDER)
416 {
417 const quint32 chunk = qMin(loopEnd - _currentSmplPos, RESAMPLING_ORDER - total);
418 memcpy(&_srcData16[total], &_dataSmpl16[_currentSmplPos], chunk * sizeof(qint16));
419 memcpy(&_srcData24[total], &_dataSmpl24[_currentSmplPos], chunk * sizeof(quint8));
420 _currentSmplPos += chunk;
421 if (_currentSmplPos >= loopEnd)
422 _currentSmplPos = loopStart;
423 total += chunk;
424 }
425 }
426
427 srcData16 = _srcData16;
428 srcData24 = _srcData24;
429}
430
431void Voice::release(bool quick)
432{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected