changeset 981:d801d8ce24fb trunk

[svn] - replace almost all of outlame_write() with standard code from disk_writer in hope of fixing endianness problem. - make use of audacious vfs functions.
author yaz
date Fri, 27 Apr 2007 02:29:33 -0700
parents 6ba4a4bfd127
children 7b0d16a9a92f
files ChangeLog src/lame/Makefile src/lame/out_lame.c
diffstat 3 files changed, 115 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Apr 26 02:06:12 2007 -0700
+++ b/ChangeLog	Fri Apr 27 02:29:33 2007 -0700
@@ -1,3 +1,15 @@
+2007-04-26 09:06:12 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
+  revision [2100]
+  - fix overflow when calculates bitrate with non-fast scan on a huge sized file.
+  - make file info dialog always do non-fast scan. user can easily add TLEN tag of correct play time length to a VBR encoded file which does not go along with fast scan.
+  - tweak debug output.
+  
+  
+  trunk/src/madplug/decoder.c  |   57 +++++++++++++++++++++++++------------------
+  trunk/src/madplug/fileinfo.c |    2 -
+  2 files changed, 35 insertions(+), 24 deletions(-)
+
+
 2007-04-24 09:53:37 +0000  William Pitcock <nenolod@sacredspiral.co.uk>
   revision [2098]
   - disable all use of puts() unless -DDEBUG is defined.
--- a/src/lame/Makefile	Thu Apr 26 02:06:12 2007 -0700
+++ b/src/lame/Makefile	Fri Apr 27 02:29:33 2007 -0700
@@ -10,6 +10,6 @@
 
 OBJECTS = ${SOURCES:.c=.o}
 
-CFLAGS += $(PICFLAGS) $(GTK_CFLAGS) -I../../intl -I../..
+CFLAGS += $(PICFLAGS) $(GTK_CFLAGS) -I../../intl -I../.. -Wall
 
 include ../../mk/objective.mk
--- a/src/lame/out_lame.c	Thu Apr 26 02:06:12 2007 -0700
+++ b/src/lame/out_lame.c	Fri Apr 27 02:29:33 2007 -0700
@@ -28,11 +28,12 @@
 #include <audacious/beepctrl.h>
 #include <audacious/configdb.h>
 #include <audacious/util.h>
+#include <audacious/vfs.h>
 
 #include <lame/lame.h>
 
 #define ENCBUFFER_SIZE 35000
-#define OUT_LAME_VER "0.2"
+#define OUT_LAME_VER "0.3"
 /* #define DEBUG 1 */
 
 GtkWidget *configure_win = NULL, *path_vbox;
@@ -77,12 +78,15 @@
 
 GtkWidget *enc_quality_vbox, *hbox1, *hbox2;
 
-// will be used in flushing
-AFormat oldfmt;
-gint oldrate, oldnch;
+struct format_info { 
+    AFormat format;
+    int frequency;
+    int channels;
+};
+struct format_info input;
 
 static gchar *file_path = NULL;
-static FILE *output_file = NULL;
+static VFSFile *output_file = NULL;
 static guint64 written = 0;
 static guint64 olen = 0;
 static AFormat afmt;
@@ -191,7 +195,6 @@
 
 };
 
-
 OutputPlugin *get_oplugin_info(void)
 {
     outlame_op.description = g_strdup_printf("Out-Lame %s", OUT_LAME_VER);
@@ -303,8 +306,10 @@
     int b_use_path_anyway = 0;
     gchar *tmpfilename = NULL;
 
-    /* store open paramators for reopen */
-    oldfmt = fmt; oldrate = rate; oldnch = nch;
+    /* store open paramators */
+    input.format = fmt;
+    input.frequency = rate;
+    input.channels = nch;
 
     /* So all the values will be reset to the ones saved */
     /* Easier than to implement a tmp variable for every value */
@@ -380,13 +385,13 @@
 #ifdef DEBUG
     printf("filename = %s\n", filename);
 #endif
-    output_file = fopen(filename, "w");
+    output_file = vfs_fopen(filename, "w");
     g_free(filename);
 
     if (!output_file)
         return 0;
 
-    if ((int) (gfp = lame_init()) == -1)
+    if ((gfp = lame_init()) == (void *)-1)
         return 0;
 
     srate = rate;
@@ -480,23 +485,102 @@
     return 1;
 }
 
