changeset 4239:51291ce4eb54

some endianness-related changes, corrected error handling
author Eugene Zagidullin <e.asphyx@gmail.com>
date Sun, 03 Feb 2008 19:02:04 +0300
parents 75ea2083e744
children 29c8603a877a
files src/audacious/output.c src/libSAD/dither.c src/libSAD/dither_ops.c
diffstat 3 files changed, 101 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/output.c	Sun Feb 03 00:50:48 2008 +0300
+++ b/src/audacious/output.c	Sun Feb 03 19:02:04 2008 +0300
@@ -419,7 +419,7 @@
     if (src_enabled) {
         AUDDBG("initializing dithering engine for 2 stage conversion\n");
         input_sad_fmt.sample_format = sadfmt_from_afmt(fmt);
-        if (input_sad_fmt.sample_format < 0) return -1;
+        if (input_sad_fmt.sample_format < 0) return FALSE;
         input_sad_fmt.fracbits = 0;
         input_sad_fmt.channels = nch;
         input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED;
@@ -434,7 +434,7 @@
         sad_state_to_float = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret);
         if (sad_state_to_float == NULL) {
             AUDDBG("ditherer init failed (decoder's native --> float)\n");
-            return -1;
+            return FALSE;
         }
         SAD_dither_set_dither (sad_state_to_float, FALSE);
         
@@ -445,7 +445,7 @@
         input_sad_fmt.samplerate = 0;
         
         output_sad_fmt.sample_format = sadfmt_from_afmt(output_fmt);
-        if (output_sad_fmt.sample_format < 0) return -1;
+        if (output_sad_fmt.sample_format < 0) return FALSE;
         output_sad_fmt.fracbits = 0;
         output_sad_fmt.channels = nch;
         output_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED;
@@ -455,7 +455,7 @@
         if (sad_state_from_float == NULL) {
             SAD_dither_free(sad_state_to_float);
             AUDDBG("ditherer init failed (float --> output)\n");
-            return -1;
+            return FALSE;
         }
         SAD_dither_set_dither (sad_state_from_float, TRUE);
         
@@ -466,7 +466,7 @@
         AUDDBG("initializing dithering engine for direct conversion\n");
 
         input_sad_fmt.sample_format = sadfmt_from_afmt(fmt);
-        if (input_sad_fmt.sample_format < 0) return -1;
+        if (input_sad_fmt.sample_format < 0) return FALSE;
         input_sad_fmt.fracbits = 0;
         input_sad_fmt.channels = nch;
         input_sad_fmt.channels_order = SAD_CHORDER_INTERLEAVED;
@@ -481,7 +481,7 @@
         sad_state = SAD_dither_init(&input_sad_fmt, &output_sad_fmt, &ret);
         if (sad_state == NULL) {
             AUDDBG("ditherer init failed\n");
-            return -1;
+            return FALSE;
         }
         SAD_dither_set_dither (sad_state, TRUE);
 
@@ -494,7 +494,7 @@
     op = get_current_output_plugin();
 
     if (op == NULL)
-        return -1;
+        return FALSE;
 
     /* Is our output port already open? */
     if ((op_state.rate != 0 && op_state.nch != 0) &&
@@ -503,7 +503,7 @@
         /* Yes, and it's the correct sampling rate. Reset the counter and go. */
         AUDDBG("flushing output instead of reopening\n");
         op->flush(0);
-        return 1;
+        return TRUE;
     }
     else if (op_state.rate != 0 && op_state.nch != 0)
         op->close_audio();
--- a/src/libSAD/dither.c	Sun Feb 03 00:50:48 2008 +0300
+++ b/src/libSAD/dither.c	Sun Feb 03 19:02:04 2008 +0300
@@ -311,6 +311,8 @@
     case SAD_SAMPLE_U16_LE:
     case SAD_SAMPLE_U16_BE: priv->output_bits = 16; break;
     case SAD_SAMPLE_S24:
