Yes that was what I was thinking.
Ah found metadata/switch in the song file that tells the decoder to loop, so for the looped songs if we somehow unset that loop switch we can possibly get the duration for a single play?
The ReplayGBSPlay::SetupMetadata shows that it
stores m_loops and
sizeof(LoopInfo)) and the
kDefaultSongDuration (for no loop play) in the metadata of the gbs song file as well as the number of songs.
For the looped play it uses this to set the duration length and the loops:
len = (len * 1000) / 1024;
m_loops = settings->loops = { 0, uint32_t(len) };
void ReplayGBSPlay::SetupMetadata(CommandBuffer metadata)
{
auto numSongs = gbs_get_status(m_gbs)->songs;
auto settings = metadata.Find<Settings>();
if (settings && settings->numSongs == numSongs)
{
for (uint32_t i = 0; i < numSongs; i++)
m_loops[i] = settings->loops[i].GetFixed();
m_currentDuration = (uint64_t(GetDurationMs()) * kSampleRate) / 1000;
}
else
{
auto value = settings ? settings->value : 0;
settings = metadata.Create<Settings>(sizeof(Settings) + numSongs * sizeof(LoopInfo));
settings->value = value;
settings->numSongs = numSongs;
for (uint16_t i = 0; i < numSongs; i++)
{
SetSubsong(i);
uint64_t len = gbs_get_status(m_gbs)->subsong_len;
if (len == 0)
len = kDefaultSongDuration;
else
len = (len * 1000) / 1024;
m_loops[i] = settings->loops[i] = { 0, uint32_t(len) };
}
SetSubsong(0);
}
}
In ReplayGBSPlay.cpp I thought of
m_loops in:
numSamples = currentPosition < currentDuration ? uint32_t(currentDuration - currentPosition) : 0;
if (numSamples == 0)
{
m_currentPosition = 0;
m_currentDuration = (uint64_t(
m_loops[m_subsongIndex].length) * kSampleRate) / 1000;
With m_loops
set by a fixed loops array:
if (settings)
{
for (uint16_t i = 0; i < settings->numSongs; i++)
m_loops[i] = settings->loops[i].GetFixed();
m_currentDuration = (uint64_t(GetDurationMs()) * kSampleRate) / 1000;
}
Also in ReplayGBSPlay::ResetPlayback there is uint64_t(GetDurationMs()) in here so could GetDurationMs be used for the progress bar?
void ReplayGBSPlay::ResetPlayback()
{
gbs_init(m_gbs, m_subsongIndex);
m_surround.Reset();
m_currentPosition = 0;
m_currentDuration = (uint64_t(
GetDurationMs()) * kSampleRate) / 1000;
m_bufPos = kMaxSamples;
}
Lastly the 15 seconds to start could it be possibly due to the wait time for the creation of Data Buffer m_bufDataCopy in auto buffer?
auto buf = m_bufDataCopy + currrentPos * 2