changeset 4258:8157686b8115

added FMT_SIZEOF macro
author Eugene Zagidullin <e.asphyx@gmail.com>
date Fri, 08 Feb 2008 22:21:56 +0300
parents b1f879a0bfcb
children 92642f860860
files src/audacious/output.c src/audacious/plugin.h
diffstat 2 files changed, 12 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/output.c	Wed Feb 06 22:42:46 2008 +0300
+++ b/src/audacious/output.c	Fri Feb 08 22:21:56 2008 +0300
@@ -120,34 +120,6 @@
 
 static void apply_replaygain_info (ReplayGainInfo *rg_info);
 
-static inline unsigned sample_size(AFormat fmt) {
-  switch(fmt) {
-    case FMT_S8:
-    case FMT_U8: return sizeof(gint8);
-    case FMT_S16_NE:
-    case FMT_S16_LE:
-    case FMT_S16_BE:
-    case FMT_U16_NE:
-    case FMT_U16_LE:
-    case FMT_U16_BE: return sizeof(gint16);
-    case FMT_S24_NE:
-    case FMT_S24_LE:
-    case FMT_S24_BE:
-    case FMT_U24_NE:
-    case FMT_U24_LE:
-    case FMT_U24_BE:
-    case FMT_S32_NE:
-    case FMT_S32_LE:
-    case FMT_S32_BE:
-    case FMT_U32_NE:
-    case FMT_U32_LE:
-    case FMT_U32_BE:
-    case FMT_FIXED32: return sizeof(gint32);
-    case FMT_FLOAT: return sizeof(float);
-    default: return 0;
-  }
-}
-
 static SAD_sample_format
 sadfmt_from_afmt(AFormat fmt)
 {
@@ -653,7 +625,7 @@
     if(src_state != NULL)
       {
         /*int lrLength = length / nch;*/
-        int lrLength = length / sample_size(fmt);
+        int lrLength = length / FMT_SIZEOF(fmt);
         int overLrLength = (int)floor(lrLength*(src_data.src_ratio+1));
 	if(lengthOfSrcIn < lrLength)
 	  {
@@ -667,7 +639,7 @@
 	    free(srcOut);
 	    free(wOut);
 	    srcOut = (float*)malloc(sizeof(float)*overLrLength);
-	    wOut = (short int*)malloc(sample_size(op_state.fmt) * 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);
@@ -685,13 +657,13 @@
             /*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 * sample_size(op_state.fmt);
+            length = src_data.output_frames_gen *  op_state.nch * FMT_SIZEOF(op_state.fmt);
           }
       } else
 #endif
     if(sad_state != NULL) {
-        int frames  = length / nch / sample_size(fmt);
-        int len =  frames * op_state.nch * sample_size(op_state.fmt);
+        int frames  = length / nch / FMT_SIZEOF(fmt);
+        int len =  frames * op_state.nch * FMT_SIZEOF(op_state.fmt);
         if(sad_out_buf == NULL || sad_out_buf_length < len ) {
             if(sad_out_buf != NULL) free (sad_out_buf);
             sad_out_buf = malloc(len);
--- a/src/audacious/plugin.h	Wed Feb 06 22:42:46 2008 +0300
+++ b/src/audacious/plugin.h	Fri Feb 08 22:21:56 2008 +0300
@@ -112,6 +112,13 @@
 
 #define __AUDACIOUS_ASSUMED_MAD_F_FRACBITS__ 28 /* useful for build time check for plugins linked against libmad, i.e. madplug */
 
+#define FMT_SIZEOF(a) ( \
+    (a == FMT_S8 || a == FMT_U8) ? sizeof(gint8) : (                                                                   \
+    (a == FMT_S16_NE || a == FMT_S16_LE || a == FMT_S16_BE || a == FMT_U16_NE || a == FMT_U16_LE || a == FMT_U16_BE) ? sizeof(gint16) : ( \
+    (a == FMT_S24_NE || a == FMT_S24_LE || a == FMT_S24_BE || a == FMT_U24_NE || a == FMT_U24_LE || a == FMT_U24_BE || \
+     a == FMT_S32_NE || a == FMT_S32_LE || a == FMT_S32_BE || a == FMT_U32_NE || a == FMT_U32_LE || a == FMT_U32_BE || \
+     a == FMT_FIXED32) ? sizeof(gint32) : sizeof(float))))
+
 typedef enum {
     INPUT_VIS_ANALYZER,
     INPUT_VIS_SCOPE,