+    case SAD_SAMPLE_S24_LE:
+    case SAD_SAMPLE_S24_BE:
     case SAD_SAMPLE_U24: priv->output_bits = 24; break;
     case SAD_SAMPLE_S32:
     case SAD_SAMPLE_U32: priv->output_bits = 32; break;
@@ -331,6 +333,8 @@
     case SAD_SAMPLE_U16_LE:
     case SAD_SAMPLE_U16_BE: priv->input_bits = 16; break;
     case SAD_SAMPLE_S24:
+    case SAD_SAMPLE_S24_LE:
+    case SAD_SAMPLE_S24_BE:
     case SAD_SAMPLE_U24: priv->input_bits = 24; break;
     case SAD_SAMPLE_S32:
     case SAD_SAMPLE_U32: priv->input_bits = 32; break;
--- a/src/libSAD/dither_ops.c	Sun Feb 03 00:50:48 2008 +0300
+++ b/src/libSAD/dither_ops.c	Sun Feb 03 19:02:04 2008 +0300
@@ -21,17 +21,36 @@
 #include "dither_ops.h"
 #include "dither.h"
 
-#define SAD_GET_LE16(a) ( (uint16_t)(((uint8_t*)(a))[0]) | (uint16_t)(((uint8_t*)(a))[1]) << 8 )
-#define SAD_GET_BE16(a) ( (uint16_t)(((uint8_t*)(a))[1]) | (uint16_t)(((uint8_t*)(a))[0]) << 8 )
+#define SAD_GET_LE16(a) ( (uint16_t)(((uint8_t*)(a))[0])      | (uint16_t)(((uint8_t*)(a))[1]) << 8 )
+#define SAD_GET_BE16(a) ( (uint16_t)(((uint8_t*)(a))[0]) << 8 | (uint16_t)(((uint8_t*)(a))[1]) )
+
+#define SAD_GET_LE32(a) ( (uint32_t)(((uint8_t*)(a))[0])       | (uint32_t)(((uint8_t*)(a))[1]) << 8 | \
+                          (uint32_t)(((uint8_t*)(a))[2]) << 16 | (uint32_t)(((uint8_t*)(a))[3]) << 24 )
+#define SAD_GET_BE32(a) ( (uint32_t)(((uint8_t*)(a))[0]) << 24 | (uint32_t)(((uint8_t*)(a))[1]) << 16 | \
+                          (uint32_t)(((uint8_t*)(a))[2]) << 8 | (uint32_t)(((uint8_t*)(a))[3]) )
 
 #define SAD_PUT_LE16(a,b) { \
-          ((uint8_t*)(a))[0] = (uint8_t)((uint32_t)(b) & 0x000000ff);        \
+          ((uint8_t*)(a))[0] = (uint8_t)((uint32_t)(b) &  0x000000ff);        \
           ((uint8_t*)(a))[1] = (uint8_t)(((uint32_t)(b) & 0x0000ff00) >> 8); \
         }
 
 #define SAD_PUT_BE16(a,b) { \
           ((uint8_t*)(a))[0] = (uint8_t)(((uint32_t)(b) & 0x0000ff00) >> 8); \
-          ((uint8_t*)(a))[1] = (uint8_t)((uint32_t)(b) & 0x000000ff);        \
+          ((uint8_t*)(a))[1] = (uint8_t)((uint32_t)(b) &  0x000000ff);        \
+        }
+
+#define SAD_PUT_LE32(a,b) { \
+          ((uint8_t*)(a))[0] = (uint8_t)((uint32_t)(b) &  0x000000ff);        \
+          ((uint8_t*)(a))[1] = (uint8_t)(((uint32_t)(b) & 0x0000ff00) >> 8); \
+          ((uint8_t*)(a))[2] = (uint8_t)(((uint32_t)(b) & 0x00ff0000) >> 16); \
+          ((uint8_t*)(a))[3] = (uint8_t)(((uint32_t)(b) & 0xff000000) >> 24); \
+        }
+
+#define SAD_PUT_BE32(a,b) { \
+          ((uint8_t*)(a))[0] = (uint8_t)(((uint32_t)(b) & 0xff000000) >> 24); \
+          ((uint8_t*)(a))[1] = (uint8_t)(((uint32_t)(b) & 0x00ff0000) >> 16); \
+          ((uint8_t*)(a))[2] = (uint8_t)(((uint32_t)(b) & 0x0000ff00) >> 8); \
+          ((uint8_t*)(a))[3] = (uint8_t)((uint32_t)(b) &  0x000000ff);       \
         }
 
 
