Skip to content

Commit

Permalink
faster code for fixing truncated samples
Browse files Browse the repository at this point in the history
  • Loading branch information
dnewman-gpsw committed Apr 24, 2019
1 parent 44c8d8b commit f156c4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions GPMF_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2614,18 +2614,12 @@ uint32_t GPMFWriteGetPayloadAndSession( size_t ws_handle, uint32_t channel, uint

if (dm->sampleCount[ts_pos] > 1) // multiple sample stored with one timestamp, interpolate
{
uint32_t additionSmps = 0, sampleTSdelta = (dm->deltaTimeStamp[ts_pos]<<8) / dm->sampleCount[ts_pos];
uint64_t refineTS = next_first_ts << 8; // improved precision.
uint32_t additionSmps;

while (((refineTS + sampleTSdelta)>>8) < latestTimeStamp)
{
refineTS += sampleTSdelta;
additionSmps++;
}
dm->deltaTimeStamp[ts_pos] -= (refineTS >> 8) - next_first_ts;
additionSmps = dm->sampleCount[ts_pos] * (latestTimeStamp - next_first_ts) / dm->deltaTimeStamp[ts_pos];
dm->deltaTimeStamp[ts_pos] -= additionSmps * dm->deltaTimeStamp[ts_pos] / dm->sampleCount[ts_pos];
dm->sampleCount[ts_pos] -= additionSmps;

next_first_ts = refineTS >> 8;
smps += additionSmps;
}

Expand Down
2 changes: 1 addition & 1 deletion demo/GPMF_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ int main(int argc, char *argv[])
}

if(faketime == 0)
GPMFWriteGetPayloadWindow(gpmfhandle, GPMF_CHANNEL_TIMED, (uint32_t *)buffer, sizeof(buffer), &payload, &payload_size, 250); // Flush partial second
GPMFWriteGetPayloadWindow(gpmfhandle, GPMF_CHANNEL_TIMED, (uint32_t *)buffer, sizeof(buffer), &payload, &payload_size, 299); // Flush partial second

nowtick = payloadtick + (tick - payloadtick) * 8 / 10; // test by reading out only the last half samples
nowtick = tick+1; // test by reading out only the last half samples
Expand Down

0 comments on commit f156c4b

Please sign in to comment.