[Cvs-annodex] commit (annodex): liboggplay/trunk/src/tests/glut-player.c

shans nobody at lists.annodex.net
Wed Jan 3 00:07:41 UTC 2007


Update of /var/local/lib/svn/annodex (new revision 2595)

Modified files:
   liboggplay/trunk/src/tests/glut-player.c

Log Message:
Synchronise to audio sample count rather than CPU clock



Modified: liboggplay/trunk/src/tests/glut-player.c
===================================================================
--- liboggplay/trunk/src/tests/glut-player.c	2007-01-02 04:39:01 UTC (rev 2594)
+++ liboggplay/trunk/src/tests/glut-player.c	2007-01-03 00:07:41 UTC (rev 2595)
@@ -149,10 +149,10 @@
  
 }
 
-static int snd_fd = -1;
+static int              snd_fd = -1;
+static unsigned int     rate;
 
 void init_audio() {
-  unsigned int    rate;
   unsigned int    channels      = 2;
   int             tmp;
   
@@ -189,9 +189,6 @@
 
 static int        window;
 
-static long       start_time_u = 0;
-static long       start_time_s = 0;
-
 void *display_frame(void * value) {
   int                     i;
   int                     j;
@@ -202,8 +199,9 @@
   OggPlayDataType         type;
   int                     num_tracks;
   OggPlayCallbackInfo  ** track_info;
-  struct timeval          tv;
   struct timespec         ts;
+  count_info              tsc;
+  static unsigned int     target      = 0;
 
   num_tracks = oggplay_get_num_tracks (player);
   ts.tv_sec = 0;
@@ -222,12 +220,6 @@
 #endif
     }
  
-    if (start_time_u == 0) {
-      gettimeofday(&tv, NULL);
-      start_time_u = tv.tv_usec;
-      start_time_s = tv.tv_sec;
-    }   
-  
     for (i = 0; i < num_tracks; i++) {
       type = oggplay_callback_info_get_type(track_info[i]);
       headers = oggplay_callback_info_get_headers(track_info[i]);
@@ -267,16 +259,13 @@
     oggplay_buffer_release_next (player);
     sem_post(&sem);
     
-    start_time_u += 40000;
-    if (start_time_u >= 1000000) {
-      start_time_u -= 1000000;
-      start_time_s += 1;
-    }
-  
-    gettimeofday(&tv, NULL);
-    long offset = ((start_time_s - tv.tv_sec) * 1000000) + 
-                  ((start_time_u - tv.tv_usec));
-  
+    ioctl(snd_fd, SNDCTL_DSP_GETOPTR, &tsc);
+    
+    target += 400;
+   
+    long long bytes = tsc.bytes;
+    long long offset = (target - (bytes * 10000 / rate / 4)) * 100;
+    
 #if DISPLAY_FRAMES
     ts.tv_nsec = offset * 1000;
     nanosleep(&ts, NULL);


-- 
shans



More information about the cvs-annodex mailing list