[xiph-commits] r12898 - trunk/speex/src

jm at svn.xiph.org jm at svn.xiph.org
Sat Apr 28 06:30:23 PDT 2007


Author: jm
Date: 2007-04-28 06:30:22 -0700 (Sat, 28 Apr 2007)
New Revision: 12898

Modified:
   trunk/speex/src/wav_io.c
   trunk/speex/src/wav_io.h
Log:
Cleaned up the endianness conversion, making sure that 16-bit samples get
interpreted as signed ints after swapping bytes.


Modified: trunk/speex/src/wav_io.c
===================================================================
--- trunk/speex/src/wav_io.c	2007-04-27 23:39:58 UTC (rev 12897)
+++ trunk/speex/src/wav_io.c	2007-04-28 13:30:22 UTC (rev 12898)
@@ -37,40 +37,9 @@
 #include <stdio.h>
 #include <string.h>
 #include "speex/speex_types.h"
+#include "wav_io.h"
 
-static spx_uint32_t le_int(spx_uint32_t i)
-{
-   spx_uint32_t ret=i;
-#ifdef WORDS_BIGENDIAN
-   ret =  i>>24;
-   ret += (i>>8)&0x0000ff00;
-   ret += (i<<8)&0x00ff0000;
-   ret += (i<<24);
-#endif
-   return ret;
-}
 
-unsigned short be_short(unsigned short s)
-{
-   unsigned short ret=s;
-#ifndef WORDS_BIGENDIAN
-   ret =  s>>8;
-   ret += s<<8;
-#endif
-   return ret;
-}
-
-unsigned short le_short(unsigned short s)
-{
-   unsigned short ret=s;
-#ifdef WORDS_BIGENDIAN
-   ret =  s>>8;
-   ret += s<<8;
-#endif
-   return ret;
-}
-
-
 int read_wav_header(FILE *file, int *rate, int *channels, int *format, spx_int32_t *size)
 {
    char ch[5];

Modified: trunk/speex/src/wav_io.h
===================================================================
--- trunk/speex/src/wav_io.h	2007-04-27 23:39:58 UTC (rev 12897)
+++ trunk/speex/src/wav_io.h	2007-04-28 13:30:22 UTC (rev 12898)
@@ -35,10 +35,30 @@
 #include <stdio.h>
 #include "speex/speex_types.h"
 
-unsigned short be_short(unsigned short s);
-unsigned short le_short(unsigned short s);
-spx_uint32_t le_int(spx_uint32_t i);
+#ifdef WORDS_BIGENDIAN
+#define le_short(s) ((short) ((unsigned short) (s) << 8) | ((unsigned short) (s) >> 8))
+#define be_short(s) ((short) (s))
+#else
+#define le_short(s) ((short) (s))
+#define be_short(s) ((short) ((unsigned short) (s) << 8) | ((unsigned short) (s) >> 8))
+#endif 
 
+/** Convert little endian */
+static inline spx_int32_t le_int(spx_int32_t i)
+{
+#ifdef WORDS_BIGENDIAN
+   spx_uint32_t ui, ret;
+   ui = i;
+   ret =  ui>>24;
+   ret |= (ui>>8)&0x0000ff00;
+   ret |= (ui<<8)&0x00ff0000;
+   ret |= (ui<<24);
+   return ret;
+#else
+   return i;
+#endif
+}
+
 int read_wav_header(FILE *file, int *rate, int *channels, int *format, spx_int32_t *size);
 
 void write_wav_header(FILE *file, int rate, int channels, int format, int size);



More information about the commits mailing list