changeset 4238:75ea2083e744

some endianness-related changes
author Eugene Zagidullin <e.asphyx@gmail.com>
date Sun, 03 Feb 2008 00:50:48 +0300
parents 8f6956130372
children 51291ce4eb54
files src/audacious/output.c src/libSAD/dither.c src/libSAD/dither_ops.c
diffstat 3 files changed, 115 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/output.c	Sat Feb 02 01:53:15 2008 +0300
+++ b/src/audacious/output.c	Sun Feb 03 00:50:48 2008 +0300
@@ -410,7 +410,8 @@
     bit_depth = cfg.output_bit_depth;
 
     AUDDBG("bit depth: %d\n", bit_depth);
-    output_fmt = (bit_depth == 24) ? FMT_S24_NE : FMT_S16_NE; /* no reason to support other output formats --asphyx */
+    output_fmt = (bit_depth == 24) ? FMT_S24_NE : FMT_S16_NE;
+    /*output_fmt = (bit_depth == 24) ? FMT_S24_LE : FMT_S16_LE;*/ /* no reason to support other output formats --asphyx */
     
     freeSAD();
 
--- a/src/libSAD/dither.c	Sat Feb 02 01:53:15 2008 +0300
+++ b/src/libSAD/dither.c	Sun Feb 03 00:50:48 2008 +0300
@@ -306,7 +306,10 @@
     case SAD_SAMPLE_U8: priv->output_bits = 8; break;
     case SAD_SAMPLE_S16:
     case SAD_SAMPLE_S16_LE:
-    case SAD_SAMPLE_U16: priv->output_bits = 16; break;
+    case SAD_SAMPLE_S16_BE:
+    case SAD_SAMPLE_U16:
+    case SAD_SAMPLE_U16_LE:
+    case SAD_SAMPLE_U16_BE: priv->output_bits = 16; break;
     case SAD_SAMPLE_S24:
     case SAD_SAMPLE_U24: priv->output_bits = 24; break;
     case SAD_SAMPLE_S32:
@@ -323,7 +326,10 @@
     case SAD_SAMPLE_U8: priv->input_bits = 8; break;
     case SAD_SAMPLE_S16:
     case SAD_SAMPLE_S16_LE:
-    case SAD_SAMPLE_U16: priv->input_bits = 16; break;
+    case SAD_SAMPLE_S16_BE:
+    case SAD_SAMPLE_U16:
+    case SAD_SAMPLE_U16_LE:
+    case SAD_SAMPLE_U16_BE: priv->input_bits = 16; break;
     case SAD_SAMPLE_S24:
     case SAD_SAMPLE_U24: priv->input_bits = 24; break;
     case SAD_SAMPLE_S32:
--- a/src/libSAD/dither_ops.c	Sat Feb 02 01:53:15 2008 +0300
+++ b/src/libSAD/dither_ops.c	Sun Feb 03 00:50:48 2008 +0300
@@ -30,8 +30,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))[0] = (uint8_t)(((uint32_t)(b) & 0x0000ff00) >> 8); \
         }
 
 
@@ -153,6 +153,70 @@
   SAD_PUT_LE16(tmp, sample);
 }
 
+/* BE: signed */
+static int32_t get_s16_be_i_sample (void *buf, int nch, int ch, int i) {
+  int16_t *tmp = (int16_t*)buf+i*nch+ch;
+  return (int16_t)SAD_GET_BE16(tmp);
+}
+
+static int32_t get_s16_be_s_sample (void *buf, int nch, int ch, int i) {
+  int16_t *tmp = ((int16_t**)buf)[ch]+i;
+  return (int16_t)SAD_GET_BE16(tmp);
+}
+
+static void put_s16_be_i_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int16_t *tmp = (int16_t*)buf+i*nch+ch;
+  SAD_PUT_BE16(tmp, sample);
+}
+
+static void put_s16_be_s_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int16_t *tmp = ((int16_t**)buf)[ch]+i;
+  SAD_PUT_BE16(tmp, sample);
+}
+
+/* LE: unsigned */
+static int32_t get_u16_le_i_sample (void *buf, int nch, int ch, int i) {
+  int16_t *tmp = (int16_t*)buf+i*nch+ch;
+  return (int16_t)SAD_GET_LE16(tmp) - 32768;
+}
+
+static int32_t get_u16_le_s_sample (void *buf, int nch, int ch, int i) {
+  int16_t *tmp = ((int16_t**)buf)[ch]+i;
+  return (int16_t)SAD_GET_LE16(tmp) - 32768;
+}
+
+static void put_u16_le_i_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int16_t *tmp = (int16_t*)buf+i*nch+ch;
+  SAD_PUT_LE16(tmp, sample + 32768);
+}
+
+static void put_u16_le_s_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int16_t *tmp = ((int16_t**)buf)[ch]+i;
+  SAD_PUT_LE16(tmp, sample + 32768);
+}
+
+/* BE: unsigned */
+static int32_t get_u16_be_i_sample (void *buf, int nch, int ch, int i) {
+  int16_t *tmp = (int16_t*)buf+i*nch+ch;
+  return (int16_t)SAD_GET_BE16(tmp) - 32768;
+}
+
+static int32_t get_u16_be_s_sample (void *buf, int nch, int ch, int i) {
+  int16_t *tmp = ((int16_t**)buf)[ch]+i;
+  return (int16_t)SAD_GET_BE16(tmp) - 32768;
+}
+
+static void put_u16_be_i_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int16_t *tmp = (int16_t*)buf+i*nch+ch;
+  SAD_PUT_BE16(tmp, sample + 32768);
+}
+
+static void put_u16_be_s_sample (void *buf, int32_t sample, int nch, int ch, int i) {
+  int16_t *tmp = ((int16_t**)buf)[ch]+i;
+  SAD_PUT_BE16(tmp, sample + 32768);
+}
+
+
 static SAD_buffer_ops buf_s16_i_ops = {
   &get_s16_i_sample,
   &put_s16_i_sample
@@ -173,6 +237,18 @@
   &put_s16_le_s_sample
 };
 
