File grip-flac-progress.patch of Package grip

- fix progress display when encoding using flac

The first hunk is actally not related to flac encoding but to ripping
in general:

- Allow for 1.5 seconds for CD-ROM drive spinup until speed and
  progress metering starts, avoids starting with very low speed
  indication.

The remaining 3 hunks apply to encoding to a .flac file,

Using a value which is too low causes the progress bar to
reach 100% a while before encoding is actually finished.
Tests with many CDs show that a value of 980 kbits is safe.

The changes are specifically only for progress display,
evaluation of %b (bitrate) is not changed.

- fix for precision problems at start of ripping:

  The fix is to do this:

-    elapsed = (gfloat)now - (gfloat)ginfo->rip_started;
+    elapsed =         now -         ginfo->rip_started;

  now and rip_started are two time_t values (seconds since epoch),
  so they are signed long int's on x86_64, so it's not a good idea
================================================================================
--- grip-3.2.0/src/rip.c
+++ grip-3.2.0/src/rip.c
@@ -805,7 +805,7 @@
     gtk_progress_bar_update(GTK_PROGRESS_BAR(uinfo->ripprogbar),percent);
 
     now = time(NULL);
-    elapsed = (gfloat)now - (gfloat)ginfo->rip_started;
+    elapsed =         now -         ginfo->rip_started;
 
     /* 1x is 44100*2*2 = 176400 bytes/sec */
     if(elapsed < 0.1f) /* 1/10 sec. */
@@ -935,10 +935,16 @@
 			      percent);
        
       now = time(NULL);
-      elapsed = (gfloat)now - (gfloat)ginfo->mp3_started[mycpu];
+      elapsed =         now -         ginfo->mp3_started[mycpu];
 
       if(elapsed < 0.1f) /* 1/10 sec. */
 	speed=0.0f;
+#define FLAC_BITRATE 980
+      // Quick fix until we can add per-encoder bitrates:
+      else if (!strcmp(ginfo->mp3extension, "flac")
+	        && ginfo->kbits_per_sec < FLAC_BITRATE)
+	speed=(gfloat)mystat.st_size/
+	  (FLAC_BITRATE * 128.0f * elapsed);
       else
 	speed=(gfloat)mystat.st_size/
 	  ((gfloat)ginfo->kbits_per_sec * 128.0f * elapsed);
@@ -1100,8 +1106,6 @@
 {
   static char res[PATH_MAX];
   EncodeTrack *enc_track;
-  gchar *conv_str,*st;
-  gsize rb,wb;
 
   enc_track=(EncodeTrack *)data;
 
@@ -1719,6 +1723,13 @@
   
   unlink(ginfo->mp3file[cpu]);
   
+  // Quick fix until we can add per-encoder bitrates
+  if (!strcmp(ginfo->mp3extension, "flac")
+	 && ginfo->kbits_per_sec < FLAC_BITRATE)
+    ginfo->mp3size[cpu]=
+      (int)((gfloat)((enc_track->end_frame-enc_track->start_frame)+1)*
+	    (gfloat)(FLAC_BITRATE*1024)/600.0);
+  else
   ginfo->mp3size[cpu]=
     (int)((gfloat)((enc_track->end_frame-enc_track->start_frame)+1)*
 	  (gfloat)(ginfo->kbits_per_sec*1024)/600.0);
@@ -1819,6 +1830,13 @@
 static size_t CalculateEncSize(GripInfo *ginfo, int track)
 {
   double tmp_encsize=0.0;
+  // Quick fix until we can add per-encoder bitrates:
+  if (!strcmp(ginfo->mp3extension, "flac")
+	 && ginfo->kbits_per_sec < FLAC_BITRATE)
+    tmp_encsize=(double)((ginfo->disc.track[track].length.mins*60+
+			  ginfo->disc.track[track].length.secs-2)*
+		         FLAC_BITRATE*1024/8);
+  else
   /* It's not the best way, but i couldn't find anything better */
   tmp_encsize=(double)((ginfo->disc.track[track].length.mins*60+
 			ginfo->disc.track[track].length.secs-2)*
openSUSE Build Service is sponsored by