Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Sep 19, 2024
1 parent 0ed41ca commit b839c47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lib/tlTimeline/PlayerAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ namespace tl
// playback is reset.
if (reset)
{
p->audioThread.frame = 0;
p->audioThread.inputFrame = 0;
p->audioThread.outputFrame = 0;
if (p->audioThread.resample)
{
p->audioThread.resample->flush();
Expand All @@ -332,11 +333,11 @@ namespace tl
int64_t t = (start - p->timeRange.start_time()).rescaled_to(inputInfo.sampleRate).value();
if (Playback::Forward == playback)
{
t += p->audioThread.frame;
t += p->audioThread.inputFrame;
}
else
{
t -= p->audioThread.frame;
t -= p->audioThread.inputFrame;
}
int64_t seconds = t / inputInfo.sampleRate;
int64_t offset = t - (seconds * inputInfo.sampleRate);
Expand Down Expand Up @@ -439,10 +440,13 @@ namespace tl
}

// Update the frame counters.
p->audioThread.frame += size;
p->audioThread.inputFrame += size;
p->audioThread.outputFrame += nFrames;
{
std::unique_lock<std::mutex> lock(p->audioMutex.mutex);
p->audioMutex.frame += otio::RationalTime(nFrames, outputInfo.sampleRate).
p->audioMutex.frame = otio::RationalTime(
p->audioThread.outputFrame,
outputInfo.sampleRate).
rescaled_to(inputInfo.sampleRate).value();
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/tlTimeline/PlayerPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ namespace tl
struct AudioThread
{
audio::Info info;
int64_t frame = 0;
int64_t inputFrame = 0;
int64_t outputFrame = 0;
std::shared_ptr<audio::AudioResample> resample;
std::list<std::shared_ptr<audio::Audio> > buffer;
std::shared_ptr<audio::Audio> silence;
Expand Down

0 comments on commit b839c47

Please sign in to comment.