* Fold entire callback into a single if-else block.
* Remove 'end' variable and just return 0 if we have more to play. Originally committed to SVN as r2806.
This commit is contained in:
parent
eb65009f66
commit
50ce42d2e9
1 changed files with 17 additions and 15 deletions
|
@ -92,18 +92,6 @@ int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, uns
|
||||||
// Get provider
|
// Get provider
|
||||||
PortAudioPlayer *player = (PortAudioPlayer *) userData;
|
PortAudioPlayer *player = (PortAudioPlayer *) userData;
|
||||||
AudioProvider *provider = player->GetProvider();
|
AudioProvider *provider = player->GetProvider();
|
||||||
int end = 0;
|
|
||||||
|
|
||||||
// Calculate how much left
|
|
||||||
int64_t lenAvailable = (player->endPos - player->playPos) > 0 ? framesPerBuffer : 0;
|
|
||||||
|
|
||||||
// Play something
|
|
||||||
if (lenAvailable > 0) {
|
|
||||||
provider->GetAudioWithVolume(outputBuffer, player->playPos, lenAvailable, player->GetVolume());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set play position
|
|
||||||
player->playPos += framesPerBuffer;
|
|
||||||
|
|
||||||
#ifdef PORTAUDIO2_DEBUG
|
#ifdef PORTAUDIO2_DEBUG
|
||||||
printf("paCallBack: playPos: %lld startPos: %lld paStart: %f Pa_GetStreamTime: %f AdcTime: %f DacTime: %f CPU: %f\n",
|
printf("paCallBack: playPos: %lld startPos: %lld paStart: %f Pa_GetStreamTime: %f AdcTime: %f DacTime: %f CPU: %f\n",
|
||||||
|
@ -111,12 +99,26 @@ int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, uns
|
||||||
timeInfo->inputBufferAdcTime, timeInfo->outputBufferDacTime, Pa_GetStreamCpuLoad(player->stream));
|
timeInfo->inputBufferAdcTime, timeInfo->outputBufferDacTime, Pa_GetStreamCpuLoad(player->stream));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set the end position to be less then the current play position.
|
// Calculate how much left
|
||||||
if (lenAvailable <= 0) {
|
int64_t lenAvailable = (player->endPos - player->playPos) > 0 ? framesPerBuffer : 0;
|
||||||
|
|
||||||
|
// Play something
|
||||||
|
if (lenAvailable > 0) {
|
||||||
|
provider->GetAudioWithVolume(outputBuffer, player->playPos, lenAvailable, player->GetVolume());
|
||||||
|
|
||||||
|
// Set play position
|
||||||
|
player->playPos += framesPerBuffer;
|
||||||
|
|
||||||
|
// Continue as normal
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Set the end position to be less then the current play position.
|
||||||
player->endPos = player->endPos - (framesPerBuffer + 8192);
|
player->endPos = player->endPos - (framesPerBuffer + 8192);
|
||||||
|
|
||||||
|
// Abort stream and stop the callback.
|
||||||
return paAbort;
|
return paAbort;
|
||||||
}
|
}
|
||||||
return end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue