[ardour-dev] smpte calc patch

nick mainsbridge beatroot at optushome.com.au
Sat Feb 21 15:30:23 PST 2004


this patch changes the way various smpte calculations are performed.
i don't have the means to test MTC here, but i've confirmed as best i
can that the numbers are correct (for a change).
subframes are also now calculated (instead of being zeroed) in
smpte_time_subframes.
anyone with MTC want to confirm that it works?
-------------- next part --------------
--- ../../../../Desktop/ardour/libs/ardour/session_time.cc	Sat Oct 11 04:52:12 2003
+++ ../libs/ardour/session_time.cc	Sun Feb 22 09:45:24 2004
@@ -63,34 +63,34 @@
 		return;
 	}
 
-	double offset_sample;
-	double secs;
-	double computed_secs;
-	double total_secs;
-	long hrs;
-	long mins;
-	
-	if (when < _smpte_offset) {
-		offset_sample = ((double) _smpte_offset - when);
-		smpte.negative = true;
-	} else {
-		offset_sample = (double) when - _smpte_offset;
-		smpte.negative = false;
-	}
-
-	total_secs = offset_sample / frame_rate();
-	secs = total_secs;
-	hrs =  (long) floor (secs / 3600.0);
-	secs -= (hrs * 3600.0);
-	mins = (long) floor (secs / 60.0);
-	secs -= (mins * 60.0);
-
-	computed_secs = (hrs * 3600.0) + (mins * 60.0) + floor (secs);
-
-	smpte.frames = (long) ((total_secs - computed_secs) * smpte_frames_per_second);
-	smpte.seconds = (long) secs;
-	smpte.minutes = mins;
-	smpte.hours = hrs;
+	jack_nframes_t offset_sample;
+	jack_nframes_t left;
+        long hrs;
+        long mins;
+        long secs;
+        long frames;
+                                                                                                                   
+        if (when < _smpte_offset) {
+                offset_sample = (_smpte_offset - when);
+                smpte.negative = true;
+        } else {
+                offset_sample =  when - _smpte_offset;
+                smpte.negative = false;
+        }
+
+	left = offset_sample;
+        hrs = (int) floor (left / (frame_rate() * 60.0f * 60.0f));
+        left -= (jack_nframes_t) floor (hrs * frame_rate() * 60.0f * 60.0f);
+        mins = (int) floor (left / (frame_rate() * 60.0f));
+        left -= (jack_nframes_t) floor (mins * frame_rate() * 60.0f);
+        secs = (int) floor (left / frame_rate() * 1.0f);
+        left -= (jack_nframes_t) floor (secs * frame_rate() * 1.0f);
+        frames = (int) floor (left / (frame_rate() / smpte_frames_per_second));
+                                                                                                                   
+        smpte.frames = frames;
+        smpte.seconds = secs;
+        smpte.minutes = mins;
+        smpte.hours = hrs;
 
 	last_smpte_when = when;
 	last_smpte = smpte;
