kmatheussen / jack_capture

A program for recording soundfiles with jack
http://www.notam02.no/arkiv/src/
Other
75 stars 28 forks source link

Fileprefix is not computed correctly on file-rotation #20

Open DerOetzi opened 8 years ago

DerOetzi commented 8 years ago

I noticed an issue on filenames generated when the wave-file is rotated by jack_capture.

The file are looking like:

jack_capture.01.wav jack_capture.01.wav.01.wav ...

I did the following local fix you may want to patch into your code:

diff --git a/jack_capture.c b/jack_capture.c
index ee03a8c..7266a82 100644
--- a/jack_capture.c
+++ b/jack_capture.c
@@ -1047,8 +1047,9 @@ static void hook_file_rotated(char *oldfn, char *newfn, int num, int xruns, int
 //////////////////////// DISK ///////////////////////////////////////
 /////////////////////////////////////////////////////////////////////

-// These four variables are used in case we break the 4GB barriere for standard wav files.
+// These five variables are used in case we break the 4GB barriere for standard wav files.
 static int num_files=1;
+static int seq=0;
 static int64_t disksize=0;
 static bool is_using_wav=true;
 static int bytes_per_frame;
@@ -1274,11 +1275,10 @@ static int rotate_file(size_t frames, int reset_totals){

   char *filename_new;
   filename_new=my_calloc(1,strlen(base_filename)+500);
-  sprintf(filename_new,"%s.%0*d.%s",base_filename,leading_zeros+1,num_files,soundfile_format);
+  sprintf(filename_new,"%s%0*d.%s",filename_prefix,leading_zeros+1,++seq,soundfile_format);
   print_message("Closing %s, and continue writing to %s.\n",filename,filename_new);
   num_files++;
-
-  hook_file_rotated(filename, filename_new, num_files, total_overruns + total_xruns, disk_errors);
+  hook_file_rotated(filename, filename_new, seq, total_overruns + total_xruns, disk_errors);

   free(filename);
   filename=filename_new;
@@ -2383,11 +2383,10 @@ void init_arguments(int argc, char *argv[]){
   // Find filename
   {
     if(base_filename==NULL){
-      int try=0;
       base_filename=my_calloc(1,5000);
       for(;;){
-       sprintf(base_filename,"%s%0*d.%s",filename_prefix,leading_zeros+1,++try,soundfile_format);
-       if(access(base_filename,F_OK)) break;
+               sprintf(base_filename,"%s%0*d.%s",filename_prefix,leading_zeros+1,++seq,soundfile_format);
+           if(access(base_filename,F_OK)) break;