本文整理汇总了C++中AudioDecoder::getBytesPerFrame方法的典型用法代码示例。如果您正苦于以下问题:C++ AudioDecoder::getBytesPerFrame方法的具体用法?C++ AudioDecoder::getBytesPerFrame怎么用?C++ AudioDecoder::getBytesPerFrame使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AudioDecoder
的用法示例。
在下文中一共展示了AudioDecoder::getBytesPerFrame方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rotateBufferThread
void AudioPlayer::rotateBufferThread(int offsetFrame)
{
char* tmpBuffer = nullptr;
AudioDecoder* decoder = AudioDecoderManager::createDecoder(_audioCache->_fileFullPath.c_str());
do
{
BREAK_IF(decoder == nullptr || !decoder->open(_audioCache->_fileFullPath.c_str()));
uint32_t framesRead = 0;
const uint32_t framesToRead = _audioCache->_queBufferFrames;
const uint32_t bufferSize = framesToRead * decoder->getBytesPerFrame();
tmpBuffer = (char*)malloc(bufferSize);
memset(tmpBuffer, 0, bufferSize);
if (offsetFrame != 0) {
decoder->seek(offsetFrame);
}
ALint sourceState;
ALint bufferProcessed = 0;
bool needToExitThread = false;
while (!_isDestroyed) {
alGetSourcei(_alSource, AL_SOURCE_STATE, &sourceState);
if (sourceState == AL_PLAYING) {
alGetSourcei(_alSource, AL_BUFFERS_PROCESSED, &bufferProcessed);
while (bufferProcessed > 0) {
bufferProcessed--;
if (_timeDirty) {
_timeDirty = false;
offsetFrame = _currTime * decoder->getSampleRate();
decoder->seek(offsetFrame);
}
else {
_currTime += QUEUEBUFFER_TIME_STEP;
if (_currTime > _audioCache->_duration) {
if (_loop) {
_currTime = 0.0f;
} else {
_currTime = _audioCache->_duration;
}
}
}
framesRead = decoder->readFixedFrames(framesToRead, tmpBuffer);
if (framesRead == 0) {
if (_loop) {
decoder->seek(0);
framesRead = decoder->readFixedFrames(framesToRead, tmpBuffer);
} else {
needToExitThread = true;
break;
}
}
ALuint bid;
alSourceUnqueueBuffers(_alSource, 1, &bid);
alBufferData(bid, _audioCache->_format, tmpBuffer, framesRead * decoder->getBytesPerFrame(), decoder->getSampleRate());
alSourceQueueBuffers(_alSource, 1, &bid);
}
}
std::unique_lock<std::mutex> lk(_sleepMutex);
if (_isDestroyed || needToExitThread) {
break;
}
_sleepCondition.wait_for(lk,std::chrono::milliseconds(75));
}
} while(false);
ALOGV("Exit rotate buffer thread ...");
if (decoder != nullptr)
{
decoder->close();
}
AudioDecoderManager::destroyDecoder(decoder);
free(tmpBuffer);
_isRotateThreadExited = true;
ALOGV("%s exited.\n", __FUNCTION__);
}