+static SAD_buffer_ops buf_s16_be_i_ops = {
+  &get_s16_be_i_sample,
+  &put_s16_be_i_sample
+};
+
+static SAD_buffer_ops buf_s16_be_s_ops = {
+  &get_s16_be_s_sample,
+  &put_s16_be_s_sample
+};
+
+/* unsigned */
+
 static SAD_buffer_ops buf_u16_i_ops = {
   &get_u16_i_sample,
   &put_u16_i_sample
@@ -183,6 +259,26 @@
   &put_u16_s_sample
 };
 
+static SAD_buffer_ops buf_u16_le_i_ops = {
+  &get_u16_le_i_sample,
+  &put_u16_le_i_sample
+};
+
+static SAD_buffer_ops buf_u16_le_s_ops = {
+  &get_u16_le_s_sample,
+  &put_u16_le_s_sample
+};
+
+static SAD_buffer_ops buf_u16_be_i_ops = {
+  &get_u16_be_i_sample,
+  &put_u16_be_i_sample
+};
+
+static SAD_buffer_ops buf_u16_be_s_ops = {
+  &get_u16_be_s_sample,
+  &put_u16_be_s_sample
+};
+
 /**************************************************************************************************************** 
  * 24-bit                                                                                                       *
  ****************************************************************************************************************/
@@ -305,25 +401,30 @@
 static SAD_buffer_ops *SAD_buffer_optable[SAD_SAMPLE_MAX][SAD_CHORDER_MAX] = {
   {&buf_s8_i_ops,     &buf_s8_s_ops},	  /* SAD_SAMPLE_S8     */
   {&buf_u8_i_ops,     &buf_u8_s_ops},	  /* SAD_SAMPLE_U8     */
+
   {&buf_s16_i_ops,    &buf_s16_s_ops},	  /* SAD_SAMPLE_S16    */
   {&buf_s16_le_i_ops, &buf_s16_le_s_ops}, /* SAD_SAMPLE_S16_LE */
-  {NULL,              NULL},		  /* SAD_SAMPLE_S16_BE */
+  {&buf_s16_be_i_ops, &buf_s16_be_s_ops}, /* SAD_SAMPLE_S16_BE */
   {&buf_u16_i_ops,    &buf_u16_s_ops},	  /* SAD_SAMPLE_U16    */
-  {NULL,              NULL}, 		  /* SAD_SAMPLE_U16_LE */
-  {NULL,              NULL}, 		  /* SAD_SAMPLE_U16_BE */
+  {&buf_u16_le_i_ops, &buf_u16_le_s_ops}, /* SAD_SAMPLE_U16_LE */
+  {&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_u24_i_ops,    &buf_u24_s_ops},	  /* SAD_SAMPLE_U24    */
   {NULL,              NULL}, 		  /* SAD_SAMPLE_U24_LE */
   {NULL,              NULL}, 		  /* SAD_SAMPLE_U24_BE */
+
   {&buf_s32_i_ops,    &buf_s32_s_ops}, 	  /* SAD_SAMPLE_S32    */
   {NULL,              NULL}, 		  /* SAD_SAMPLE_S32_LE */
   {NULL,              NULL}, 		  /* SAD_SAMPLE_S32_BE */
   {&buf_u32_i_ops,    &buf_u32_s_ops}, 	  /* SAD_SAMPLE_U32    */
   {NULL,              NULL}, 		  /* SAD_SAMPLE_U32_LE */
   {NULL,              NULL}, 		  /* SAD_SAMPLE_U32_BE */
+
   {&buf_s32_i_ops,    &buf_s32_s_ops}, 	  /* SAD_SAMPLE_FIXED32*/
+
   {NULL,              NULL}		  /* SAD_SAMPLE_FLOAT  */
 };