summaryrefslogtreecommitdiff
path: root/gr-blocks/include
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2013-03-09 09:35:07 -0500
committerTom Rondeau <trondeau@vt.edu>2013-03-09 09:35:07 -0500
commit21c95a82a495f0cf9dfe511f9ef370bae9ac0eeb (patch)
treeae8b5808eb5b03495c3758baf5bb4ab679c68a7a /gr-blocks/include
parent4389b769891283face9aa397bd4d736f478e97e4 (diff)
blocks: moved tagged_file_sink and wavfile source/sink/base to gr-blocks.
Diffstat (limited to 'gr-blocks/include')
-rw-r--r--gr-blocks/include/blocks/CMakeLists.txt4
-rw-r--r--gr-blocks/include/blocks/tagged_file_sink.h65
-rw-r--r--gr-blocks/include/blocks/wavfile.h101
-rw-r--r--gr-blocks/include/blocks/wavfile_sink.h87
-rw-r--r--gr-blocks/include/blocks/wavfile_source.h70
5 files changed, 327 insertions, 0 deletions
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 8ffbdf0b19..d5f1448b45 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -106,6 +106,7 @@ install(FILES
log2_const.h
nco.h
vco.h
+ wavfile.h
add_ff.h
bin_statistics_f.h
burst_tagger.h
@@ -164,6 +165,7 @@ install(FILES
streams_to_vector.h
stretch_ff.h
tag_debug.h
+ tagged_file_sink.h
tagged_stream_to_pdu.h
threshold_ff.h
throttle.h
@@ -174,6 +176,8 @@ install(FILES
vco_f.h
vector_to_stream.h
vector_to_streams.h
+ wavfile_sink.h
+ wavfile_source.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
)
diff --git a/gr-blocks/include/blocks/tagged_file_sink.h b/gr-blocks/include/blocks/tagged_file_sink.h
new file mode 100644
index 0000000000..62da72f789
--- /dev/null
+++ b/gr-blocks/include/blocks/tagged_file_sink.h
@@ -0,0 +1,65 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2010,2013 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 <blocks/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief A file sink that uses tags to save files.
+ * \ingroup sink_blk
+ *
+ * The sink uses a tag with the key 'burst' to trigger the saving
+ * of the burst data to a new file. If the value of this tag is
+ * True, it will open a new file and start writing all incoming
+ * data to it. If the tag is False, it will close the file (if
+ * already opened). The file names are based on the time when the
+ * burst tag was seen. If there is an 'rx_time' tag (standard with
+ * UHD sources), that is used as the time. If no 'rx_time' tag is
+ * found, the new time is calculated based off the sample rate of
+ * the block.
+ */
+ class BLOCKS_API tagged_file_sink : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::tagged_file_sink::sptr
+ typedef boost::shared_ptr<tagged_file_sink> sptr;
+
+ /*!
+ * \brief Build a tagged_file_sink block.
+ *
+ * \param itemsize The item size of the input data stream.
+ * \param samp_rate The sample rate used to determine the time
+ * difference between bursts
+ */
+ static sptr make(size_t itemsize, double samp_rate);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_TAGGED_FILE_SINK_H */
diff --git a/gr-blocks/include/blocks/wavfile.h b/gr-blocks/include/blocks/wavfile.h
new file mode 100644
index 0000000000..690f8fc22a
--- /dev/null
+++ b/gr-blocks/include/blocks/wavfile.h
@@ -0,0 +1,101 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2013 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.
+ */
+
+// This file stores all the RIFF file type knowledge for the gr_wavfile_*
+// blocks.
+
+#include <blocks/api.h>
+#include <cstdio>
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Read signal information from a given WAV file.
+ *
+ * \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.
+ */
+ bool
+ wavheader_parse(FILE *fp,
+ unsigned int &sample_rate,
+ int &nchans,
+ int &bytes_per_sample,
+ int &first_sample_pos,
+ unsigned int &samples_per_chan);
+
+ /*!
+ * \brief Read one sample from an open WAV file at the current position.
+ *
+ * Takes care of endianness.
+ */
+ short int
+ wav_read_sample(FILE *fp, int bytes_per_sample);
+
+
+ /*!
+ * \brief Write a valid RIFF file header
+ *
+ * Note: Some header values are kept blank because they're usually
+ * not known a-priori (file and chunk lengths). Use
+ * gri_wavheader_complete() to fill these in.
+ */
+ bool
+ wavheader_write(FILE *fp,
+ unsigned int sample_rate,
+ int nchans,
+ int bytes_per_sample);
+
+ /*!
+ * \brief Write one sample to an open WAV file at the current position.
+ *
+ * Takes care of endianness.
+ */
+ void
+ wav_write_sample(FILE *fp, short int sample, int bytes_per_sample);
+
+
+ /*!
+ * \brief Complete a WAV header
+ *
+ * Note: The stream position is changed during this function. If
+ * anything needs to be written to the WAV file after calling this
+ * function (which shouldn't happen), you need to fseek() to the
+ * end of the file (or whereever).
+ *
+ * \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
+ wavheader_complete(FILE *fp, unsigned int byte_count);
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/include/blocks/wavfile_sink.h b/gr-blocks/include/blocks/wavfile_sink.h
new file mode 100644
index 0000000000..b095191d07
--- /dev/null
+++ b/gr-blocks/include/blocks/wavfile_sink.h
@@ -0,0 +1,87 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2009,2013 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_WAVFILE_SINK_H
+#define INCLUDED_GR_WAVFILE_SINK_H
+
+#include <blocks/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Write stream to a Microsoft PCM (.wav) file.
+ *
+ * Values must be floats within [-1;1].
+ * Check gr_make_wavfile_sink() for extra info.
+ *
+ * \ingroup sink_blk
+ */
+ class BLOCKS_API wavfile_sink : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::wavfile_sink::sptr
+ typedef boost::shared_ptr<wavfile_sink> sptr;
+
+ /*
+ * \p filename The .wav file to be opened
+ * \p n_channels Number of channels (2 = stereo or I/Q output)
+ * \p sample_rate Sample rate [S/s]
+ * \p bits_per_sample 16 or 8 bit, default is 16
+ */
+ static sptr make(const char *filename,
+ int n_channels,
+ unsigned int sample_rate,
+ int bits_per_sample = 16);
+
+ /*!
+ * \brief Opens a new file and writes a WAV header. Thread-safe.
+ */
+ virtual bool open(const char* filename) = 0;
+
+ /*!
+ * \brief Closes the currently active file and completes the WAV
+ * header. Thread-safe.
+ */
+ virtual void close() = 0;
+
+ /*!
+ * \brief Set the sample rate. This will not affect the WAV file
+ * currently opened. Any following open() calls will use this new
+ * sample rate.
+ */
+ virtual void set_sample_rate(unsigned int sample_rate) = 0;
+
+ /*!
+ * \brief Set bits per sample. This will not affect the WAV file
+ * currently opened (see set_sample_rate()). If the value is
+ * neither 8 nor 16, the call is ignored and the current value
+ * is kept.
+ */
+ virtual void set_bits_per_sample(int bits_per_sample) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_WAVFILE_SINK_H */
diff --git a/gr-blocks/include/blocks/wavfile_source.h b/gr-blocks/include/blocks/wavfile_source.h
new file mode 100644
index 0000000000..46cb82b698
--- /dev/null
+++ b/gr-blocks/include/blocks/wavfile_source.h
@@ -0,0 +1,70 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2008,2013 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_WAVFILE_SOURCE_H
+#define INCLUDED_GR_WAVFILE_SOURCE_H
+
+#include <blocks/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Read stream from a Microsoft PCM (.wav) file, output floats
+ *
+ * Unless otherwise called, values are within [-1;1].
+ * Check gr_make_wavfile_source() for extra info.
+ *
+ * \ingroup source_blk
+ */
+ class BLOCKS_API wavfile_source : virtual public gr_sync_block
+ {
+ public:
+ // gr::blocks::wavfile_source::sptr
+ typedef boost::shared_ptr<wavfile_source> sptr;
+
+ static sptr make(const char *filename, bool repeat = false);
+
+ /*!
+ * \brief Read the sample rate as specified in the wav file header
+ */
+ virtual unsigned int sample_rate() const = 0;
+
+ /*!
+ * \brief Return the number of bits per sample as specified in
+ * the wav file header. Only 8 or 16 bit are supported here.
+ */
+ virtual int bits_per_sample() const = 0;
+
+ /*!
+ * \brief Return the number of channels in the wav file as
+ * specified in the wav file header. This is also the max number
+ * of outputs you can have.
+ */
+ virtual int channels() const = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_WAVFILE_SOURCE_H */