Last active
December 20, 2015 15:51
-
-
Save yorung/fee4c48f6856ee9c7035 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Voice::Play(bool loop) | |
| { | |
| if (!IsReady()) { | |
| return; | |
| } | |
| auto playback = [](SLAndroidSimpleBufferQueueItf q, void* context_) { | |
| double now = GetTime(); | |
| if (now - systemMisc.GetLastUpdateTime() >= 0.5) { | |
| return; | |
| } | |
| WaveContext* context = (WaveContext*)context_; | |
| int totalSize; | |
| const void* buf = RiffFindChunk(context->fileImg, "data", &totalSize); | |
| int enqueued = context->enqueuedSize; | |
| if (enqueued >= totalSize) { | |
| if (!context->loop) { | |
| return; | |
| } | |
| enqueued = 0; | |
| } | |
| int toEnqueue = std::min(totalSize - enqueued, 32768); | |
| enqueued += toEnqueue; | |
| context->enqueuedSize = enqueued; | |
| SLCall(q, Enqueue, (char*)buf + enqueued - toEnqueue, toEnqueue); | |
| }; | |
| SLCall(context->playerPlay, SetPlayState, SL_PLAYSTATE_STOPPED); | |
| SLCall(context->playerBufferQueue, RegisterCallback, playback, context); | |
| context->enqueuedSize = 0; | |
| context->loop = loop; | |
| SLCall(context->playerPlay, SetPlayState, SL_PLAYSTATE_PLAYING); | |
| playback(context->playerBufferQueue, context); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment