summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/io/gri_wavfile.cc
diff options
context:
space:
mode:
authorJosh Blum2012-06-28 17:55:34 -0700
committerJosh Blum2012-06-28 17:55:34 -0700
commit75fac1e1476578cd354a2cc586af23da88ce4b12 (patch)
tree78f221002962b241ff6459c287e0b3da425a44f9 /gnuradio-core/src/lib/io/gri_wavfile.cc
parentfeaa399ba51e8959e92cf9b73375db1c6b638b3f (diff)
downloadgnuradio-75fac1e1476578cd354a2cc586af23da88ce4b12.tar.gz
gnuradio-75fac1e1476578cd354a2cc586af23da88ce4b12.tar.bz2
gnuradio-75fac1e1476578cd354a2cc586af23da88ce4b12.zip
core: fix for gri wave byteswapping
Sorry guys, I misunderstood the comments. Wave data is specifically in little endian format. Therefore we should only be swapping on big endian machines. Since systems only provide network endian macros: The following commit provides a cross platform byteswap and macros for host to/from worknet short and long.
Diffstat (limited to 'gnuradio-core/src/lib/io/gri_wavfile.cc')
-rw-r--r--gnuradio-core/src/lib/io/gri_wavfile.cc46
1 files changed, 29 insertions, 17 deletions
diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc
index 780bd1b98..277e6b7b0 100644
--- a/gnuradio-core/src/lib/io/gri_wavfile.cc
+++ b/gnuradio-core/src/lib/io/gri_wavfile.cc
@@ -27,33 +27,45 @@
#include <gri_wavfile.h>
#include <cstring>
#include <stdint.h>
-#include <boost/asio.hpp>
+#include <boost/detail/endian.hpp> //BOOST_BIG_ENDIAN
# define VALID_COMPRESSION_TYPE 0x0001
-// WAV files are always little-endian, so we need some byte switching macros
-
// Basically, this is the opposite of htonx() and ntohx()
-#ifdef WORDS_BIGENDIAN
+// Define host to/from worknet (little endian) short and long
+#ifdef BOOST_BIG_ENDIAN
+
+ static inline uint16_t __gri_wav_bs16(uint16_t x)
+ {
+ return (x>>8) | (x<<8);
+ }
-static inline uint32_t host_to_wav(uint32_t x) { return htonl(x); }
-static inline uint16_t host_to_wav(uint16_t x) { return htons(x); }
-static inline int16_t host_to_wav(int16_t x) { return htons(x); }
-static inline uint32_t wav_to_host(uint32_t x) { return ntohl(x); }
-static inline uint16_t wav_to_host(uint16_t x) { return ntohs(x); }
-static inline int16_t wav_to_host(int16_t x) { return ntohs(x); }
+ static inline uint32_t __gri_wav_bs32(uint32_t x)
+ {
+ return (uint32_t(__gri_wav_bs16(uint16_t(x&0xfffful)))<<16) | (__gri_wav_bs16(uint16_t(x>>16)));
+ }
+
+ #define htowl(x) __gri_wav_bs32(x)
+ #define wtohl(x) __gri_wav_bs32(x)
+ #define htows(x) __gri_wav_bs16(x)
+ #define wtohs(x) __gri_wav_bs16(x)
#else
-static inline uint32_t host_to_wav(uint32_t x) { return x; }
-static inline uint16_t host_to_wav(uint16_t x) { return x; }
-static inline int16_t host_to_wav(int16_t x) { return x; }
-static inline uint32_t wav_to_host(uint32_t x) { return x; }
-static inline uint16_t wav_to_host(uint16_t x) { return x; }
-static inline int16_t wav_to_host(int16_t x) { return x; }
+ #define htowl(x) uint32_t(x)
+ #define wtohl(x) uint32_t(x)
+ #define htows(x) uint16_t(x)
+ #define wtohs(x) uint16_t(x)
-#endif // WORDS_BIGENDIAN
+#endif // BOOST_BIG_ENDIAN
+// WAV files are always little-endian, so we need some byte switching macros
+static inline uint32_t host_to_wav(uint32_t x) { return htowl(x); }
+static inline uint16_t host_to_wav(uint16_t x) { return htows(x); }
+static inline int16_t host_to_wav(int16_t x) { return htows(x); }
+static inline uint32_t wav_to_host(uint32_t x) { return wtohl(x); }
+static inline uint16_t wav_to_host(uint16_t x) { return wtohs(x); }
+static inline int16_t wav_to_host(int16_t x) { return wtohs(x); }
bool
gri_wavheader_parse(FILE *fp,