summaryrefslogtreecommitdiff
path: root/gnuradio-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-core/src')
-rw-r--r--gnuradio-core/src/lib/general/CMakeLists.txt1
-rw-r--r--gnuradio-core/src/lib/general/general.i2
-rw-r--r--gnuradio-core/src/lib/general/gr_tag_debug.cc100
-rw-r--r--gnuradio-core/src/lib/general/gr_tag_debug.h85
-rw-r--r--gnuradio-core/src/lib/general/gr_tag_debug.i35
-rw-r--r--gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t7
-rw-r--r--gnuradio-core/src/lib/io/gri_wavfile.cc136
-rw-r--r--gnuradio-core/src/lib/io/gri_wavfile.h27
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py43
9 files changed, 317 insertions, 119 deletions
diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt
index 399e07599..b671c963b 100644
--- a/gnuradio-core/src/lib/general/CMakeLists.txt
+++ b/gnuradio-core/src/lib/general/CMakeLists.txt
@@ -292,6 +292,7 @@ set(gr_core_general_triple_threats
gr_annotator_raw
gr_burst_tagger
gr_correlate_access_code_tag_bb
+ gr_tag_debug
)
foreach(file_tt ${gr_core_general_triple_threats})
diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i
index fe2cbdb82..c0ce65527 100644
--- a/gnuradio-core/src/lib/general/general.i
+++ b/gnuradio-core/src/lib/general/general.i
@@ -141,6 +141,7 @@
#include <gr_correlate_access_code_tag_bb.h>
#include <gr_add_ff.h>
#include <gr_vector_map.h>
+#include <gr_tag_debug.h>
%}
%include "gri_control_loop.i"
@@ -262,3 +263,4 @@
%include "gr_correlate_access_code_tag_bb.i"
%include "gr_add_ff.i"
%include "gr_vector_map.i"
+%include "gr_tag_debug.i"
diff --git a/gnuradio-core/src/lib/general/gr_tag_debug.cc b/gnuradio-core/src/lib/general/gr_tag_debug.cc
new file mode 100644
index 000000000..c4031f438
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_tag_debug.cc
@@ -0,0 +1,100 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_tag_debug.h>
+#include <gr_io_signature.h>
+#include <iostream>
+#include <iomanip>
+
+gr_tag_debug_sptr
+gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name)
+{
+ return gnuradio::get_initial_sptr
+ (new gr_tag_debug(sizeof_stream_item, name));
+}
+
+gr_tag_debug::gr_tag_debug(size_t sizeof_stream_item, const std::string &name)
+ : gr_sync_block("tag_debug",
+ gr_make_io_signature(1, -1, sizeof_stream_item),
+ gr_make_io_signature(0, 0, 0)),
+ d_name(name), d_display(true)
+{
+}
+
+std::vector<gr_tag_t>
+gr_tag_debug::current_tags()
+{
+ gruel::scoped_lock l(d_mutex);
+ return d_tags;
+}
+
+void
+gr_tag_debug::set_display(bool d)
+{
+ gruel::scoped_lock l(d_mutex);
+ d_display = d;
+}
+
+int
+gr_tag_debug::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ gruel::scoped_lock l(d_mutex);
+
+ if(d_display) {
+ std::cout << std::endl
+ << "----------------------------------------------------------------------";
+ std::cout << std::endl << "Tag Debug: " << d_name << std::endl;
+ }
+
+ uint64_t abs_N, end_N;
+ for(size_t i = 0; i < input_items.size(); i++) {
+ abs_N = nitems_read(i);
+ end_N = abs_N + (uint64_t)(noutput_items);
+
+ d_tags.clear();
+ get_tags_in_range(d_tags, i, abs_N, end_N);
+
+ if(d_display) {
+ std::cout << "Input Stream: " << i << std::endl;
+ for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++) {
+ std::cout << std::setw(10) << "Offset: " << d_tags_itr->offset
+ << std::setw(10) << "Source: " << pmt::pmt_symbol_to_string(d_tags_itr->srcid)
+ << std::setw(10) << "Key: " << pmt::pmt_symbol_to_string(d_tags_itr->key)
+ << std::setw(10) << "Value: ";
+ pmt::pmt_print(d_tags_itr->value);
+ }
+ }
+ }
+
+ if(d_display) {
+ std::cout << "----------------------------------------------------------------------";
+ std::cout << std::endl;
+ }
+
+ return noutput_items;
+}
diff --git a/gnuradio-core/src/lib/general/gr_tag_debug.h b/gnuradio-core/src/lib/general/gr_tag_debug.h
new file mode 100644
index 000000000..57578884a
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_tag_debug.h
@@ -0,0 +1,85 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_TAG_DEBUG_H
+#define INCLUDED_GR_TAG_DEBUG_H
+
+#include <gr_core_api.h>
+#include <gr_sync_block.h>
+#include <gruel/thread.h>
+#include <stddef.h>
+
+class gr_tag_debug;
+typedef boost::shared_ptr<gr_tag_debug> gr_tag_debug_sptr;
+
+GR_CORE_API gr_tag_debug_sptr
+gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name);
+
+/*!
+ * \brief Bit bucket that prints out any tag received.
+ * \ingroup sink_blk
+ *
+ * This block collects all tags sent to it on all input ports and
+ * displays them to stdout in a formatted way. The \p name parameter
+ * is used to identify which debug sink generated the tag, so when
+ * connecting a block to this debug sink, an appropriate name is
+ * something that identifies the input block.
+ *
+ * This block otherwise acts as a NULL sink in that items from the
+ * input stream are ignored. It is designed to be able to attach to
+ * any block and watch all tags streaming out of that block for
+ * debugging purposes.
+ *
+ * The tags from the last call to this work function are stored and
+ * can be retrieved using the function 'current_tags'.
+ */
+class GR_CORE_API gr_tag_debug : public gr_sync_block
+{
+ private:
+ friend GR_CORE_API gr_tag_debug_sptr
+ gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name);
+ gr_tag_debug(size_t sizeof_stream_item, const std::string &name);
+
+ std::string d_name;
+ std::vector<gr_tag_t> d_tags;
+ std::vector<gr_tag_t>::iterator d_tags_itr;
+ bool d_display;
+ gruel::mutex d_mutex;
+
+ public:
+ /*!
+ * \brief Returns a vector of gr_tag_t items as of the last call to
+ * work.
+ */
+ std::vector<gr_tag_t> current_tags();
+
+ /*!
+ * \brief Set the display of tags to stdout on/off.
+ */
+ void set_display(bool d);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_GR_TAG_DEBUG_H */
diff --git a/gnuradio-core/src/lib/general/gr_tag_debug.i b/gnuradio-core/src/lib/general/gr_tag_debug.i
new file mode 100644
index 000000000..3af1bdcfe
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_tag_debug.i
@@ -0,0 +1,35 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,tag_debug)
+
+%include <gr_tags.i>
+
+gr_tag_debug_sptr
+gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name);
+
+class gr_tag_debug : public gr_sync_block
+{
+public:
+ std::vector<gr_tag_t> current_tags();
+ void set_display(bool d);
+};
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 bdd0e810a..6959eac82 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 e316a0825..277e6b7b0 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,110 +27,45 @@
#include <gri_wavfile.h>
#include <cstring>
#include <stdint.h>
+#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
-
-// FIXME: Use libgruel versions
-
-#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);
-}
+// Basically, this is the opposite of htonx() and ntohx()
+// Define host to/from worknet (little endian) short and long
+#ifdef BOOST_BIG_ENDIAN
-static inline uint32_t
-wav_to_host(uint32_t x)
-{
- return bswap_32(x);
-}
+ static inline uint16_t __gri_wav_bs16(uint16_t x)
+ {
+ return (x>>8) | (x<<8);
+ }
-static inline uint16_t
-wav_to_host(uint16_t x)
-{
- return bswap_16(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)));
+ }
-static inline int16_t
-wav_to_host(int16_t x)
-{
- return bswap_16(x);
-}
+ #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,
@@ -225,12 +160,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;
+ int16_t buf_16bit;
- fresult = fread(&buf, bytes_per_sample, 1, fp);
-
- 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 c757be26b..16280e34a 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/gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py b/gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py
new file mode 100755
index 000000000..81babca04
--- /dev/null
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+#
+# Copyright 2012 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+from gnuradio import gr, gr_unittest
+
+class test_tag_debug(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_001(self):
+ # Just run some data through and make sure it doesn't puke.
+ src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ src = gr.vector_source_i(src_data)
+ op = gr.tag_debug(gr.sizeof_int, "tag QA")
+ self.tb.connect(src, op)
+ self.tb.run()
+ x = op.current_tags()
+
+if __name__ == '__main__':
+ gr_unittest.run(test_tag_debug, "test_tag_debug.xml")