@@ -303,6 +322,50 @@
   ((int32_t**)buf)[ch][i] = (int32_t)sample & 0x00ffffff;
 }
 
+/* LE signed */
+
+static int32_t get_s24_le_i_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  return (int32_t)EXPAND_24_TO_32(SAD_GET_LE32(tmp));
+}
+
+static int32_t get_s24_le_s_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  return (int32_t)EXPAND_24_TO_32(SAD_GET_LE32(tmp));
+}
+
+static void put_s24_le_i_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  SAD_PUT_LE32(tmp, sample & 0x00ffffff);
+}
+
+static void put_s24_le_s_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  SAD_PUT_LE32(tmp, sample & 0x00ffffff);
+}
+
+/* BE signed */
+
+static int32_t get_s24_be_i_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  return (int32_t)EXPAND_24_TO_32(SAD_GET_BE32(tmp));
+}
+
+static int32_t get_s24_be_s_sample (void *buf, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  return (int32_t)EXPAND_24_TO_32(SAD_GET_BE32(tmp));
+}
+
+static void put_s24_be_i_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = (int32_t*)buf+i*nch+ch;
+  SAD_PUT_BE32(tmp, sample & 0x00ffffff);
+}
+
+static void put_s24_be_s_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int32_t *tmp = ((int32_t**)buf)[ch]+i;
+  SAD_PUT_BE32(tmp, sample & 0x00ffffff);
+}
+
 /* unsigned */
 static int32_t get_u24_i_sample (void *buf, int nch, int ch, int i) {
   return (int32_t)EXPAND_24_TO_32(((uint32_t*)buf)[i*nch+ch]) - 8388608;
@@ -330,6 +393,26 @@
   &put_s24_s_sample
 };
 
+static SAD_buffer_ops buf_s24_le_i_ops = {
+  &get_s24_le_i_sample,
+  &put_s24_le_i_sample
+};
+
+static SAD_buffer_ops buf_s24_le_s_ops = {
+  &get_s24_le_s_sample,
+  &put_s24_le_s_sample
+};
+
+static SAD_buffer_ops buf_s24_be_i_ops = {
+  &get_s24_be_i_sample,
+  &put_s24_be_i_sample
+};
+
+static SAD_buffer_ops buf_s24_be_s_ops = {
+  &get_s24_be_s_sample,
+  &put_s24_be_s_sample
+};
+
 static SAD_buffer_ops buf_u24_i_ops = {
   &get_u24_i_sample,
   &put_u24_i_sample
@@ -410,8 +493,8 @@
   {&buf_u16_be_i_ops, &buf_u16_be_s_ops}, /* SAD_SAMPLE_U16_BE */
 
   {&buf_s24_i_ops,    &buf_s24_s_ops},	  /* SAD_SAMPLE_S24    */
-  {NULL,              NULL}, 		  /* SAD_SAMPLE_S24_LE */
-  {NULL,              NULL}, 		  /* SAD_SAMPLE_S24_BE */
+  {&buf_s24_le_i_ops, &buf_s24_le_s_ops}, /* SAD_SAMPLE_S24_LE */
+  {&buf_s24_be_i_ops, &buf_s24_be_s_ops}, /* SAD_SAMPLE_S24_BE */
   {&buf_u24_i_ops,    &buf_u24_s_ops},	  /* SAD_SAMPLE_U24    */
   {NULL,              NULL}, 		  /* SAD_SAMPLE_U24_LE */
   {NULL,              NULL}, 		  /* SAD_SAMPLE_U24_BE */