MCPcopy Create free account
hub / github.com/axmolengine/axmol / rotateBufferThread

Method rotateBufferThread

core/audio/AudioPlayer.cpp:452–590  ·  view source on GitHub ↗

rotateBufferThread is used to rotate alBufferData for _alSource when playing big audio file

Source from the content-addressed store, hash-verified

450
451// rotateBufferThread is used to rotate alBufferData for _alSource when playing big audio file
452void AudioPlayer::rotateBufferThread(int offsetFrame)
453{
454 yasio::set_thread_name("axmol-audio");
455
456 char* tmpBuffer = nullptr;
457 auto& fullPath = _audioCache->_fileFullPath;
458 AudioDecoder* decoder = AudioDecoderManager::createDecoder(fullPath);
459 long long rotateSleepTime = static_cast<long long>(QUEUEBUFFER_TIME_STEP * 1000) / 2;
460 do
461 {
462 BREAK_IF(decoder == nullptr || !decoder->open(fullPath));
463
464 uint32_t framesRead = 0;
465 const uint32_t framesToRead = _audioCache->_queBufferFrames;
466 const uint32_t bufferSize = decoder->framesToBytes(framesToRead);
467#if AX_USE_ALSOFT
468 const auto sourceFormat = decoder->getSourceFormat();
469#endif
470 tmpBuffer = (char*)malloc(bufferSize);
471 memset(tmpBuffer, 0, bufferSize);
472
473 if (offsetFrame != 0)
474 {
475 decoder->seek(offsetFrame);
476 }
477
478 ALint sourceState;
479 ALint bufferProcessed = 0;
480 bool needToExitThread = false;
481
482 while (!_stopping)
483 {
484 alGetSourcei(_alSource, AL_SOURCE_STATE, &sourceState);
485 if (sourceState == AL_PLAYING)
486 {
487 alGetSourcei(_alSource, AL_BUFFERS_PROCESSED, &bufferProcessed);
488 while (bufferProcessed > 0)
489 {
490 bufferProcessed--;
491 if (_timeDirty)
492 {
493 _timeDirty = false;
494 offsetFrame = _currTime * decoder->getSampleRate() * decoder->getChannelCount();
495 decoder->seek(offsetFrame);
496 }
497 else
498 {
499 _currTime += QUEUEBUFFER_TIME_STEP;
500 if (_currTime > _audioCache->_duration)
501 {
502 if (_loop)
503 {
504 _currTime = 0.0f;
505 }
506 else
507 {
508 _currTime = _audioCache->_duration;
509 }

Callers

nothing calls this directly

Calls 12

set_thread_nameFunction · 0.85
alBufferDataFunction · 0.85
alGetErrorFunction · 0.85
getSourceFormatMethod · 0.80
getSampleRateMethod · 0.80
getChannelCountMethod · 0.80
readFixedFramesMethod · 0.80
getSamplesPerBlockMethod · 0.80
freeFunction · 0.50
openMethod · 0.45
framesToBytesMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected