summaryrefslogtreecommitdiff
path: root/gnuradio-core/src/lib/io
diff options
context:
space:
mode:
authorJohnathan Corgan2011-03-16 08:18:30 -0700
committerJohnathan Corgan2011-03-16 08:18:30 -0700
commit4cd06fadac972d4cac559c15488bc39823063afe (patch)
tree6fe57896bc216d8c9e672194f2e4e0e75aedb645 /gnuradio-core/src/lib/io
parent4ad736e21f45f64fd616bb53f54e45e1c63e7330 (diff)
parent1d70ed2bd928d52a383e688949cc7f747dd584fa (diff)
downloadgnuradio-4cd06fadac972d4cac559c15488bc39823063afe.tar.gz
gnuradio-4cd06fadac972d4cac559c15488bc39823063afe.tar.bz2
gnuradio-4cd06fadac972d4cac559c15488bc39823063afe.zip
Merge remote branch 'gnuradio/next'
* gnuradio/next: (806 commits) gruel: added missing ignores gruel: fixed swig interface file to dereference pmt_t. qtgui: fix distcheck error gruel: fixing structure. Passes make check. gruel: SWIGing Gruel into Python to access PMTs. gnuradio-examples: add C++ audio examples using new gr-audio created gruel/attributes.h to house compiler specific attribute macros audio: remove obsoleted individual top-level components gr-audio: added README and default config fix volk: simplify the get new method for the aligned pool grc: moved all usrp1 and usrp2 stuff out of grc and into gr-usrp*/grc grc: swap store the subprocess object rather than the pid when executing qtgui: removed python directory that was added, never used uhd: use %ignore to hide warnings and fix errors Added/updated ignore files. Fixing gr_filter_design program to import from gnuradio Python package. audio: high prio for platform specific audio osx audio: added windows and osx audio source files audio: added config checks for other audios, added jack and port audio: make prefs look like old audio, removed old audio.py ...
Diffstat (limited to 'gnuradio-core/src/lib/io')
-rw-r--r--gnuradio-core/src/lib/io/Makefile.am11
-rw-r--r--gnuradio-core/src/lib/io/gr_histo_sink_f.cc5
-rw-r--r--gnuradio-core/src/lib/io/gr_message_source.i8
-rw-r--r--gnuradio-core/src/lib/io/gr_tagged_file_sink.cc212
-rw-r--r--gnuradio-core/src/lib/io/gr_tagged_file_sink.h70
-rw-r--r--gnuradio-core/src/lib/io/gr_tagged_file_sink.i35
-rw-r--r--gnuradio-core/src/lib/io/gr_wavfile_sink.cc5
-rw-r--r--gnuradio-core/src/lib/io/io.i3
8 files changed, 339 insertions, 10 deletions
diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am
index c52554645..442d5e3a9 100644
--- a/gnuradio-core/src/lib/io/Makefile.am
+++ b/gnuradio-core/src/lib/io/Makefile.am
@@ -56,7 +56,8 @@ libio_la_SOURCES = \
gr_udp_source.cc \
gr_wavfile_sink.cc \
gr_wavfile_source.cc \
- gri_wavfile.cc
+ gri_wavfile.cc \
+ gr_tagged_file_sink.cc
grinclude_HEADERS = \
gr_file_sink.h \
@@ -89,9 +90,9 @@ grinclude_HEADERS = \
gr_udp_source.h \
gr_wavfile_source.h \
gr_wavfile_sink.h \
- gri_wavfile.h
+ gri_wavfile.h \
+ gr_tagged_file_sink.h
-if PYTHON
swiginclude_HEADERS = \
io.i \
gr_file_sink.i \
@@ -111,5 +112,5 @@ swiginclude_HEADERS = \
gr_udp_sink.i \
gr_udp_source.i \
gr_wavfile_source.i \
- gr_wavfile_sink.i
-endif
+ gr_wavfile_sink.i \
+ gr_tagged_file_sink.i
diff --git a/gnuradio-core/src/lib/io/gr_histo_sink_f.cc b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc
index a37189c24..fc0c12ce6 100644
--- a/gnuradio-core/src/lib/io/gr_histo_sink_f.cc
+++ b/gnuradio-core/src/lib/io/gr_histo_sink_f.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2009,2010 Free Software Foundation, Inc.
+ * Copyright 2009,2010,2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -26,6 +26,7 @@
#include <gr_histo_sink_f.h>
#include <gr_io_signature.h>
+#include <boost/math/special_functions/round.hpp>
static float get_clean_num(float num){
if (num == 0) return 0;
@@ -101,7 +102,7 @@ gr_histo_sink_f::send_frame(void){
int index;
float bin_width = (maximum - minimum)/(d_num_bins-1);
for (unsigned int i = 0; i < d_sample_count; i++){
- index = round((d_samps[i] - minimum)/bin_width);
+ index = boost::math::iround((d_samps[i] - minimum)/bin_width);
/* ensure the index range in case a small floating point error is involed */
if (index < 0) index = 0;
if (index >= (int)d_num_bins) index = d_num_bins-1;
diff --git a/gnuradio-core/src/lib/io/gr_message_source.i b/gnuradio-core/src/lib/io/gr_message_source.i
index 8a9c762d0..e4e2016d0 100644
--- a/gnuradio-core/src/lib/io/gr_message_source.i
+++ b/gnuradio-core/src/lib/io/gr_message_source.i
@@ -22,6 +22,14 @@
GR_SWIG_BLOCK_MAGIC(gr,message_source);
+#ifdef SWIGGUILE
+// Rename these. Without this, the primitive bindings are OK, but the
+// goops bindings try to create a bogus generic-function...
+// See core.scm for the second part of the workaround.
+%rename(message_source_limit_ctor) gr_make_message_source(size_t itemsize, int msgq_limit);
+%rename(message_source_msgq_ctor) gr_make_message_source(size_t itemsize, gr_msg_queue_sptr msgq);
+#endif
+
gr_message_source_sptr gr_make_message_source (size_t itemsize, int msgq_limit=0);
gr_message_source_sptr gr_make_message_source (size_t itemsize, gr_msg_queue_sptr msgq);
diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc
new file mode 100644
index 000000000..c76ede542
--- /dev/null
+++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc
@@ -0,0 +1,212 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2010 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_tagged_file_sink.h>
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+#include <iostream>
+#include <gr_tag_info.h>
+
+#ifdef O_BINARY
+#define OUR_O_BINARY O_BINARY
+#else
+#define OUR_O_BINARY 0
+#endif
+
+// should be handled via configure
+#ifdef O_LARGEFILE
+#define OUR_O_LARGEFILE O_LARGEFILE
+#else
+#define OUR_O_LARGEFILE 0
+#endif
+
+
+gr_tagged_file_sink::gr_tagged_file_sink (size_t itemsize, double samp_rate)
+ : gr_sync_block ("tagged_file_sink",
+ gr_make_io_signature (1, 1, itemsize),
+ gr_make_io_signature (0, 0, 0)),
+ d_itemsize (itemsize), d_n(0), d_sample_rate(samp_rate)
+{
+ d_state = NOT_IN_BURST;
+ d_last_N = 0;
+ d_timeval = 0;
+}
+
+gr_tagged_file_sink_sptr
+gr_make_tagged_file_sink (size_t itemsize, double samp_rate)
+{
+ return gnuradio::get_initial_sptr(new gr_tagged_file_sink (itemsize, samp_rate));
+}
+
+gr_tagged_file_sink::~gr_tagged_file_sink ()
+{
+}
+
+int
+gr_tagged_file_sink::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ char *inbuf = (char *) input_items[0];
+
+ uint64_t start_N = nitems_read(0);
+ uint64_t end_N = start_N + (uint64_t)(noutput_items);
+ pmt::pmt_t bkey = pmt::pmt_string_to_symbol("burst");
+ //pmt::pmt_t tkey = pmt::pmt_string_to_symbol("time"); // use gr_tags::key_time
+
+ std::vector<pmt::pmt_t> all_tags;
+ get_tags_in_range(all_tags, 0, start_N, end_N);
+
+ std::sort(all_tags.begin(), all_tags.end(), gr_tags::nitems_compare);
+
+ std::vector<pmt::pmt_t>::iterator vitr = all_tags.begin();
+
+ int idx = 0, idx_stop = 0;
+ while(idx < noutput_items) {
+ if(d_state == NOT_IN_BURST) {
+ while(vitr != all_tags.end()) {
+ if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) &&
+ pmt::pmt_is_true(gr_tags::get_value(*vitr))) {
+
+ uint64_t N = gr_tags::get_nitems(*vitr);
+ idx = (int)(N - start_N);
+
+ //std::cout << std::endl << "Found start of burst: "
+ // << idx << ", " << N << std::endl;
+
+ // Find time burst occurred by getting latest time tag and extrapolating
+ // to new time based on sample rate of this block.
+ std::vector<pmt::pmt_t> time_tags;
+ //get_tags_in_range(time_tags, 0, d_last_N, N, gr_tags::key_time);
+ get_tags_in_range(time_tags, 0, d_last_N, N,
+ pmt::pmt_string_to_symbol("time"));
+ if(time_tags.size() > 0) {
+ pmt::pmt_t tag = time_tags[time_tags.size()-1];
+
+ uint64_t time_nitems = gr_tags::get_nitems(tag);
+
+ // Get time based on last time tag from USRP
+ pmt::pmt_t time = gr_tags::get_value(tag);
+ int tsecs = pmt::pmt_to_long(pmt::pmt_tuple_ref(time, 0));
+ double tfrac = pmt::pmt_to_double(pmt::pmt_tuple_ref(time, 1));
+
+ // Get new time from last time tag + difference in time to when
+ // burst tag occured based on the sample rate
+ double delta = (double)(N - time_nitems) / d_sample_rate;
+ d_timeval = (double)tsecs + tfrac + delta;
+
+ //std::cout.setf(std::ios::fixed, std::ios::floatfield);
+ //std::cout.precision(8);
+ //std::cout << "Time found: " << (double)tsecs + tfrac << std::endl;
+ //std::cout << " time: " << d_timeval << std::endl;
+ //std::cout << " time at N = " << time_nitems << " burst N = " << N << std::endl;
+ }
+ else {
+ // if no time tag, use last seen tag and update time based on
+ // sample rate of the block
+ d_timeval += (double)(N - d_last_N) / d_sample_rate;
+ //std::cout << "Time not found" << std::endl;
+ //std::cout << " time: " << d_timeval << std::endl;
+ }
+ d_last_N = N;
+
+ std::stringstream filename;
+ filename.setf(std::ios::fixed, std::ios::floatfield);
+ filename.precision(8);
+ filename << "file" << d_n << "_" << d_timeval << ".dat";
+ d_n++;
+
+ int fd;
+ if ((fd = ::open (filename.str().c_str(),
+ O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY,
+ 0664)) < 0){
+ perror (filename.str().c_str());
+ return -1;
+ }
+
+ // FIXME:
+ //if ((d_handle = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL){
+ if ((d_handle = fdopen (fd, "wb")) == NULL){
+ perror (filename.str().c_str());
+ ::close(fd); // don't leak file descriptor if fdopen fails.
+ }
+
+ //std::cout << "Created new file: " << filename.str() << std::endl;
+
+ d_state = IN_BURST;
+ break;
+ }
+
+ vitr++;
+ }
+ if(d_state == NOT_IN_BURST)
+ return noutput_items;
+ }
+ else { // In burst
+ while(vitr != all_tags.end()) {
+ if((pmt::pmt_eqv(gr_tags::get_key(*vitr), bkey)) &&
+ pmt::pmt_is_false(gr_tags::get_value(*vitr))) {
+ uint64_t N = gr_tags::get_nitems(*vitr);
+ idx_stop = (int)N - start_N;
+
+ //std::cout << "Found end of burst: "
+ // << idx_stop << ", " << N << std::endl;
+
+ int count = fwrite (&inbuf[d_itemsize*idx], d_itemsize, idx_stop-idx, d_handle);
+ if (count == 0) {
+ if(ferror(d_handle)) {
+ perror("gr_tagged_file_sink: error writing file");
+ }
+ }
+ idx = idx_stop;
+ d_state = NOT_IN_BURST;
+ vitr++;
+ fclose(d_handle);
+ break;
+ }
+ else {
+ vitr++;
+ }
+ }
+ if(d_state == IN_BURST) {
+ int count = fwrite (&inbuf[idx], d_itemsize, noutput_items-idx, d_handle);
+ if (count == 0) {
+ if(ferror(d_handle)) {
+ perror("gr_tagged_file_sink: error writing file");
+ }
+ }
+ idx = noutput_items;
+ }
+ }
+ }
+
+ return noutput_items;
+}
diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h
new file mode 100644
index 000000000..956340f8d
--- /dev/null
+++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.h
@@ -0,0 +1,70 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2010 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_TAGGED_FILE_SINK_H
+#define INCLUDED_GR_TAGGED_FILE_SINK_H
+
+#include <gr_sync_block.h>
+
+class gr_tagged_file_sink;
+typedef boost::shared_ptr<gr_tagged_file_sink> gr_tagged_file_sink_sptr;
+
+gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize,
+ double samp_rate);
+
+/*!
+ * \brief Write stream to file descriptor.
+ * \ingroup sink_blk
+ */
+
+class gr_tagged_file_sink : public gr_sync_block
+{
+ friend gr_tagged_file_sink_sptr gr_make_tagged_file_sink (size_t itemsize,
+ double samp_rate);
+
+ private:
+ enum {
+ NOT_IN_BURST = 0,
+ IN_BURST
+ };
+
+ size_t d_itemsize;
+ int d_state;
+ FILE *d_handle;
+ int d_n;
+ double d_sample_rate;
+ uint64_t d_last_N;
+ double d_timeval;
+
+ protected:
+ gr_tagged_file_sink (size_t itemsize, double samp_rate);
+
+ public:
+ ~gr_tagged_file_sink ();
+
+ int work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+};
+
+
+#endif /* INCLUDED_GR_TAGGED_FILE_SINK_H */
diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i
new file mode 100644
index 000000000..1408adfc1
--- /dev/null
+++ b/gnuradio-core/src/lib/io/gr_tagged_file_sink.i
@@ -0,0 +1,35 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2010 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,tagged_file_sink)
+
+gr_tagged_file_sink_sptr
+gr_make_tagged_file_sink (size_t itemsize, double samp_rate);
+
+class gr_tagged_file_sink : public gr_sync_block
+{
+ protected:
+ gr_tagged_file_sink (size_t itemsize, double samp_rate);
+
+ public:
+ ~gr_tagged_file_sink ();
+};
diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc
index b60a6e3ab..a96aadc72 100644
--- a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc
+++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2004,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
+ * Copyright 2004,2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -33,6 +33,7 @@
#include <cmath>
#include <fcntl.h>
#include <gruel/thread.h>
+#include <boost/math/special_functions/round.hpp>
// win32 (mingw/msvc) specific
#ifdef HAVE_IO_H
@@ -224,7 +225,7 @@ gr_wavfile_sink::convert_to_short(float sample)
sample = d_min_sample_val;
}
- return (short int) roundf(sample);
+ return (short int) boost::math::iround(sample);
}
diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i
index 3538942ca..365577cd4 100644
--- a/gnuradio-core/src/lib/io/io.i
+++ b/gnuradio-core/src/lib/io/io.i
@@ -43,7 +43,7 @@
#include <gr_udp_source.h>
#include <gr_wavfile_sink.h>
#include <gr_wavfile_source.h>
-
+#include <gr_tagged_file_sink.h>
%}
%include "gr_file_sink_base.i"
@@ -64,4 +64,5 @@
%include "gr_udp_source.i"
%include "gr_wavfile_sink.i"
%include "gr_wavfile_source.i"
+%include "gr_tagged_file_sink.i"