+static void convert_buffer(gpointer buffer, gint length)
+{
+    gint i;
+
+    if (afmt == FMT_S8)
+    {
+        guint8 *ptr1 = buffer;
+        gint8 *ptr2 = buffer;
+
+        for (i = 0; i < length; i++)
+            *(ptr1++) = *(ptr2++) ^ 128;
+    }
+    if (afmt == FMT_S16_BE)
+    {
+        gint16 *ptr = buffer;
+
+        for (i = 0; i < length >> 1; i++, ptr++)
+            *ptr = GUINT16_SWAP_LE_BE(*ptr);
+    }
+    if (afmt == FMT_S16_NE)
+    {
+        gint16 *ptr = buffer;
+
+        for (i = 0; i < length >> 1; i++, ptr++)
+            *ptr = GINT16_TO_LE(*ptr);
+    }
+    if (afmt == FMT_U16_BE)
+    {
+        gint16 *ptr1 = buffer;
+        guint16 *ptr2 = buffer;
+
+        for (i = 0; i < length >> 1; i++, ptr2++)
+            *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_BE(*ptr2) ^ 32768);
+    }
+    if (afmt == FMT_U16_LE)
+    {
+        gint16 *ptr1 = buffer;
+        guint16 *ptr2 = buffer;
+
+        for (i = 0; i < length >> 1; i++, ptr2++)
+            *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_LE(*ptr2) ^ 32768);
+    }
+    if (afmt == FMT_U16_NE)
+    {
+        gint16 *ptr1 = buffer;
+        guint16 *ptr2 = buffer;
+
+        for (i = 0; i < length >> 1; i++, ptr2++)
+            *(ptr1++) = GINT16_TO_LE((*ptr2) ^ 32768);
+    }
+}
+
 static void outlame_write(void *ptr, gint length)
 {
+    AFormat new_format;
+    int new_frequency, new_channels;
+    EffectPlugin *ep;
+
+    new_format = input.format;
+    new_frequency = input.frequency;
+    new_channels = input.channels;
+
+    ep = get_current_effect_plugin();
+    if ( effects_enabled() && ep && ep->query_format ) { 
+        ep->query_format(&new_format,&new_frequency,&new_channels);
+    }
+
+    if ( effects_enabled() && ep && ep->mod_samples ) { 
+        length = ep->mod_samples(&ptr,length,
+                                 input.format,
+                                 input.frequency,
+                                 input.channels );
+    }
+
+    if (afmt == FMT_S8 || afmt == FMT_S16_BE ||
+        afmt == FMT_U16_LE || afmt == FMT_U16_BE || afmt == FMT_U16_NE)
+        convert_buffer(ptr, length);
+#ifdef WORDS_BIGENDIAN
+    if (afmt == FMT_S16_NE)
+        convert_buffer(ptr, length);
+#endif
 
     if (inch == 1) {
         encout =
-            lame_encode_buffer(gfp, (short *)ptr, (short *)ptr, length / 2, encbuffer,
+            lame_encode_buffer(gfp, ptr, ptr, length / 2, encbuffer,
                                ENCBUFFER_SIZE);
     }
     else {
         encout =
-            lame_encode_buffer_interleaved(gfp, (short *)ptr, length / 4, encbuffer,
+            lame_encode_buffer_interleaved(gfp, ptr, length / 4, encbuffer,
                                            ENCBUFFER_SIZE);
     }
-    fwrite(encbuffer, 1, encout, output_file);
+
+    vfs_fwrite(encbuffer, 1, encout, output_file);
     written += encout;
     olen += length;
-
 }
 
 static void outlame_close(void)
@@ -504,11 +588,11 @@
     if (output_file) {
 
         encout = lame_encode_flush_nogap(gfp, encbuffer, ENCBUFFER_SIZE);
-        fwrite(encbuffer, 1, encout, output_file);
+        vfs_fwrite(encbuffer, 1, encout, output_file);
 
 //        lame_mp3_tags_fid(gfp, output_file); // will erase id3v2 tag?? 
 
-        fclose(output_file);
+        vfs_fclose(output_file);
         lame_close(gfp);
 
         free_lameid3(&lameid3);
@@ -533,7 +617,7 @@
         return;
     }
     outlame_close();
-    outlame_open(oldfmt, oldrate, oldnch);
+    outlame_open(input.format, input.frequency, input.channels);
 #ifdef DEBUG
     printf("flush %d\n", time);
 #endif
@@ -2105,7 +2189,7 @@
         vbr_quality_adj = gtk_adjustment_new(4, 0, 9, 1, 1, 1);
         vbr_quality_spin =
             gtk_spin_button_new(GTK_ADJUSTMENT(vbr_quality_adj), 8, 0);
-        gtk_widget_set_usize(vbr_quality_spin, 20, 20);
+        gtk_widget_set_usize(vbr_quality_spin, 20, -1);
         gtk_box_pack_start(GTK_BOX(vbr_options_hbox3), vbr_quality_spin,
                            TRUE, TRUE, 0);
         gtk_signal_connect(GTK_OBJECT(vbr_quality_adj), "value-changed",