more 64/32bit fun

This commit is contained in:
Fischlurch 2011-05-13 04:04:02 +02:00
parent 10215948a5
commit 3139fb7f1e
3 changed files with 43 additions and 17 deletions

View file

@ -81,6 +81,14 @@ lumiera_rational_to_time (FSecs const& fractionalSeconds)
return rational_cast<gavl_time_t> (GAVL_TIME_SCALE * fractionalSeconds);
}
gavl_time_t
lumiera_framecount_to_time (uint64_t frameCount, FrameRate const& fps)
{
// convert to 64bit
boost::rational<uint64_t> framerate (fps.numerator(), fps.denominator());
return rational_cast<gavl_time_t> (GAVL_TIME_SCALE * frameCount / framerate);
}
gavl_time_t
lumiera_frame_duration (FrameRate const& fps)
@ -122,7 +130,7 @@ lumiera_quantise_time (gavl_time_t time, gavl_time_t origin, gavl_time_t grid)
}
gavl_time_t
lumiera_time_of_gridpoint (long nr, gavl_time_t origin, gavl_time_t grid)
lumiera_time_of_gridpoint (int64_t nr, gavl_time_t origin, gavl_time_t grid)
{
gavl_time_t offset = nr * grid;
return origin + offset;
@ -154,14 +162,14 @@ lumiera_build_time_fps (float fps, uint frames, uint secs, uint mins, uint hours
gavl_time_t
lumiera_build_time_ntsc_drop (uint frames, uint secs, uint mins, uint hours)
{
int total_mins = 60 * hours + mins;
int total_frames = 108000 * hours
+ 1800 * mins
+ 30 * secs
+ frames
- 2 * (total_mins - total_mins / 10);
uint64_t total_mins = 60 * hours + mins;
uint64_t total_frames = 108000 * hours
+ 1800 * mins
+ 30 * secs
+ frames
- 2 * (total_mins - total_mins / 10);
return (total_frames / 29.97f) * 1000 * GAVL_TIME_SCALE_MS;
return lumiera_framecount_to_time (total_frames, FrameRate::NTSC);
}
int

View file

@ -69,6 +69,16 @@ gavl_time_t
lumiera_rational_to_time (lib::time::FSecs const& fractionalSeconds);
/**
* Converts a frame count into Lumiera's internal time scale.
* based on a framerate given as rational number (e.g. NTSC)
* @note handles only positive frame counts and assumes the
* origin to be at zero.
*/
gavl_time_t
lumiera_framecount_to_time (uint64_t frameCount, lib::time::FrameRate const& fps);
/**
* Calculates the duration of one frame in Lumiera time units.
* @param framerate underlying framerate as rational number
@ -125,7 +135,7 @@ lumiera_quantise_time (gavl_time_t time, gavl_time_t origin, gavl_time_t grid);
* @return time point (frame start) on the Lumiera internal time scale
*/
gavl_time_t
lumiera_time_of_gridpoint (long nr, gavl_time_t origin, gavl_time_t grid);
lumiera_time_of_gridpoint (int64_t nr, gavl_time_t origin, gavl_time_t grid);
/**
* Builds a time value by summing up the given components.
@ -140,6 +150,11 @@ lumiera_build_time (long millis, uint secs, uint mins, uint hours);
/**
* Builds a time value by summing up the given components.
* @todo replace float framerates by lib::time::FrameRate
* @deprecated this function doesn't fit in the general time handling concept.
* SMPTE is a timecode format, and should be distinguished from a
* raw time value. For any timecode format, we always require an explicit
* 'time grid' (coordinate system), which also defines a zero point.
* Usually, this time grid is managed and provided by the session
*/
gavl_time_t
lumiera_build_time_fps (float fps, uint frames, uint secs, uint mins, uint hours);
@ -183,6 +198,9 @@ lumiera_time_frames (gavl_time_t time, float fps);
/**
* Extract the frame count for the given time, using the given fps.
* @todo use the rational lib::time::FrameRate instead of a float
* @deprecated should be moved down into the implementation;
* this function doesn't fit into the general time handling,
* because it doesn't link to a time grid (coordinate system)
*/
int
lumiera_time_frame_count (gavl_time_t time, float fps);

View file

@ -79,11 +79,11 @@ namespace time {
TimeValue
Smpte::evaluate (SmpteTC const& tc, QuantR quantiser)
{
long frameRate = tc.getFps();
long gridPoint = tc.frames
+ tc.secs * frameRate
+ tc.mins * frameRate * 60
+ tc.hours * frameRate * 60 * 60;
uint frameRate = tc.getFps();
int64_t gridPoint(tc.frames);
gridPoint += int64_t(tc.secs) * frameRate;
gridPoint += int64_t(tc.mins) * frameRate * 60;
gridPoint += int64_t(tc.hours) * frameRate * 60 * 60;
return quantiser.timeOf (tc.sgn * gridPoint);
}
@ -103,9 +103,9 @@ namespace time {
uint
Smpte::getFramerate (QuantR quantiser_, TimeValue const& rawTime)
{
long refCnt = quantiser_.gridPoint(rawTime);
long newCnt = quantiser_.gridPoint(Time(0.5,1) + rawTime);
long effectiveFrames = newCnt - refCnt;
int64_t refCnt = quantiser_.gridPoint(rawTime);
int64_t newCnt = quantiser_.gridPoint(Time(0,1) + rawTime);
int64_t effectiveFrames = newCnt - refCnt;
ENSURE (1000 > effectiveFrames);
ENSURE (0 < effectiveFrames);
return uint(effectiveFrames);