diff options
author | Johnathan Corgan | 2012-06-22 15:08:04 -0700 |
---|---|---|
committer | Johnathan Corgan | 2012-06-22 15:08:04 -0700 |
commit | 6e0626fd93b99eab2234fba79fc0174261ea67f4 (patch) | |
tree | aedd86a26944292a4b08c43201b47db8eb0d6674 /gnuradio-core/src/lib/io/gri_wavfile.cc | |
parent | 2036030273d1c4842670ca3b2bd96e72aa408c9e (diff) | |
parent | 82f6a4ee66ce37b67a62af8924b1727e77c68816 (diff) | |
download | gnuradio-6e0626fd93b99eab2234fba79fc0174261ea67f4.tar.gz gnuradio-6e0626fd93b99eab2234fba79fc0174261ea67f4.tar.bz2 gnuradio-6e0626fd93b99eab2234fba79fc0174261ea67f4.zip |
Merge branch 'master' into wip/gr-blocks-master
Diffstat (limited to 'gnuradio-core/src/lib/io/gri_wavfile.cc')
-rw-r--r-- | gnuradio-core/src/lib/io/gri_wavfile.cc | 120 |
1 files changed, 23 insertions, 97 deletions
diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index e316a0825..780bd1b98 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,107 +27,30 @@ #include <gri_wavfile.h> #include <cstring> #include <stdint.h> +#include <boost/asio.hpp> # define VALID_COMPRESSION_TYPE 0x0001 // WAV files are always little-endian, so we need some byte switching macros -// FIXME: Use libgruel versions - +// Basically, this is the opposite of htonx() and ntohx() #ifdef WORDS_BIGENDIAN -#ifdef HAVE_BYTESWAP_H -#include <byteswap.h> -#else -#warning Using non-portable code (likely wrong other than ILP32). - -static inline short int -bswap_16 (unsigned short int x) -{ - return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); -} - -static inline unsigned int -bswap_32 (unsigned int x) -{ - return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ - | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); -} -#endif // HAVE_BYTESWAP_H - -static inline uint32_t -host_to_wav(uint32_t x) -{ - return bswap_32(x); -} - -static inline uint16_t -host_to_wav(uint16_t x) -{ - return bswap_16(x); -} - -static inline int16_t -host_to_wav(int16_t x) -{ - return bswap_16(x); -} - -static inline uint32_t -wav_to_host(uint32_t x) -{ - return bswap_32(x); -} - -static inline uint16_t -wav_to_host(uint16_t x) -{ - return bswap_16(x); -} - -static inline int16_t -wav_to_host(int16_t x) -{ - return bswap_16(x); -} +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); } #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; -} +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; } #endif // WORDS_BIGENDIAN @@ -225,12 +148,15 @@ gri_wavheader_parse(FILE *fp, short int gri_wav_read_sample(FILE *fp, int bytes_per_sample) { - int16_t buf = 0; - size_t fresult; - - fresult = fread(&buf, bytes_per_sample, 1, fp); + int16_t buf_16bit; - return (short) wav_to_host(buf); + if(!fread(&buf_16bit, bytes_per_sample, 1, fp)) { + return 0; + } + if(bytes_per_sample == 1) { + return (short) buf_16bit; + } + return (short)wav_to_host(buf_16bit); } |