diff options
-rw-r--r-- | gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t | 7 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gri_wavfile.cc | 118 | ||||
-rw-r--r-- | gnuradio-core/src/lib/io/gri_wavfile.h | 27 | ||||
-rw-r--r-- | gr-filter/lib/CMakeLists.txt | 2 | ||||
-rwxr-xr-x | gr-filter/python/qa_fft_filter.py | 6 | ||||
-rwxr-xr-x | gr-filter/python/qa_pfb_channelizer.py | 10 |
6 files changed, 45 insertions, 125 deletions
diff --git a/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t b/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t index bdd0e810a7..6959eac824 100644 --- a/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t +++ b/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t @@ -29,6 +29,7 @@ #include <algorithm> #include <gr_io_signature.h> #include <stdexcept> +#include <algorithm> #include <gr_complex.h> @@ -64,8 +65,7 @@ int case GR_CONST_WAVE: t = (gr_complex) d_ampl + d_offset; - for (int i = 0; i < noutput_items; i++) // FIXME unroll - optr[i] = t; + std::fill_n(optr, noutput_items, t); break; case GR_SIN_WAVE: @@ -142,8 +142,7 @@ int case GR_CONST_WAVE: t = (@TYPE@) d_ampl + d_offset; - for (int i = 0; i < noutput_items; i++) // FIXME unroll - optr[i] = t; + std::fill_n(optr, noutput_items, t); break; case GR_SIN_WAVE: diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index e316a08254..3bc9d8fad5 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -27,107 +27,30 @@ #include <gri_wavfile.h> #include <cstring> #include <stdint.h> +#include <gruel/inet.h> # 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 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); } #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); } diff --git a/gnuradio-core/src/lib/io/gri_wavfile.h b/gnuradio-core/src/lib/io/gri_wavfile.h index c757be26bc..16280e34a9 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.h +++ b/gnuradio-core/src/lib/io/gri_wavfile.h @@ -29,20 +29,15 @@ /*! * \brief Read signal information from a given WAV file. * - * \p fp File pointer to an opened, empty file. - * \p sample_rate Stores the sample rate [S/s] - * \p nchans Number of channels - * \p bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding to - * 8 or 16 bit samples, respectively) - * \p first_sample_pos Number of the first byte containing a sample. Use this - * with fseek() to jump from the end of the file to the first sample - * when in repeat mode. - * \p samples_per_chan Number of samples per channel - * \p normalize_fac The normalization factor with which you need to divide the - * integer values of the samples to get them within [-1;1] - * \p normalize_shift The value by which the sample values need to be shifted - * after normalization (reason being, 8-bit WAV files store samples as - * unsigned char and 16-bit as signed short int) + * \param[in] fp File pointer to an opened, empty file. + * \param[out] sample_rate Stores the sample rate [S/s] + * \param[out] nchans Number of channels + * \param[out] bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding o + * 8 or 16 bit samples, respectively) + * \param[out] first_sample_pos Number of the first byte containing a sample. Use this + * with fseek() to jump from the end of the file to the + * first sample when in repeat mode. + * \param[out] samples_per_chan Number of samples per channel * \return True on a successful read, false if the file could not be read or is * not a valid WAV file. */ @@ -94,8 +89,8 @@ gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample); * shouldn't happen), you need to fseek() to the end of the file (or * whereever). * - * \p fp File pointer to an open WAV file with a blank header - * \p byte_count Length of all samples written to the file in bytes. + * \param[in] fp File pointer to an open WAV file with a blank header + * \param[in] byte_count Length of all samples written to the file in bytes. */ bool gri_wavheader_complete(FILE *fp, unsigned int byte_count); diff --git a/gr-filter/lib/CMakeLists.txt b/gr-filter/lib/CMakeLists.txt index a54cd7b1da..048a948e6a 100644 --- a/gr-filter/lib/CMakeLists.txt +++ b/gr-filter/lib/CMakeLists.txt @@ -142,9 +142,9 @@ list(APPEND filter_sources list(APPEND filter_libs gnuradio-core gnuradio-fft + volk ${Boost_LIBRARIES} ${FFTW3F_LIBRARIES} - ${VOLK_LIBRARIES} ) add_library(gnuradio-filter SHARED ${filter_sources}) diff --git a/gr-filter/python/qa_fft_filter.py b/gr-filter/python/qa_fft_filter.py index eaef3156d8..cb5416373f 100755 --- a/gr-filter/python/qa_fft_filter.py +++ b/gr-filter/python/qa_fft_filter.py @@ -28,14 +28,14 @@ import random def make_random_complex_tuple(L): result = [] for x in range(L): - result.append(complex(random.uniform(-1000,1000), - random.uniform(-1000,1000))) + result.append(complex(2*random.random()-1, + 2*random.random()-1)) return tuple(result) def make_random_float_tuple(L): result = [] for x in range(L): - result.append(float(int(random.uniform(-1000,1000)))) + result.append(float(int(2*random.random()-1))) return tuple(result) diff --git a/gr-filter/python/qa_pfb_channelizer.py b/gr-filter/python/qa_pfb_channelizer.py index 33d2b2188c..3d35c46e44 100755 --- a/gr-filter/python/qa_pfb_channelizer.py +++ b/gr-filter/python/qa_pfb_channelizer.py @@ -94,11 +94,11 @@ class test_pfb_channelizer(gr_unittest.TestCase): dst3_data = snks[3].data() dst4_data = snks[4].data() - self.assertComplexTuplesAlmostEqual(expected0_data[-Ntest:], dst0_data[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected1_data[-Ntest:], dst1_data[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected2_data[-Ntest:], dst2_data[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected3_data[-Ntest:], dst3_data[-Ntest:], 4) - self.assertComplexTuplesAlmostEqual(expected4_data[-Ntest:], dst4_data[-Ntest:], 4) + self.assertComplexTuplesAlmostEqual(expected0_data[-Ntest:], dst0_data[-Ntest:], 3) + self.assertComplexTuplesAlmostEqual(expected1_data[-Ntest:], dst1_data[-Ntest:], 3) + self.assertComplexTuplesAlmostEqual(expected2_data[-Ntest:], dst2_data[-Ntest:], 3) + self.assertComplexTuplesAlmostEqual(expected3_data[-Ntest:], dst3_data[-Ntest:], 3) + self.assertComplexTuplesAlmostEqual(expected4_data[-Ntest:], dst4_data[-Ntest:], 3) if __name__ == '__main__': gr_unittest.run(test_pfb_channelizer, "test_pfb_channelizer.xml") |