Hi!

Since last time I realized that the FILE* structure can handle write-buffering, so I rewrote my patch to use the standard solution. It makes a real performance difference recording massive audio.
Attached.

bye


--- AmAudioFile.h	2012-07-03 15:25:30.000000000 +0200
+++ AmAudioFile.h	2013-03-04 13:08:10.000000000 +0100
@@ -107,6 +107,8 @@
   /** internal function for opening the file */
   int fpopen_int(const string& filename, OpenMode mode, FILE* n_fp, const string& subtype);
 
+  char* write_buffer;
+
 public:
   AmSharedVar<bool> loop;
   AmSharedVar<bool> autorewind;
--- AmAudioFile.cpp	2012-07-03 15:25:30.000000000 +0200
+++ AmAudioFile.cpp	2013-03-05 15:52:48.705385034 +0100
@@ -31,6 +31,9 @@
 
 #include <string.h>
 
+#define WRITE_BUFFER_SIZE (40960)
+
+
 AmAudioFileFormat::AmAudioFileFormat(const string& name, int subtype)
   : name(name), subtype(subtype), p_subtype(0)
 {
@@ -156,6 +159,11 @@
       return -1;
     }
   }
+  if (mode == AmAudioFile::Write && write_buffer == NULL)
+  {
+    write_buffer = new char[WRITE_BUFFER_SIZE];
+    setbuffer(n_fp, write_buffer, WRITE_BUFFER_SIZE);
+  }
 
   return fpopen_int(f_name, mode, n_fp, subtype);
 }
@@ -243,13 +251,19 @@
   : AmBufferedAudio(0, 0, 0), data_size(0),
     fp(0), begin(0), loop(false), autorewind(false),
     on_close_done(false),
-    close_on_exit(true)
+    close_on_exit(true),
+    write_buffer(NULL)
 {
 }
 
 AmAudioFile::~AmAudioFile()
 {
   close();
+  if (write_buffer != NULL)
+  {
+    delete[] write_buffer;
+    write_buffer = NULL;
+  }
 }
 
 void AmAudioFile::rewind()
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to