changeset 4259:92642f860860

- added template for src_flow - vis_flow can work now with FMT_FLOAT, but disabled pending src stuff refactoring
author Eugene Zagidullin <e.asphyx@gmail.com>
date Sat, 09 Feb 2008 01:05:36 +0300
parents 8157686b8115
children 032207ff2a87 a41fb6bc632a
files src/audacious/Makefile src/audacious/input.c src/audacious/output.c src/audacious/plugin.h src/audacious/src_flow.c src/audacious/src_flow.h src/audacious/util.c src/audacious/util.h
diffstat 8 files changed, 176 insertions(+), 175 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/Makefile	Fri Feb 08 22:21:56 2008 +0300
+++ b/src/audacious/Makefile	Sat Feb 09 01:05:36 2008 +0300
@@ -36,6 +36,7 @@
        pluginenum.c						\
        rcfile.c							\
        signals.c						\
+       src_flow.c						\
        strings.c						\
        tuple.c							\
        tuple_formatter.c				\
--- a/src/audacious/input.c	Fri Feb 08 22:21:56 2008 +0300
+++ b/src/audacious/input.c	Sat Feb 09 01:05:36 2008 +0300
@@ -1,5 +1,5 @@
 /*  Audacious - Cross-platform multimedia player
- *  Copyright (C) 2005-2007  Audacious development team
+ *  Copyright (C) 2005-2008  Audacious development team
  *
  *  Based on BMP:
  *  Copyright (C) 2003-2004  BMP development team
@@ -53,6 +53,8 @@
 #include "vfs_buffer.h"
 #include "vfs_buffered_file.h"
 
+#include "libSAD.h"
+
 G_LOCK_DEFINE_STATIC(vis_mutex);
 
 struct _VisNode {
@@ -77,6 +79,8 @@
 
 static GList *vis_list = NULL;
 static int volume_l = -1, volume_r = -1;
+static SAD_dither_t *sad_state = NULL;
+static gint sad_nch = -1;
 
 InputPlayback *
 get_current_input_playback(void)
@@ -144,141 +148,63 @@
     G_UNLOCK(vis_mutex);
 }
 
-static void
-convert_to_s16_ne(AFormat fmt, gpointer ptr, gint16 * left,
-                  gint16 * right, gint nch, gint max)
-{
-    gint16 *ptr16;
-    guint16 *ptru16;
-    guint8 *ptru8;
-    gint i;
-
-    switch (fmt) {
-    case FMT_U8:
-        ptru8 = ptr;
-        if (nch == 1)
-            for (i = 0; i < max; i++)
-                left[i] = ((*ptru8++) ^ 128) << 8;
-        else
-            for (i = 0; i < max; i++) {
-                left[i] = ((*ptru8++) ^ 128) << 8;
-                right[i] = ((*ptru8++) ^ 128) << 8;
-            }
-        break;
-    case FMT_S8:
-        ptru8 = ptr;
-        if (nch == 1)
-            for (i = 0; i < max; i++)
-                left[i] = (*ptru8++) << 8;
-        else
-            for (i = 0; i < max; i++) {
-                left[i] = (*ptru8++) << 8;
-                right[i] = (*ptru8++) << 8;
-            }
-        break;
-    case FMT_U16_LE:
-        ptru16 = ptr;
-        if (nch == 1)
-            for (i = 0; i < max; i++, ptru16++)
-                left[i] = GUINT16_FROM_LE(*ptru16) ^ 32768;
-        else
-            for (i = 0; i < max; i++) {
-                left[i] = GUINT16_FROM_LE(*ptru16) ^ 32768;
-                ptru16++;
-                right[i] = GUINT16_FROM_LE(*ptru16) ^ 32768;
-                ptru16++;
-            }
-        break;
-    case FMT_U16_BE:
-        ptru16 = ptr;
-        if (nch == 1)
-            for (i = 0; i < max; i++, ptru16++)
-                left[i] = GUINT16_FROM_BE(*ptru16) ^ 32768;
-        else
-            for (i = 0; i < max; i++) {
-                left[i] = GUINT16_FROM_BE(*ptru16) ^ 32768;
-                ptru16++;
-                right[i] = GUINT16_FROM_BE(*ptru16) ^ 32768;
-                ptru16++;
-            }
-        break;
-    case FMT_U16_NE:
-        ptru16 = ptr;
-        if (nch == 1)
-            for (i = 0; i < max; i++)
-                left[i] = (*ptru16++) ^ 32768;
-        else
-            for (i = 0; i < max; i++) {
-                left[i] = (*ptru16++) ^ 32768;
-                right[i] = (*ptru16++) ^ 32768;
-            }
-        break;
-    case FMT_S16_LE:
-        ptr16 = ptr;
-        if (nch == 1)
-            for (i = 0; i < max; i++, ptr16++)
-                left[i] = GINT16_FROM_LE(*ptr16);
-        else
-            for (i = 0; i < max; i++) {
-                left[i] = GINT16_FROM_LE(*ptr16);
-                ptr16++;
-                right[i] = GINT16_FROM_LE(*ptr16);
-                ptr16++;
-            }
-        break;
-    case FMT_S16_BE:
-        ptr16 = ptr;
-        if (nch == 1)
-            for (i = 0; i < max; i++, ptr16++)
-                left[i] = GINT16_FROM_BE(*ptr16);
-        else
-            for (i = 0; i < max; i++) {
-                left[i] = GINT16_FROM_BE(*ptr16);
-                ptr16++;
-                right[i] = GINT16_FROM_BE(*ptr16);
-                ptr16++;
-            }
-        break;
-    case FMT_S16_NE:
-        ptr16 = ptr;
-        if (nch == 1)
-            for (i = 0; i < max; i++)
-                left[i] = (*ptr16++);
-        else
-            for (i = 0; i < max; i++) {
-                left[i] = (*ptr16++);
-                right[i] = (*ptr16++);
-            }
-        break;
-    default:
-        AUDDBG("Incorrect sample format!\n");
-    }
-}
-
 InputVisType
 input_get_vis_type()
 {
     return INPUT_VIS_OFF;
 }
 
+static SAD_dither_t*
+init_sad(gint nch)
+{
+    gint ret;
+
+    SAD_buffer_format in, out;
+    in.sample_format = SAD_SAMPLE_FLOAT;
+    in.fracbits = 0;
+    in.channels = nch;
+    in.channels_order = SAD_CHORDER_INTERLEAVED;
+    in.samplerate = 0;
+    
+    out.sample_format = SAD_SAMPLE_S16;
+    out.fracbits = 0;
+    out.channels = nch;
+    out.channels_order = SAD_CHORDER_SEPARATED; /* sic! --asphyx */
+    out.samplerate = 0;
+        
+    SAD_dither_t *state = SAD_dither_init(&in, &out, &ret);
+    if (state != NULL) SAD_dither_set_dither(state, FALSE);
+    return state;
+}
+
 void
 input_add_vis_pcm(gint time, AFormat fmt, gint nch, gint length, gpointer ptr)
 {
     VisNode *vis_node;
     gint max;
+    
+    if (fmt != FMT_FLOAT || nch > 2) return;
 
-    max = length / nch;
-    if (fmt == FMT_U16_LE || fmt == FMT_U16_BE || fmt == FMT_U16_NE ||
-        fmt == FMT_S16_LE || fmt == FMT_S16_BE || fmt == FMT_S16_NE)
-        max /= 2;
+    if (sad_state == NULL || nch != sad_nch) {
+        if(sad_state != NULL) SAD_dither_free(sad_state);
+        sad_state = init_sad(nch);
+        if(sad_state == NULL) return;
+        sad_nch = nch;
+    }
+
+    max = length / nch / sizeof(float);
     max = CLAMP(max, 0, 512);
 
     vis_node = g_slice_new0(VisNode);
     vis_node->time = time;
     vis_node->nch = nch;
     vis_node->length = max;
-    convert_to_s16_ne(fmt, ptr, vis_node->data[0], vis_node->data[1], nch,
-                      max);
+
+    gint16 *tmp[2];
+
+    tmp[0] = vis_node->data[0];
+    tmp[1] = vis_node->data[1];
+    SAD_dither_process_buffer(sad_state, ptr, tmp, max);
 
     G_LOCK(vis_mutex);
     vis_list = g_list_append(vis_list, vis_node);
--- a/src/audacious/output.c	Fri Feb 08 22:21:56 2008 +0300
+++ b/src/audacious/output.c	Sat Feb 09 01:05:36 2008 +0300
@@ -45,6 +45,7 @@
 #include "visualization.h"
 
 #include "libSAD.h"
+#include "util.h"
 
 #include <math.h>
 
@@ -83,54 +84,8 @@
     .written_time = get_written_time,
 };
 