@@ -101,52 +101,81 @@
 Session::smpte_time_subframes (jack_nframes_t when, SMPTE_Time& smpte)
 {
 	if (last_smpte_valid && when == last_smpte_when) {
-		smpte = last_smpte;
-		return;
-	}
-
-	double offset_sample;
-	double secs;
-	double computed_secs;
-	double total_secs;
-	long hrs;
-	long mins;
-	
-	if (when < _smpte_offset) {
-		offset_sample = ((double) _smpte_offset - when);
-		smpte.negative = true;
-	} else {
-		offset_sample = (double) when - _smpte_offset;
-		smpte.negative = false;
-	}
-
-	total_secs = offset_sample / frame_rate();
-	secs = total_secs;
-	hrs =  (long) floor (secs / 3600.0);
-	secs -= (hrs * 3600.0);
-	mins = (long) floor (secs / 60.0);
-	secs -= (mins * 60.0);
-
-	computed_secs = (hrs * 3600.0) + (mins * 60.0) + floor (secs);
-
-	smpte.frames = (long) ((total_secs - computed_secs) * smpte_frames_per_second);
-
-	/* XXX not sure how to compute this yet */
+                smpte = last_smpte;
+                return;
+        }
+                                                                                                                   
+        jack_nframes_t offset_sample;
+        jack_nframes_t left;
+        long hrs;
+        long mins;
+        long secs;
+        long frames;
+	long subframes;
+                                                                                                                   
+        if (when < _smpte_offset) {
+                offset_sample = (_smpte_offset - when);
+                smpte.negative = true;
+        } else {
+                offset_sample =  when - _smpte_offset;
+                smpte.negative = false;
+        }
+                                                                                                                   
+        left = offset_sample;
+        hrs = (int) floor (left / (frame_rate() * 60.0f * 60.0f));
+        left -= (jack_nframes_t) floor (hrs * frame_rate() * 60.0f * 60.0f);
+        mins = (int) floor (left / (frame_rate() * 60.0f));
+        left -= (jack_nframes_t) floor (mins * frame_rate() * 60.0f);
+        secs = (int) floor (left / frame_rate() * 1.0f);
+        left -= (jack_nframes_t) floor (secs * frame_rate() * 1.0f);
+        frames = (int) floor (left / (frame_rate() / smpte_frames_per_second));
+	left -= (jack_nframes_t) floor (frames * frame_rate() / smpte_frames_per_second);
+	/* eighty bits in a SMPTE frame */
+	subframes = (int) floor (left / (frame_rate() / (smpte_frames_per_second * 80)));
 	
-	smpte.subframes = 0;
-
-	smpte.seconds = (long) secs;
-	smpte.minutes = mins;
-	smpte.hours = hrs;
+        smpte.subframes = subframes;
+        smpte.frames = frames;
+        smpte.seconds = secs;
+        smpte.minutes = mins;
+        smpte.hours = hrs;
+                                                                                                                   
+        last_smpte_when = when;
+        last_smpte = smpte;
+        last_smpte_valid = true;
 
-	last_smpte_when = when;
-	last_smpte = smpte;
-	last_smpte_valid = true;
 }
 
 void
 Session::smpte_duration (jack_nframes_t when, SMPTE_Time& smpte) const
 {
+        jack_nframes_t left;
+        long hrs;
+        long mins;
+        long secs;
+        long frames;
+        long subframes;
+
+	left = when;
+        hrs = (int) floor (left / (frame_rate() * 60.0f * 60.0f));
+        left -= (jack_nframes_t) floor (hrs * frame_rate() * 60.0f * 60.0f);
+        mins = (int) floor (left / (frame_rate() * 60.0f));
+        left -= (jack_nframes_t) floor (mins * frame_rate() * 60.0f);
+        secs = (int) floor (left / frame_rate() * 1.0f);
+        left -= (jack_nframes_t) floor (secs * frame_rate() * 1.0f);
+        frames = (int) floor (left / (frame_rate() / smpte_frames_per_second));
+        left -= (jack_nframes_t) floor (frames * frame_rate() / smpte_frames_per_second);
+        /* eighty bits in a SMPTE frame */
+        subframes = (int) floor (left / (frame_rate() / (smpte_frames_per_second * 80)));
+                                                                                                                   
+        smpte.subframes = subframes;
+        smpte.frames = frames;
+        smpte.seconds = secs;
+        smpte.minutes = mins;
+        smpte.hours = hrs;
+
+/*  i've left the original here.. i can't really test the new one.
+it was only accurate to frames. maybe it was intentional ..nm
+
 	double sample;
 	double secs;
 	double computed_secs;
@@ -169,6 +198,8 @@
 	smpte.seconds = (long) secs;
 	smpte.minutes = mins;
 	smpte.hours = hrs;
+
+*/
 }
 
 void


More information about the Ardour-Dev mailing list