summaryrefslogtreecommitdiff
path: root/gr-blocks/include/gnuradio
diff options
context:
space:
mode:
authorRon Economos <w6rz@comcast.net>2020-06-23 14:40:40 -0700
committerMarcus Müller <marcus@hostalia.de>2020-09-01 23:26:30 +0200
commit18f64ba685cfc2533e2d7726aa43c524b007d97b (patch)
treeba7f4420cce2728ab9ccbd2c2471b851d41138fb /gr-blocks/include/gnuradio
parent028b2167d7c1a6e7c4eb428b1c6cdd5225add264 (diff)
gr-blocks: Transition the WAV sink and source blocks to libsndfile.
Compressed input and output with FLAC and Ogg Vorbis now supported.
Diffstat (limited to 'gr-blocks/include/gnuradio')
-rw-r--r--gr-blocks/include/gnuradio/blocks/wavfile.h90
-rw-r--r--gr-blocks/include/gnuradio/blocks/wavfile_sink.h8
2 files changed, 32 insertions, 66 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/wavfile.h b/gr-blocks/include/gnuradio/blocks/wavfile.h
index 9f21834947..578900bf30 100644
--- a/gr-blocks/include/gnuradio/blocks/wavfile.h
+++ b/gr-blocks/include/gnuradio/blocks/wavfile.h
@@ -14,93 +14,55 @@
#ifndef _GR_WAVFILE_H_
#define _GR_WAVFILE_H_
-#include <gnuradio/blocks/api.h>
#include <cstdio>
namespace gr {
namespace blocks {
-
//! WAV file header information.
struct wav_header_info {
- // TODO: refactor to use correct types (int16/32, etc.).
//! sample rate [S/s]
- unsigned sample_rate;
+ int sample_rate;
//! Number of channels
int nchans;
//! Bytes per sample
- /** Can either be 1 or 2 (corresponding to 8 or 16 bit samples, respectively) */
int bytes_per_sample;
- //! 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.
- */
- int first_sample_pos;
-
//! Number of samples per channel
- unsigned samples_per_chan;
-
- //! Size of DATA chunk
- unsigned data_chunk_size;
-};
-
-/*!
- * \brief Read signal information from a given WAV file.
- *
- * \param[in] fp File pointer to an opened, empty file.
- * \param[out] info Parsed information.
- * \return True on a successful read, false if the file could not be read or is
- * not a valid or incompatible WAV file.
- */
-BLOCKS_API bool wavheader_parse(FILE* fp, wav_header_info& info);
-
-/*!
- * \brief Read one sample from an open WAV file at the current position.
- *
- * \details
- * Takes care of endianness.
- */
-BLOCKS_API short int wav_read_sample(FILE* fp, int bytes_per_sample);
-
+ long long samples_per_chan;
-/*!
- * \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.
- */
-BLOCKS_API bool
-wavheader_write(FILE* fp, unsigned int sample_rate, int nchans, int bytes_per_sample);
+ //! sndfile format
+ int format;
-/*!
- * \brief Write one sample to an open WAV file at the current position.
- *
- * \details
- * Takes care of endianness.
- */
-BLOCKS_API void wav_write_sample(FILE* fp, short int sample, int bytes_per_sample);
+ //! sndfile format
+ int subformat;
+};
+enum wavfile_format_t {
+ FORMAT_WAV = 0x010000,
+ FORMAT_FLAC = 0x170000,
+ FORMAT_OGG = 0x200000,
+ FORMAT_RF64 = 0x220000,
+};
-/*!
- * \brief Complete a WAV header
- *
- * \details
- * 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 wherever).
- *
- * \param[in] fp File pointer to an open WAV file with a blank header
- * \param[in] first_sample_pos Position of the first sample in DATA chunk.
- */
-BLOCKS_API bool wavheader_complete(FILE* fp, unsigned first_sample_pos);
+enum wavfile_subformat_t {
+ FORMAT_PCM_S8 = 1,
+ FORMAT_PCM_16,
+ FORMAT_PCM_24,
+ FORMAT_PCM_32,
+ FORMAT_PCM_U8,
+ FORMAT_FLOAT,
+ FORMAT_DOUBLE,
+ FORMAT_VORBIS = 0x0060,
+};
} /* namespace blocks */
} /* namespace gr */
+typedef gr::blocks::wavfile_format_t wavfile_format_t;
+typedef gr::blocks::wavfile_subformat_t wavfile_subformat_t;
+
#endif /* _GR_WAVFILE_H_ */
diff --git a/gr-blocks/include/gnuradio/blocks/wavfile_sink.h b/gr-blocks/include/gnuradio/blocks/wavfile_sink.h
index 144f446cce..f228f06168 100644
--- a/gr-blocks/include/gnuradio/blocks/wavfile_sink.h
+++ b/gr-blocks/include/gnuradio/blocks/wavfile_sink.h
@@ -12,6 +12,7 @@
#define INCLUDED_GR_WAVFILE_SINK_H
#include <gnuradio/blocks/api.h>
+#include <gnuradio/blocks/wavfile.h>
#include <gnuradio/sync_block.h>
namespace gr {
@@ -35,12 +36,15 @@ public:
* \param filename The .wav file to be opened
* \param n_channels Number of channels (2 = stereo or I/Q output)
* \param sample_rate Sample rate [S/s]
- * \param bits_per_sample 16 or 8 bit, default is 16
+ * \param format Output format (WAV, FLAC, Ogg Vorbis, RF64)
+ * \param subformat Bits per sample
+ * \param append Append to existing file
*/
static sptr make(const char* filename,
int n_channels,
unsigned int sample_rate,
- int bits_per_sample = 16,
+ wavfile_format_t format,
+ wavfile_subformat_t subformat,
bool append = false);
/*!