-static const struct {
-    AFormat afmt;
-    SAD_sample_format sadfmt;
-} format_table[] = {
-    {FMT_U8, SAD_SAMPLE_U8},
-    {FMT_S8, SAD_SAMPLE_S8},
-
-    {FMT_S16_LE, SAD_SAMPLE_S16_LE},
-    {FMT_S16_BE, SAD_SAMPLE_S16_BE},
-    {FMT_S16_NE, SAD_SAMPLE_S16},
-
-    {FMT_U16_LE, SAD_SAMPLE_U16_LE},
-    {FMT_U16_BE, SAD_SAMPLE_U16_BE},
-    {FMT_U16_NE, SAD_SAMPLE_U16},
-
-    {FMT_S24_LE, SAD_SAMPLE_S24_LE},
-    {FMT_S24_BE, SAD_SAMPLE_S24_BE},
-    {FMT_S24_NE, SAD_SAMPLE_S24},
-    
-    {FMT_U24_LE, SAD_SAMPLE_U24_LE},
-    {FMT_U24_BE, SAD_SAMPLE_U24_BE},
-    {FMT_U24_NE, SAD_SAMPLE_U24},
-
-    {FMT_S32_LE, SAD_SAMPLE_S32_LE},
-    {FMT_S32_BE, SAD_SAMPLE_S32_BE},
-    {FMT_S32_NE, SAD_SAMPLE_S32},
-    
-    {FMT_U32_LE, SAD_SAMPLE_U32_LE},
-    {FMT_U32_BE, SAD_SAMPLE_U32_BE},
-    {FMT_U32_NE, SAD_SAMPLE_U32},
-    
-    {FMT_FLOAT, SAD_SAMPLE_FLOAT},
-    {FMT_FIXED32, SAD_SAMPLE_FIXED32},
-};
-
 static void apply_replaygain_info (ReplayGainInfo *rg_info);
 
