X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Ftimecode%2Fsrc%2Ftime.cc;h=494e6e114558d3e04083d54fac56f2bbdb53189c;hb=22b07e0233a29d9633ffa825a79503befaf2e16e;hp=cf2c4a1b3e3a894c9948436a53531c8a2aef5377;hpb=37b1f5017e904005fae6b815b1519b3fa595d8d3;p=ardour.git diff --git a/libs/timecode/src/time.cc b/libs/timecode/src/time.cc index cf2c4a1b3e..494e6e1145 100644 --- a/libs/timecode/src/time.cc +++ b/libs/timecode/src/time.cc @@ -1,16 +1,16 @@ /* Copyright (C) 2006-2010 Paul Davis - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. @@ -46,7 +46,7 @@ increment (Time& timecode, uint32_t subframes_per_frame) timecode.negative = false; return SECONDS; } - + timecode.negative = false; wrap = decrement (timecode, subframes_per_frame); if (!Timecode_IS_ZERO (timecode)) { @@ -94,7 +94,7 @@ increment (Time& timecode, uint32_t subframes_per_frame) } break; } - + if (wrap == SECONDS) { if (timecode.seconds == 59) { timecode.seconds = 0; @@ -112,7 +112,7 @@ increment (Time& timecode, uint32_t subframes_per_frame) } else { timecode.frames++; } - + return wrap; } @@ -124,7 +124,7 @@ Wrap decrement (Time& timecode, uint32_t subframes_per_frame) { Wrap wrap = NONE; - + if (timecode.negative || Timecode_IS_ZERO (timecode)) { timecode.negative = false; wrap = increment (timecode, subframes_per_frame); @@ -136,7 +136,7 @@ decrement (Time& timecode, uint32_t subframes_per_frame) timecode.negative = true; return SECONDS; } - + switch ((int)ceil (timecode.rate)) { case 24: if (timecode.frames == 0) { @@ -161,7 +161,7 @@ decrement (Time& timecode, uint32_t subframes_per_frame) timecode.frames = 29; wrap = SECONDS; } - + } else { if (timecode.frames == 0) { timecode.frames = 29; @@ -176,7 +176,7 @@ decrement (Time& timecode, uint32_t subframes_per_frame) } break; } - + if (wrap == SECONDS) { if (timecode.seconds == 0) { timecode.seconds = 59; @@ -195,11 +195,11 @@ decrement (Time& timecode, uint32_t subframes_per_frame) } else { timecode.frames--; } - + if (Timecode_IS_ZERO (timecode)) { timecode.negative = false; } - + return wrap; } @@ -220,7 +220,7 @@ Wrap increment_subframes (Time& timecode, uint32_t subframes_per_frame) { Wrap wrap = NONE; - + if (timecode.negative) { timecode.negative = false; wrap = decrement_subframes (timecode, subframes_per_frame); @@ -229,7 +229,7 @@ increment_subframes (Time& timecode, uint32_t subframes_per_frame) } return wrap; } - + timecode.subframes++; if (timecode.subframes >= subframes_per_frame) { timecode.subframes = 0; @@ -245,14 +245,14 @@ Wrap decrement_subframes (Time& timecode, uint32_t subframes_per_frame) { Wrap wrap = NONE; - + if (timecode.negative) { timecode.negative = false; wrap = increment_subframes (timecode, subframes_per_frame); timecode.negative = true; return wrap; } - + if (timecode.subframes <= 0) { timecode.subframes = 0; if (Timecode_IS_ZERO (timecode)) { @@ -279,10 +279,10 @@ Wrap increment_seconds (Time& timecode, uint32_t subframes_per_frame) { Wrap wrap = NONE; - + // Clear subframes frames_floor (timecode); - + if (timecode.negative) { // Wrap second if on second boundary wrap = increment (timecode, subframes_per_frame); @@ -307,11 +307,11 @@ increment_seconds (Time& timecode, uint32_t subframes_per_frame) timecode.frames = 59; break; } - + // Increment by one frame wrap = increment (timecode, subframes_per_frame); } - + return wrap; } @@ -323,7 +323,7 @@ seconds_floor (Time& timecode) { // Clear subframes frames_floor (timecode); - + // Go to lowest possible frame in this second switch ((int)ceil (timecode.rate)) { case 24: @@ -341,7 +341,7 @@ seconds_floor (Time& timecode) } break; } - + if (Timecode_IS_ZERO (timecode)) { timecode.negative = false; } @@ -353,10 +353,10 @@ Wrap increment_minutes (Time& timecode, uint32_t subframes_per_frame) { Wrap wrap = NONE; - + // Clear subframes frames_floor (timecode); - + if (timecode.negative) { // Wrap if on minute boundary wrap = increment_seconds (timecode, subframes_per_frame); @@ -368,7 +368,7 @@ increment_minutes (Time& timecode, uint32_t subframes_per_frame) // Wrap minute by incrementing second wrap = increment_seconds (timecode, subframes_per_frame); } - + return wrap; } @@ -393,10 +393,10 @@ Wrap increment_hours (Time& timecode, uint32_t subframes_per_frame) { Wrap wrap = NONE; - + // Clear subframes frames_floor (timecode); - + if (timecode.negative) { // Wrap if on hour boundary wrap = increment_minutes (timecode, subframes_per_frame); @@ -406,7 +406,7 @@ increment_hours (Time& timecode, uint32_t subframes_per_frame) timecode.minutes = 59; wrap = increment_minutes (timecode, subframes_per_frame); } - + return wrap; } @@ -419,7 +419,7 @@ hours_floor(Time& timecode) timecode.seconds = 0; timecode.frames = 0; timecode.subframes = 0; - + if (Timecode_IS_ZERO (timecode)) { timecode.negative = false; } @@ -716,11 +716,18 @@ timecode_to_sample( frame_rate() in the non-integer Timecode rate case. */ - sample = (int64_t)lrint((((timecode.hours * 60 * 60) + (timecode.minutes * 60) + timecode.seconds) * (lrint(timecode.rate) * frames_per_timecode_frame)) + (timecode.frames * frames_per_timecode_frame)); + sample = (int64_t) rint( + ( + ((timecode.hours * 60 * 60) + (timecode.minutes * 60) + timecode.seconds) + * + (rint(timecode.rate) * frames_per_timecode_frame) + ) + + (timecode.frames * frames_per_timecode_frame) + ); } if (use_subframes) { - sample += (int64_t) lrint(((double)timecode.subframes * frames_per_timecode_frame) / (double)subframes_per_frame); + sample += (int64_t) rint(((double)timecode.subframes * frames_per_timecode_frame) / (double)subframes_per_frame); } if (use_offset) { @@ -763,7 +770,7 @@ sample_to_timecode ( if (!use_offset) { timecode.negative = (sample < 0); - offset_sample = llabs(sample); + offset_sample = ::llabs(sample); } else { if (offset_is_negative) { offset_sample = sample + offset_samples; @@ -786,7 +793,7 @@ sample_to_timecode ( const int64_t D = frameNumber / 17982; const int64_t M = frameNumber % 17982; - timecode.subframes = lrint(subframes_per_frame + timecode.subframes = rint(subframes_per_frame * ((double)offset_sample * timecode_frames_per_second / sample_frame_rate - (double)frameNumber)); if (timecode.subframes == subframes_per_frame) { @@ -806,7 +813,7 @@ sample_to_timecode ( double timecode_frames_fraction; int64_t timecode_frames_left; const double frames_per_timecode_frame = sample_frame_rate / timecode_frames_per_second; - const int64_t frames_per_hour = (int64_t)(3600 * lrint(timecode_frames_per_second) * frames_per_timecode_frame); + const int64_t frames_per_hour = (int64_t)(3600. * rint(timecode_frames_per_second) * frames_per_timecode_frame); timecode.hours = offset_sample / frames_per_hour; @@ -815,7 +822,7 @@ sample_to_timecode ( timecode_frames_left_exact = (double)(offset_sample % frames_per_hour) / frames_per_timecode_frame; timecode_frames_fraction = timecode_frames_left_exact - floor( timecode_frames_left_exact ); - timecode.subframes = (int32_t) lrint(timecode_frames_fraction * subframes_per_frame); + timecode.subframes = (int32_t) rint(timecode_frames_fraction * subframes_per_frame); timecode_frames_left = (int64_t) floor (timecode_frames_left_exact); if (use_subframes && timecode.subframes == subframes_per_frame) { @@ -839,8 +846,8 @@ sample_to_timecode ( } // namespace Timecode -std::ostream& -operator<<(std::ostream& ostr, const Timecode::Time& t) +std::ostream& +operator<<(std::ostream& ostr, const Timecode::Time& t) { return t.print (ostr); }