Skip to content

Commit

Permalink
fix(SdlAFAudioRender): calculate the frame duration
Browse files Browse the repository at this point in the history
Signed-off-by: Your Name <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Sep 10, 2020
1 parent d5bbe3f commit 7c48f5e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions framework/render/audio/SdlAFAudioRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ namespace Cicada {
}
SDL_PauseAudioDevice(mDevID, 0); // start play audio
}
if (frame->getInfo().duration < 0 && frame->getInfo().audio.sample_rate > 0) {
frame->getInfo().duration = frame->getInfo().audio.nb_samples * 100000 / frame->getInfo().audio.sample_rate;
}
// if (frame->getInfo().duration < 0 && frame->getInfo().audio.sample_rate > 0) {
// frame->getInfo().duration = (uint64_t) frame->getInfo().audio.nb_samples * 1000000 / frame->getInfo().audio.sample_rate;
// }

// mAudioFrames.push(std::move(frame));
if (getQueDuration() > 500 * 1000) {
Expand All @@ -93,6 +93,7 @@ namespace Cicada {

if (mFiler != nullptr) {
int ret;
int origin_samples = frame->getInfo().audio.nb_samples;
unique_ptr<IAFFrame> filter_frame{};
ret = mFiler->pull(filter_frame, 0);

Expand All @@ -115,7 +116,7 @@ namespace Cicada {
memset(pcmBuffer, 0, pcmDataLength);
}
SDL_QueueAudio(mDevID, pcmBuffer, pcmDataLength);
mPlayedDuration += filter_frame->getInfo().duration;
mPlayedDuration += (uint64_t) origin_samples * 1000000 / filter_frame->getInfo().audio.sample_rate;
}

return mFiler->push(frame, 0);
Expand All @@ -140,8 +141,8 @@ namespace Cicada {
}
SDL_QueueAudio(mDevID, pcmBuffer, pcmDataLength);
assert(frame->getInfo().duration > 0);
mPlayedDuration += frame->getInfo().duration;
// AF_LOGD("queued duration is %llu\n", getQueDuration());
mPlayedDuration += (uint64_t) frame->getInfo().audio.nb_samples * 1000000 / frame->getInfo().audio.sample_rate;
// AF_LOGD("queued duration is %llu\n", getQueDuration());
frame = nullptr;
return 0;
}
Expand Down

0 comments on commit 7c48f5e

Please sign in to comment.