-static SAD_sample_format
-sadfmt_from_afmt(AFormat fmt)
-{
-    int i;
-    for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++) {
-        if (format_table[i].afmt == fmt) return format_table[i].sadfmt;
-    }
-
-    return -1;
-}
-
 OutputPlugin *
 get_current_output_plugin(void)
 {
@@ -606,25 +561,30 @@
               )
 {
     static Flow *postproc_flow = NULL;
+    static Flow *legacy_flow = NULL;
     OutputPlugin *op = playback->output;
     gint writeoffs;
 
     if (length <= 0) return;
     gint time = playback->output->written_time();
 
+    if (legacy_flow == NULL)
+    {
+        legacy_flow = flow_new();
+        flow_link_element(legacy_flow, iir_flow);
+        flow_link_element(legacy_flow, effect_flow);
+        flow_link_element(legacy_flow, volumecontrol_flow);
+    }
+    
     if (postproc_flow == NULL)
     {
         postproc_flow = flow_new();
-        flow_link_element(postproc_flow, iir_flow);
-        flow_link_element(postproc_flow, effect_flow);
         flow_link_element(postproc_flow, vis_flow);
-        flow_link_element(postproc_flow, volumecontrol_flow);
     }
 
 #ifdef USE_SRC
     if(src_state != NULL)
       {
-        /*int lrLength = length / nch;*/
         int lrLength = length / FMT_SIZEOF(fmt);
         int overLrLength = (int)floor(lrLength*(src_data.src_ratio+1));
 	if(lengthOfSrcIn < lrLength)
@@ -641,8 +601,11 @@
 	    srcOut = (float*)malloc(sizeof(float)*overLrLength);
 	    wOut = (short int*)malloc(FMT_SIZEOF(op_state.fmt) * overLrLength);
 	  }
-        /*src_short_to_float_array((short int*)ptr, srcIn, lrLength);*/
+        
         SAD_dither_process_buffer(sad_state_to_float, ptr, srcIn, lrLength / nch);
+        /*flow_execute(postproc_flow, time, &srcIn, lrLength * sizeof(float), FMT_FLOAT, op_state.rate, nch);*/ /*FIXME*/
+
+
         src_data.data_in = srcIn;
         src_data.data_out = srcOut;
         src_data.end_of_input = 0;
@@ -654,7 +617,6 @@
           }
         else
           {
-            /*src_float_to_short_array(srcOut, wOut, src_data.output_frames_gen*2);*/
             SAD_dither_process_buffer(sad_state_from_float, srcOut, wOut, src_data.output_frames_gen);
             ptr = wOut;
             length = src_data.output_frames_gen *  op_state.nch * FMT_SIZEOF(op_state.fmt);
@@ -676,9 +638,9 @@
     
     if (op_state.fmt == FMT_S16_NE || (op_state.fmt == FMT_S16_LE && G_BYTE_ORDER == G_LITTLE_ENDIAN) ||
                                       (op_state.fmt == FMT_S16_BE && G_BYTE_ORDER == G_BIG_ENDIAN)) {
-        length = flow_execute(postproc_flow, time, &ptr, length, op_state.fmt, op_state.rate, op_state.nch);
+        length = flow_execute(legacy_flow, time, &ptr, length, op_state.fmt, op_state.rate, op_state.nch);
     } else {
-        AUDDBG("postproc_flow can deal only with S16_NE streams\n"); /*FIXME*/
+        AUDDBG("legacy_flow can deal only with S16_NE streams\n"); /*FIXME*/
     }
 
     writeoffs = 0;
--- a/src/audacious/plugin.h	Fri Feb 08 22:21:56 2008 +0300
+++ b/src/audacious/plugin.h	Sat Feb 09 01:05:36 2008 +0300
@@ -1,5 +1,5 @@
 /*  Audacious
- *  Copyright (C) 2005-2007  Audacious team.
+ *  Copyright (C) 2005-2008  Audacious team.
  *
  *  BMP - Cross-platform multimedia player
  *  Copyright (C) 2003-2004  BMP development team.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audacious/src_flow.c	Sat Feb 09 01:05:36 2008 +0300
@@ -0,0 +1,31 @@
+/*  Audacious - Cross-platform multimedia player
+ *  Copyright (C) 2005-2008  Audacious development team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 3 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses>.
+ *
+ *  The Audacious team does not consider modular code linking to
+ *  Audacious or using our public API to be a derived work.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#ifdef USE_SRC
+
+#include <samplerate.h>
+
+/* The devil is in the details */
+
+#endif /* USE_SRC */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audacious/src_flow.h	Sat Feb 09 01:05:36 2008 +0300
@@ -0,0 +1,30 @@
+/*  Audacious - Cross-platform multimedia player
+ *  Copyright (C) 2005-2008  Audacious development team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 3 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses>.
+ *
+ *  The Audacious team does not consider modular code linking to
+ *  Audacious or using our public API to be a derived work.
+ */
+
+#ifndef SRC_FLOW_H
+#define SRC_FLOW_H
+
+#include <glib.h>
+#include "flow.h"
+
+void src_flow(FlowContext *context);
+void src_flow_init(gint infreq, gint outfreq);
+void src_flow_free();
+
+#endif
--- a/src/audacious/util.c	Fri Feb 08 22:21:56 2008 +0300
+++ b/src/audacious/util.c	Sat Feb 09 01:05:36 2008 +0300
@@ -1,5 +1,5 @@
 /*  Audacious - Cross-platform multimedia player
- *  Copyright (C) 2005-2007  Audacious development team
+ *  Copyright (C) 2005-2008  Audacious development team
  *
  *  Based on BMP:
  *  Copyright (C) 2003-2004  BMP development team.
@@ -52,6 +52,7 @@
 #include "playback.h"
 #include "strings.h"
 #include "ui_playlist.h"
+#include "libSAD.h"
 
 #ifdef USE_CHARDET
     #include "../libguess/libguess.h"
@@ -72,6 +73,53 @@
     gboolean found;
 } FindFileContext;
 
+static const struct {
+    AFormat afmt;
+    SAD_sample_format sadfmt;
+} format_table[] = {
+    {FMT_U8, SAD_SAMPLE_U8},
+    {FMT_S8, SAD_SAMPLE_S8},
+
+    {FMT_S16_LE, SAD_SAMPLE_S16_LE},
+    {FMT_S16_BE, SAD_SAMPLE_S16_BE},
+    {FMT_S16_NE, SAD_SAMPLE_S16},
+
+    {FMT_U16_LE, SAD_SAMPLE_U16_LE},
+    {FMT_U16_BE, SAD_SAMPLE_U16_BE},
+    {FMT_U16_NE, SAD_SAMPLE_U16},
+
+    {FMT_S24_LE, SAD_SAMPLE_S24_LE},
+    {FMT_S24_BE, SAD_SAMPLE_S24_BE},
+    {FMT_S24_NE, SAD_SAMPLE_S24},
+    
+    {FMT_U24_LE, SAD_SAMPLE_U24_LE},
+    {FMT_U24_BE, SAD_SAMPLE_U24_BE},
+    {FMT_U24_NE, SAD_SAMPLE_U24},
+
+    {FMT_S32_LE, SAD_SAMPLE_S32_LE},
+    {FMT_S32_BE, SAD_SAMPLE_S32_BE},
+    {FMT_S32_NE, SAD_SAMPLE_S32},
+    
+    {FMT_U32_LE, SAD_SAMPLE_U32_LE},
+    {FMT_U32_BE, SAD_SAMPLE_U32_BE},
+    {FMT_U32_NE, SAD_SAMPLE_U32},
+    
+    {FMT_FLOAT, SAD_SAMPLE_FLOAT},
+    {FMT_FIXED32, SAD_SAMPLE_FIXED32},
+};
+
+SAD_sample_format
+sadfmt_from_afmt(AFormat fmt)
+{
+    int i;
+    for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++) {
+        if (format_table[i].afmt == fmt) return format_table[i].sadfmt;
+    }
+
+    return -1;
+}
+
+
 static gboolean
 find_file_func(const gchar * path, const gchar * basename, gpointer data)
 {
--- a/src/audacious/util.h	Fri Feb 08 22:21:56 2008 +0300
+++ b/src/audacious/util.h	Sat Feb 09 01:05:36 2008 +0300
@@ -1,5 +1,5 @@
 /*  Audacious - Cross-platform multimedia player
- *  Copyright (C) 2005-2007  Audacious development team
+ *  Copyright (C) 2005-2008  Audacious development team
  *
  *  Based on BMP:
  *  Copyright (C) 2003-2004  BMP development team
@@ -38,6 +38,7 @@
 G_BEGIN_DECLS
 
 #include "audacious/plugin.h"
+#include "libSAD/libSAD.h"
 
 #define SWAP(a, b)      { a^=b; b^=a; a^=b; }
 
@@ -104,6 +105,8 @@
 
 gchar *construct_uri(gchar *string, const gchar *playlist_name);
 
+SAD_sample_format sadfmt_from_afmt(AFormat fmt);
+
 G_END_DECLS
 
 #endif