Fix AudioLocation::is_near function to handle a corner case where the two frames have different samples_per_frame, and sample_start is at the samples_per_frame limit.

This commit is contained in:
Nelson Ho
2017-01-07 17:34:11 -05:00
parent c9b74ec96d
commit c33e6fa2a8

View File

@@ -90,29 +90,13 @@ int AudioLocation::is_near(AudioLocation location, int samples_per_frame, int am
// This is too far away to be considered
return false;
int sample_diff = abs(location.sample_start - sample_start);
if (location.frame == frame && sample_diff >= 0 && sample_diff <= amount)
// Note that samples_per_frame can vary slightly frame to frame when the
// audio sampling rate is not an integer multiple of the video fps.
int diff = samples_per_frame * (location.frame - frame) + location.sample_start - sample_start;
if (abs(diff) <= amount)
// close
return true;
// new frame is after
if (location.frame > frame)
{
// remaining samples + new samples
sample_diff = (samples_per_frame - sample_start) + location.sample_start;
if (sample_diff >= 0 && sample_diff <= amount)
return true;
}
// new frame is before
if (location.frame < frame)
{
// remaining new samples + old samples
sample_diff = (samples_per_frame - location.sample_start) + sample_start;
if (sample_diff >= 0 && sample_diff <= amount)
return true;
}
// not close
return false;
}