diff options
27 files changed, 17 insertions, 1645 deletions
diff --git a/docs/sphinx/source/gr/index.rst b/docs/sphinx/source/gr/index.rst index b1663a7e23..ebdaa6e00f 100644 --- a/docs/sphinx/source/gr/index.rst +++ b/docs/sphinx/source/gr/index.rst @@ -31,7 +31,6 @@ Signal Sources gnuradio.gr.file_descriptor_source gnuradio.gr.file_source gnuradio.gr.udp_source - gnuradio.gr.wavfile_source Signal Sinks ^^^^^^^^^^^^ @@ -52,7 +51,6 @@ Signal Sinks gnuradio.gr.histo_sink_f gnuradio.gr.oscope_sink_f gnuradio.gr.udp_sink - gnuradio.gr.wavfile_sink Information Coding and Decoding diff --git a/docs/sphinx/source/gr/sink_blk.rst b/docs/sphinx/source/gr/sink_blk.rst index 56b29efff9..fef7937742 100644 --- a/docs/sphinx/source/gr/sink_blk.rst +++ b/docs/sphinx/source/gr/sink_blk.rst @@ -14,4 +14,3 @@ gnuradio.gr: Signal Sinks .. autooldblock:: gnuradio.gr.histo_sink_f .. autooldblock:: gnuradio.gr.oscope_sink_f .. autooldblock:: gnuradio.gr.udp_sink -.. autooldblock:: gnuradio.gr.wavfile_sink diff --git a/docs/sphinx/source/gr/source_blk.rst b/docs/sphinx/source/gr/source_blk.rst index f3a1b4954f..5bbd4591ec 100644 --- a/docs/sphinx/source/gr/source_blk.rst +++ b/docs/sphinx/source/gr/source_blk.rst @@ -11,5 +11,4 @@ gnuradio.gr: Signal Sources .. autooldblock:: gnuradio.gr.file_descriptor_source .. autooldblock:: gnuradio.gr.file_source .. autooldblock:: gnuradio.gr.udp_source -.. autooldblock:: gnuradio.gr.wavfile_source diff --git a/gnuradio-core/src/examples/mp-sched/wfm_rcv_pll_to_wav.py b/gnuradio-core/src/examples/mp-sched/wfm_rcv_pll_to_wav.py index ac060c0cce..67dbc41960 100755 --- a/gnuradio-core/src/examples/mp-sched/wfm_rcv_pll_to_wav.py +++ b/gnuradio-core/src/examples/mp-sched/wfm_rcv_pll_to_wav.py @@ -80,7 +80,7 @@ class wfm_rx_block (gr.top_block): # wave file as final sink if 1: - sink = gr.wavfile_sink(output_filename, 2, int(audio_rate), 16) + sink = blocks.wavfile_sink(output_filename, 2, int(audio_rate), 16) else: sink = audio.sink (int (audio_rate), options.audio_output, diff --git a/gnuradio-core/src/lib/io/CMakeLists.txt b/gnuradio-core/src/lib/io/CMakeLists.txt index dc0ffe62b1..7d1572ca70 100644 --- a/gnuradio-core/src/lib/io/CMakeLists.txt +++ b/gnuradio-core/src/lib/io/CMakeLists.txt @@ -37,7 +37,6 @@ list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/microtune_4937.cc ${CMAKE_CURRENT_SOURCE_DIR}/microtune_xxxx.cc ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.cc - ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.cc ) ######################################################################## @@ -58,7 +57,6 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/microtune_eval_board_defs.h ${CMAKE_CURRENT_SOURCE_DIR}/microtune_xxxx.h ${CMAKE_CURRENT_SOURCE_DIR}/ppio_ppdev.h - ${CMAKE_CURRENT_SOURCE_DIR}/gri_wavfile.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio COMPONENT "core_devel" ) @@ -92,9 +90,6 @@ set(gr_core_io_triple_threats sdr_1000 gr_udp_sink gr_udp_source - gr_wavfile_source - gr_wavfile_sink - gr_tagged_file_sink ) foreach(file_tt ${gr_core_io_triple_threats}) diff --git a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc b/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc deleted file mode 100644 index 3288fcdd60..0000000000 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.cc +++ /dev/null @@ -1,229 +0,0 @@ -/* -*- 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 <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdexcept> -#include <iostream> - -#ifdef HAVE_IO_H -#include <io.h> -#endif - -#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::string_to_symbol("burst"); - pmt::pmt_t tkey = pmt::string_to_symbol("rx_time"); // use gr_tags::key_time - - std::vector<gr_tag_t> all_tags; - get_tags_in_range(all_tags, 0, start_N, end_N); - - std::sort(all_tags.begin(), all_tags.end(), gr_tag_t::offset_compare); - - std::vector<gr_tag_t>::iterator vitr = all_tags.begin(); - - // Look for a time tag and initialize d_timeval. - std::vector<gr_tag_t> time_tags_outer; - get_tags_in_range(time_tags_outer, 0, start_N, end_N, tkey); - if (time_tags_outer.size() > 0) { - const gr_tag_t tag = time_tags_outer[0]; - uint64_t offset = tag.offset; - pmt::pmt_t time = tag.value; - uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); - double tfrac = pmt::to_double(pmt::tuple_ref(time, 1)); - double delta = (double)offset / d_sample_rate; - d_timeval = (double)tsecs + tfrac + delta; - d_last_N = offset; - } - - int idx = 0, idx_stop = 0; - while(idx < noutput_items) { - if(d_state == NOT_IN_BURST) { - while(vitr != all_tags.end()) { - if((pmt::eqv((*vitr).key, bkey)) && - pmt::is_true((*vitr).value)) { - - uint64_t N = (*vitr).offset; - 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<gr_tag_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, tkey); - if(time_tags.size() > 0) { - const gr_tag_t tag = time_tags[time_tags.size()-1]; - - uint64_t time_nitems = tag.offset; - - // Get time based on last time tag from USRP - pmt::pmt_t time = tag.value; - uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); - double tfrac = pmt::to_double(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" << unique_id() << "_" << 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::eqv((*vitr).key, bkey)) && - pmt::is_false((*vitr).value)) { - uint64_t N = (*vitr).offset; - 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[d_itemsize*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 deleted file mode 100644 index d6f931a677..0000000000 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- 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_core_api.h> -#include <gr_sync_block.h> -#include <cstdio> // for FILE - -class gr_tagged_file_sink; -typedef boost::shared_ptr<gr_tagged_file_sink> gr_tagged_file_sink_sptr; - -GR_CORE_API 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_CORE_API gr_tagged_file_sink : public gr_sync_block -{ - friend GR_CORE_API 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 deleted file mode 100644 index 2f2596e122..0000000000 --- a/gnuradio-core/src/lib/io/gr_tagged_file_sink.i +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- 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 deleted file mode 100644 index 8526032f6d..0000000000 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc +++ /dev/null @@ -1,280 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2006,2007,2008,2009,2010,2011 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_wavfile_sink.h> -#include <gr_io_signature.h> -#include <gri_wavfile.h> -#include <stdexcept> -#include <climits> -#include <cstring> -#include <cmath> -#include <fcntl.h> -#include <gruel/thread.h> -#include <boost/math/special_functions/round.hpp> - -// win32 (mingw/msvc) specific -#ifdef HAVE_IO_H -#include <io.h> -#endif -#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_wavfile_sink_sptr -gr_make_wavfile_sink(const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample) -{ - return gnuradio::get_initial_sptr(new gr_wavfile_sink (filename, - n_channels, - sample_rate, - bits_per_sample)); -} - -gr_wavfile_sink::gr_wavfile_sink(const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample) - : gr_sync_block ("wavfile_sink", - gr_make_io_signature(1, n_channels, sizeof(float)), - gr_make_io_signature(0, 0, 0)), - d_sample_rate(sample_rate), d_nchans(n_channels), - d_fp(0), d_new_fp(0), d_updated(false) -{ - if (bits_per_sample != 8 && bits_per_sample != 16) { - throw std::runtime_error("Invalid bits per sample (supports 8 and 16)"); - } - d_bytes_per_sample = bits_per_sample / 8; - d_bytes_per_sample_new = d_bytes_per_sample; - - if (!open(filename)) { - throw std::runtime_error ("can't open file"); - } - - if (bits_per_sample == 8) { - d_max_sample_val = 0xFF; - d_min_sample_val = 0; - d_normalize_fac = d_max_sample_val/2; - d_normalize_shift = 1; - } else { - d_max_sample_val = 0x7FFF; - d_min_sample_val = -0x7FFF; - d_normalize_fac = d_max_sample_val; - d_normalize_shift = 0; - if (bits_per_sample != 16) { - fprintf(stderr, "Invalid bits per sample value requested, using 16"); - } - } -} - - -bool -gr_wavfile_sink::open(const char* filename) -{ - gruel::scoped_lock guard(d_mutex); - - // we use the open system call to get access to the O_LARGEFILE flag. - int fd; - if ((fd = ::open (filename, - O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY, - 0664)) < 0){ - perror (filename); - return false; - } - - if (d_new_fp) { // if we've already got a new one open, close it - fclose(d_new_fp); - d_new_fp = 0; - } - - if ((d_new_fp = fdopen (fd, "wb")) == NULL) { - perror (filename); - ::close(fd); // don't leak file descriptor if fdopen fails. - return false; - } - d_updated = true; - - if (!gri_wavheader_write(d_new_fp, - d_sample_rate, - d_nchans, - d_bytes_per_sample_new)) { - fprintf(stderr, "[%s] could not write to WAV file\n", __FILE__); - exit(-1); - } - - return true; -} - - -void -gr_wavfile_sink::close() -{ - gruel::scoped_lock guard(d_mutex); - - if (!d_fp) - return; - - close_wav(); -} - -void gr_wavfile_sink::close_wav() -{ - unsigned int byte_count = d_sample_count * d_bytes_per_sample; - - gri_wavheader_complete(d_fp, byte_count); - - fclose(d_fp); - d_fp = NULL; -} - - -gr_wavfile_sink::~gr_wavfile_sink () -{ - if (d_new_fp) { - fclose(d_new_fp); - } - - close(); -} - - -int -gr_wavfile_sink::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - float **in = (float **) &input_items[0]; - int n_in_chans = input_items.size(); - - short int sample_buf_s; - - int nwritten; - - gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block - do_update(); // update: d_fp is reqd - if (!d_fp) // drop output on the floor - return noutput_items; - - for (nwritten = 0; nwritten < noutput_items; nwritten++) { - for (int chan = 0; chan < d_nchans; chan++) { - // Write zeros to channels which are in the WAV file - // but don't have any inputs here - if (chan < n_in_chans) { - sample_buf_s = - convert_to_short(in[chan][nwritten]); - } else { - sample_buf_s = 0; - } - - gri_wav_write_sample(d_fp, sample_buf_s, d_bytes_per_sample); - - if (feof(d_fp) || ferror(d_fp)) { - fprintf(stderr, "[%s] file i/o error\n", __FILE__); - close(); - exit(-1); - } - d_sample_count++; - } - } - - return nwritten; -} - - -short int -gr_wavfile_sink::convert_to_short(float sample) -{ - sample += d_normalize_shift; - sample *= d_normalize_fac; - if (sample > d_max_sample_val) { - sample = d_max_sample_val; - } else if (sample < d_min_sample_val) { - sample = d_min_sample_val; - } - - return (short int) boost::math::iround(sample); -} - - -void -gr_wavfile_sink::set_bits_per_sample(int bits_per_sample) -{ - gruel::scoped_lock guard(d_mutex); - if (bits_per_sample == 8 || bits_per_sample == 16) { - d_bytes_per_sample_new = bits_per_sample / 8; - } -} - - -void -gr_wavfile_sink::set_sample_rate(unsigned int sample_rate) -{ - gruel::scoped_lock guard(d_mutex); - d_sample_rate = sample_rate; -} - - -void -gr_wavfile_sink::do_update() -{ - if (!d_updated) { - return; - } - - if (d_fp) { - close_wav(); - } - - d_fp = d_new_fp; // install new file pointer - d_new_fp = 0; - d_sample_count = 0; - d_bytes_per_sample = d_bytes_per_sample_new; - - if (d_bytes_per_sample == 1) { - d_max_sample_val = UCHAR_MAX; - d_min_sample_val = 0; - d_normalize_fac = d_max_sample_val/2; - d_normalize_shift = 1; - } else if (d_bytes_per_sample == 2) { - d_max_sample_val = SHRT_MAX; - d_min_sample_val = SHRT_MIN; - d_normalize_fac = d_max_sample_val; - d_normalize_shift = 0; - } - - d_updated = false; -} diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h deleted file mode 100644 index 162151b7a8..0000000000 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008,2009 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 <gr_core_api.h> -#include <gr_sync_block.h> -#include <gr_file_sink_base.h> -#include <boost/thread.hpp> - -class gr_wavfile_sink; -typedef boost::shared_ptr<gr_wavfile_sink> gr_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 - */ -GR_CORE_API gr_wavfile_sink_sptr -gr_make_wavfile_sink (const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample = 16); - -/*! - * \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 GR_CORE_API gr_wavfile_sink : public gr_sync_block -{ -private: - friend GR_CORE_API gr_wavfile_sink_sptr gr_make_wavfile_sink (const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample); - - gr_wavfile_sink(const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample); - - unsigned d_sample_rate; - int d_nchans; - unsigned d_sample_count; - int d_bytes_per_sample; - int d_bytes_per_sample_new; - int d_max_sample_val; - int d_min_sample_val; - int d_normalize_shift; - int d_normalize_fac; - - FILE *d_fp; - FILE *d_new_fp; - bool d_updated; - boost::mutex d_mutex; - - /*! - * \brief Convert a sample value within [-1;+1] to a corresponding - * short integer value - */ - short convert_to_short(float sample); - - /*! - * \brief If any file changes have occurred, update now. This is called - * internally by work() and thus doesn't usually need to be called by - * hand. - */ - void do_update(); - - /*! - * \brief Writes information to the WAV header which is not available - * a-priori (chunk size etc.) and closes the file. Not thread-safe and - * assumes d_fp is a valid file pointer, should thus only be called by - * other methods. - */ - void close_wav(); - -public: - ~gr_wavfile_sink (); - - /*! - * \brief Opens a new file and writes a WAV header. Thread-safe. - */ - bool open(const char* filename); - - /*! - * \brief Closes the currently active file and completes the WAV - * header. Thread-safe. - */ - void close(); - - /*! - * \brief Set the sample rate. This will not affect the WAV file - * currently opened. Any following open() calls will use this new - * sample rate. - */ - void set_sample_rate(unsigned int sample_rate); - - /*! - * \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. - */ - void set_bits_per_sample(int bits_per_sample); - - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - -}; - -#endif /* INCLUDED_GR_WAVFILE_SINK_H */ diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.i b/gnuradio-core/src/lib/io/gr_wavfile_sink.i deleted file mode 100644 index 48d1130bd2..0000000000 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.i +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008 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,wavfile_sink); - -gr_wavfile_sink_sptr -gr_make_wavfile_sink (const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample = 16) throw (std::runtime_error); - -class gr_wavfile_sink : public gr_sync_block -{ -protected: - gr_wavfile_sink(const char *filename, - int n_channels, - unsigned int sample_rate, - int bits_per_sample) throw (std::runtime_error); - -public: - ~gr_wavfile_sink (); - bool open(const char* filename); - void close(); - void set_sample_rate(unsigned int sample_rate); - void set_bits_per_sample(int bits_per_sample); -}; - diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.cc b/gnuradio-core/src/lib/io/gr_wavfile_source.cc deleted file mode 100644 index c8372868ba..0000000000 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.cc +++ /dev/null @@ -1,171 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2008,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_wavfile_source.h> -#include <gr_io_signature.h> -#include <gri_wavfile.h> -#include <sys/types.h> -#include <fcntl.h> -#include <stdexcept> - -// win32 (mingw/msvc) specific -#ifdef HAVE_IO_H -#include <io.h> -#endif -#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_wavfile_source_sptr -gr_make_wavfile_source (const char *filename, bool repeat) -{ - return gnuradio::get_initial_sptr(new gr_wavfile_source (filename, repeat)); -} - - -gr_wavfile_source::gr_wavfile_source (const char *filename, bool repeat) - : gr_sync_block ("wavfile_source", - gr_make_io_signature (0, 0, 0), - gr_make_io_signature (1, 2, sizeof(float))), - d_fp(NULL), d_repeat(repeat), - d_sample_rate(1), d_nchans(1), d_bytes_per_sample(2), d_first_sample_pos(0), - d_samples_per_chan(0), d_sample_idx(0) -{ - // we use "open" to use to the O_LARGEFILE flag - - int fd; - if ((fd = open (filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0) { - perror (filename); - throw std::runtime_error ("can't open file"); - } - - if ((d_fp = fdopen (fd, "rb")) == NULL) { - perror (filename); - throw std::runtime_error ("can't open file"); - } - - // Scan headers, check file validity - if (!gri_wavheader_parse(d_fp, - d_sample_rate, - d_nchans, - d_bytes_per_sample, - d_first_sample_pos, - d_samples_per_chan)) { - throw std::runtime_error("is not a valid wav file"); - } - - if (d_samples_per_chan == 0) { - throw std::runtime_error("WAV file does not contain any samples"); - } - - if (d_bytes_per_sample == 1) { - d_normalize_fac = 128; - d_normalize_shift = 1; - } else { - d_normalize_fac = 0x7FFF; - d_normalize_shift = 0; - } - - // Re-set the output signature - set_output_signature(gr_make_io_signature(1, d_nchans, sizeof(float))); -} - - -gr_wavfile_source::~gr_wavfile_source () -{ - fclose(d_fp); -} - - -int -gr_wavfile_source::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) -{ - float **out = (float **) &output_items[0]; - int n_out_chans = output_items.size(); - - int i; - short sample; - - for (i = 0; i < noutput_items; i++) { - if (d_sample_idx >= d_samples_per_chan) { - if (!d_repeat) { - // if nothing was read at all, say we're done. - return i ? i : -1; - } - - if (fseek (d_fp, d_first_sample_pos, SEEK_SET) == -1) { - fprintf(stderr, "[%s] fseek failed\n", __FILE__); - exit(-1); - } - - d_sample_idx = 0; - } - - for (int chan = 0; chan < d_nchans; chan++) { - sample = gri_wav_read_sample(d_fp, d_bytes_per_sample); - - if (chan < n_out_chans) { - out[chan][i] = convert_to_float(sample); - } - } - - d_sample_idx++; - - // OK, EOF is not necessarily an error. But we're not going to - // deal with handling corrupt wav files, so if they give us any - // trouble they won't be processed. Serves them bloody right. - if (feof(d_fp) || ferror(d_fp)) { - if (i == 0) { - fprintf(stderr, "[%s] WAV file has corrupted header or i/o error\n", __FILE__); - return -1; - } - return i; - } - } - - return noutput_items; -} - - -float -gr_wavfile_source::convert_to_float(short int sample) -{ - float sample_out = (float) sample; - sample_out /= d_normalize_fac; - sample_out -= d_normalize_shift; - return sample_out; -} diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.h b/gnuradio-core/src/lib/io/gr_wavfile_source.h deleted file mode 100644 index 02e6e36788..0000000000 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2008 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 <gr_core_api.h> -#include <gr_sync_block.h> -#include <cstdio> // for FILE - -class gr_wavfile_source; -typedef boost::shared_ptr<gr_wavfile_source> gr_wavfile_source_sptr; - -GR_CORE_API gr_wavfile_source_sptr -gr_make_wavfile_source (const char *filename, bool repeat = false); - -/*! - * \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 GR_CORE_API gr_wavfile_source : public gr_sync_block -{ -private: - friend GR_CORE_API gr_wavfile_source_sptr gr_make_wavfile_source (const char *filename, - bool repeat); - gr_wavfile_source(const char *filename, bool repeat); - - FILE *d_fp; - bool d_repeat; - - unsigned d_sample_rate; - int d_nchans; - int d_bytes_per_sample; - int d_first_sample_pos; - unsigned d_samples_per_chan; - unsigned d_sample_idx; - int d_normalize_shift; - int d_normalize_fac; - - /*! - * \brief Convert an integer sample value to a float value within [-1;1] - */ - float convert_to_float(short int sample); - -public: - ~gr_wavfile_source (); - - int work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); - - /*! - * \brief Read the sample rate as specified in the wav file header - */ - unsigned int sample_rate() const { return d_sample_rate; }; - - /*! - * \brief Return the number of bits per sample as specified in the wav - * file header. Only 8 or 16 bit are supported here. - */ - int bits_per_sample() const { return d_bytes_per_sample * 8; }; - - /*! - * \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. - */ - int channels() const { return d_nchans; }; -}; - -#endif /* INCLUDED_GR_WAVFILE_SOURCE_H */ diff --git a/gnuradio-core/src/lib/io/gr_wavfile_source.i b/gnuradio-core/src/lib/io/gr_wavfile_source.i deleted file mode 100644 index 5af2224f14..0000000000 --- a/gnuradio-core/src/lib/io/gr_wavfile_source.i +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008 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,wavfile_source); - -gr_wavfile_source_sptr -gr_make_wavfile_source (const char *filename, - bool repeat = false) throw (std::runtime_error); - -class gr_wavfile_source : public gr_sync_block -{ -private: - gr_wavfile_source(const char *filename, - bool repeat) throw (std::runtime_error); - -public: - ~gr_wavfile_source(); - - unsigned int sample_rate(); - int bits_per_sample(); - int channels(); -}; - diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc deleted file mode 100644 index 277e6b7b0e..0000000000 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ /dev/null @@ -1,251 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2008,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 <gri_wavfile.h> -#include <cstring> -#include <stdint.h> -#include <boost/detail/endian.hpp> //BOOST_BIG_ENDIAN - -# define VALID_COMPRESSION_TYPE 0x0001 - -// 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 uint16_t __gri_wav_bs16(uint16_t x) - { - return (x>>8) | (x<<8); - } - - 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))); - } - - #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 - - #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 // 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, - unsigned int &sample_rate_o, - int &nchans_o, - int &bytes_per_sample_o, - int &first_sample_pos_o, - unsigned int &samples_per_chan_o) -{ - // _o variables take return values - char str_buf[8] = {0}; - - uint32_t file_size; - uint32_t fmt_hdr_skip; - uint16_t compression_type; - uint16_t nchans; - uint32_t sample_rate; - uint32_t avg_bytes_per_sec; - uint16_t block_align; - uint16_t bits_per_sample; - uint32_t chunk_size; - - size_t fresult; - - fresult = fread(str_buf, 1, 4, fp); - if (fresult != 4 || strncmp(str_buf, "RIFF", 4) || feof(fp)) { - return false; - } - - fresult = fread(&file_size, 1, 4, fp); - - fresult = fread(str_buf, 1, 8, fp); - if (fresult != 8 || strncmp(str_buf, "WAVEfmt ", 8) || feof(fp)) { - return false; - } - - fresult = fread(&fmt_hdr_skip, 1, 4, fp); - - fresult = fread(&compression_type, 1, 2, fp); - if (wav_to_host(compression_type) != VALID_COMPRESSION_TYPE) { - return false; - } - - fresult = fread(&nchans, 1, 2, fp); - fresult = fread(&sample_rate, 1, 4, fp); - fresult = fread(&avg_bytes_per_sec, 1, 4, fp); - fresult = fread(&block_align, 1, 2, fp); - fresult = fread(&bits_per_sample, 1, 2, fp); - - if (ferror(fp)) { - return false; - } - - fmt_hdr_skip = wav_to_host(fmt_hdr_skip); - nchans = wav_to_host(nchans); - sample_rate = wav_to_host(sample_rate); - bits_per_sample = wav_to_host(bits_per_sample); - - if (bits_per_sample != 8 && bits_per_sample != 16) { - return false; - } - - fmt_hdr_skip -= 16; - if (fmt_hdr_skip) { - fseek(fp, fmt_hdr_skip, SEEK_CUR); - } - - // data chunk - fresult = fread(str_buf, 1, 4, fp); - if (strncmp(str_buf, "data", 4)) { - return false; - } - - fresult = fread(&chunk_size, 1, 4, fp); - if (ferror(fp)) { - return false; - } - - // More byte swapping - chunk_size = wav_to_host(chunk_size); - - // Output values - sample_rate_o = (unsigned) sample_rate; - nchans_o = (int) nchans; - bytes_per_sample_o = (int) (bits_per_sample / 8); - first_sample_pos_o = (int) ftell(fp); - samples_per_chan_o = (unsigned) (chunk_size / (bytes_per_sample_o * nchans)); - return true; -} - - -short int -gri_wav_read_sample(FILE *fp, int bytes_per_sample) -{ - int16_t buf_16bit; - - 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); -} - - -bool -gri_wavheader_write(FILE *fp, - unsigned int sample_rate, - int nchans, - int bytes_per_sample) -{ - const int header_len = 44; - char wav_hdr[header_len] = "RIFF\0\0\0\0WAVEfmt \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0data\0\0\0"; - uint16_t nchans_f = (uint16_t) nchans; - uint32_t sample_rate_f = (uint32_t) sample_rate; - uint16_t block_align = bytes_per_sample * nchans; - uint32_t avg_bytes = sample_rate * block_align; - uint16_t bits_per_sample = bytes_per_sample * 8; - - nchans_f = host_to_wav(nchans_f); - sample_rate_f = host_to_wav(sample_rate_f); - block_align = host_to_wav(block_align); - avg_bytes = host_to_wav(avg_bytes); - bits_per_sample = host_to_wav(bits_per_sample); - - wav_hdr[16] = 0x10; // no extra bytes - wav_hdr[20] = 0x01; // no compression - memcpy((void *) (wav_hdr + 22), (void *) &nchans_f, 2); - memcpy((void *) (wav_hdr + 24), (void *) &sample_rate_f, 4); - memcpy((void *) (wav_hdr + 28), (void *) &avg_bytes, 4); - memcpy((void *) (wav_hdr + 32), (void *) &block_align, 2); - memcpy((void *) (wav_hdr + 34), (void *) &bits_per_sample, 2); - - fwrite(&wav_hdr, 1, header_len, fp); - if (ferror(fp)) { - return false; - } - - return true; -} - - -void -gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample) -{ - void *data_ptr; - unsigned char buf_8bit; - int16_t buf_16bit; - - if (bytes_per_sample == 1) { - buf_8bit = (unsigned char) sample; - data_ptr = (void *) &buf_8bit; - } else { - buf_16bit = host_to_wav((int16_t) sample); - data_ptr = (void *) &buf_16bit; - } - - fwrite(data_ptr, 1, bytes_per_sample, fp); -} - - -bool -gri_wavheader_complete(FILE *fp, unsigned int byte_count) -{ - uint32_t chunk_size = (uint32_t) byte_count; - chunk_size = host_to_wav(chunk_size); - - fseek(fp, 40, SEEK_SET); - fwrite(&chunk_size, 1, 4, fp); - - chunk_size = (uint32_t) byte_count + 36; // fmt chunk and data header - chunk_size = host_to_wav(chunk_size); - fseek(fp, 4, SEEK_SET); - - fwrite(&chunk_size, 1, 4, fp); - - if (ferror(fp)) { - return false; - } - - return true; -} diff --git a/gnuradio-core/src/lib/io/gri_wavfile.h b/gnuradio-core/src/lib/io/gri_wavfile.h deleted file mode 100644 index 16280e34a9..0000000000 --- a/gnuradio-core/src/lib/io/gri_wavfile.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008 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 <gr_core_api.h> -#include <cstdio> - -/*! - * \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 -gri_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 -gri_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 -gri_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 -gri_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 -gri_wavheader_complete(FILE *fp, unsigned int byte_count); diff --git a/gnuradio-core/src/lib/io/io.i b/gnuradio-core/src/lib/io/io.i index be2ce99374..b1fcde6d15 100644 --- a/gnuradio-core/src/lib/io/io.i +++ b/gnuradio-core/src/lib/io/io.i @@ -39,9 +39,6 @@ #include <ppio.h> #include <gr_udp_sink.h> #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" @@ -58,8 +55,5 @@ %include "ppio.i" %include "gr_udp_sink.i" %include "gr_udp_source.i" -%include "gr_wavfile_sink.i" -%include "gr_wavfile_source.i" -%include "gr_tagged_file_sink.i" diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_wavefile.py b/gnuradio-core/src/python/gnuradio/gr/qa_wavefile.py deleted file mode 100755 index 3b9a3eb204..0000000000 --- a/gnuradio-core/src/python/gnuradio/gr/qa_wavefile.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2008,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. -# - -from gnuradio import gr, gr_unittest - -import os -from os.path import getsize - -g_in_file = os.path.join (os.getenv ("srcdir"), "test_16bit_1chunk.wav") - -class test_wavefile(gr_unittest.TestCase): - - def setUp (self): - self.tb = gr.top_block () - - def tearDown (self): - self.tb = None - - def test_001_checkwavread (self): - wf = gr.wavfile_source(g_in_file) - self.assertEqual(wf.sample_rate(), 8000) - - def test_002_checkwavcopy (self): - infile = g_in_file - outfile = "test_out.wav" - - wf_in = gr.wavfile_source(infile) - wf_out = gr.wavfile_sink(outfile, - wf_in.channels(), - wf_in.sample_rate(), - wf_in.bits_per_sample()) - self.tb.connect(wf_in, wf_out) - self.tb.run() - wf_out.close() - - self.assertEqual(getsize(infile), getsize(outfile)) - - in_f = file(infile, 'rb') - out_f = file(outfile, 'rb') - - in_data = in_f.read() - out_data = out_f.read() - out_f.close() - os.remove(outfile) - - self.assertEqual(in_data, out_data) - - -if __name__ == '__main__': - gr_unittest.run(test_wavefile, "test_wavefile.xml") diff --git a/gr-analog/examples/tags/uhd_burst_detector.py b/gr-analog/examples/tags/uhd_burst_detector.py index 6e73e8ad1e..c0a8d955c2 100755 --- a/gr-analog/examples/tags/uhd_burst_detector.py +++ b/gr-analog/examples/tags/uhd_burst_detector.py @@ -70,7 +70,7 @@ class uhd_burst_detector(gr.top_block): self.f2s = blocks.float_to_short() # Use file sink burst tagger to capture bursts - self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) + self.fsnk = blocks.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) ################################################## diff --git a/gr-audio/examples/python/dial_tone_wav.py b/gr-audio/examples/python/dial_tone_wav.py index 4d8d6b4019..91bf744c95 100755 --- a/gr-audio/examples/python/dial_tone_wav.py +++ b/gr-audio/examples/python/dial_tone_wav.py @@ -23,6 +23,7 @@ # GNU Radio example program to record a dial tone to a WAV file from gnuradio import gr +from gnuradio import blocks from gnuradio.eng_option import eng_option from optparse import OptionParser @@ -55,7 +56,7 @@ class my_top_block(gr.top_block): src1 = analog.sig_source_f(sample_rate, analog.GR_SIN_WAVE, 440, ampl) head0 = gr.head(gr.sizeof_float, int(options.samples)) head1 = gr.head(gr.sizeof_float, int(options.samples)) - dst = gr.wavfile_sink(args[0], 2, int(options.sample_rate), 16) + dst = blocks.wavfile_sink(args[0], 2, int(options.sample_rate), 16) self.connect(src0, head0, (dst, 0)) self.connect(src1, head1, (dst, 1)) diff --git a/gr-blocks/examples/tags/test_file_tags.py b/gr-blocks/examples/tags/test_file_tags.py index 1493864bd4..92112325b2 100755 --- a/gr-blocks/examples/tags/test_file_tags.py +++ b/gr-blocks/examples/tags/test_file_tags.py @@ -41,7 +41,7 @@ def main(): ann = gr.annotator_alltoall(1000000, gr.sizeof_short) tagger = blocks..burst_tagger(gr.sizeof_short) - fsnk = gr.tagged_file_sink(gr.sizeof_short, 1) + fsnk = blocks.tagged_file_sink(gr.sizeof_short, 1) tb = gr.top_block() tb.connect(src, thr, (tagger, 0)) diff --git a/gr-blocks/include/blocks/wavfile.h b/gr-blocks/include/blocks/wavfile.h index 690f8fc22a..b852c01e2d 100644 --- a/gr-blocks/include/blocks/wavfile.h +++ b/gr-blocks/include/blocks/wavfile.h @@ -20,7 +20,7 @@ * Boston, MA 02110-1301, USA. */ -// This file stores all the RIFF file type knowledge for the gr_wavfile_* +// This file stores all the RIFF file type knowledge for the wavfile_* // blocks. #include <blocks/api.h> diff --git a/gr-blocks/lib/tagged_file_sink_impl.cc b/gr-blocks/lib/tagged_file_sink_impl.cc index a2e9ab3853..7d011e45f0 100644 --- a/gr-blocks/lib/tagged_file_sink_impl.cc +++ b/gr-blocks/lib/tagged_file_sink_impl.cc @@ -84,8 +84,8 @@ namespace gr { 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("rx_time"); // use gr_tags::key_time + pmt::pmt_t bkey = pmt::string_to_symbol("burst"); + pmt::pmt_t tkey = pmt::string_to_symbol("rx_time"); // use gr_tags::key_time std::vector<gr_tag_t> all_tags; get_tags_in_range(all_tags, 0, start_N, end_N); @@ -101,8 +101,8 @@ namespace gr { const gr_tag_t tag = time_tags_outer[0]; uint64_t offset = tag.offset; pmt::pmt_t time = tag.value; - uint64_t tsecs = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(time, 0)); - double tfrac = pmt::pmt_to_double(pmt::pmt_tuple_ref(time, 1)); + uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); + double tfrac = pmt::to_double(pmt::tuple_ref(time, 1)); double delta = (double)offset / d_sample_rate; d_timeval = (double)tsecs + tfrac + delta; d_last_N = offset; @@ -112,8 +112,8 @@ namespace gr { while(idx < noutput_items) { if(d_state == NOT_IN_BURST) { while(vitr != all_tags.end()) { - if((pmt::pmt_eqv((*vitr).key, bkey)) && - pmt::pmt_is_true((*vitr).value)) { + if((pmt::eqv((*vitr).key, bkey)) && + pmt::is_true((*vitr).value)) { uint64_t N = (*vitr).offset; idx = (int)(N - start_N); @@ -133,8 +133,8 @@ namespace gr { // Get time based on last time tag from USRP pmt::pmt_t time = tag.value; - uint64_t tsecs = pmt::pmt_to_uint64(pmt::pmt_tuple_ref(time, 0)); - double tfrac = pmt::pmt_to_double(pmt::pmt_tuple_ref(time, 1)); + uint64_t tsecs = pmt::to_uint64(pmt::tuple_ref(time, 0)); + double tfrac = pmt::to_double(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 @@ -190,8 +190,8 @@ namespace gr { } else { // In burst while(vitr != all_tags.end()) { - if((pmt::pmt_eqv((*vitr).key, bkey)) && - pmt::pmt_is_false((*vitr).value)) { + if((pmt::eqv((*vitr).key, bkey)) && + pmt::is_false((*vitr).value)) { uint64_t N = (*vitr).offset; idx_stop = (int)N - start_N; diff --git a/gr-fcd/examples/grc/fcd_apt_rx.grc b/gr-fcd/examples/grc/fcd_apt_rx.grc index c4d3e64d1a..41a806a102 100644 --- a/gr-fcd/examples/grc/fcd_apt_rx.grc +++ b/gr-fcd/examples/grc/fcd_apt_rx.grc @@ -270,7 +270,7 @@ </param> </block> <block> - <key>gr_wavfile_sink</key> + <key>blocks_wavfile_sink</key> <param> <key>id</key> <value>wavfile_sink</value> diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index ab8489f7d8..94225e976e 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -14,7 +14,6 @@ <block>gr_file_source</block> <block>blks2_tcp_source</block> <block>gr_udp_source</block> - <block>gr_wavfile_source</block> <block>pad_source</block> <block>virtual_source</block> </cat> @@ -25,7 +24,6 @@ <block>gr_file_sink</block> <block>blks2_tcp_sink</block> <block>gr_udp_sink</block> - <block>gr_wavfile_sink</block> <block>pad_sink</block> <block>virtual_sink</block> </cat> diff --git a/grc/blocks/gr_wavfile_sink.xml b/grc/blocks/gr_wavfile_sink.xml deleted file mode 100644 index 651e16cb6b..0000000000 --- a/grc/blocks/gr_wavfile_sink.xml +++ /dev/null @@ -1,43 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Wav File Sink -################################################### - --> -<block> - <name>Wav File Sink</name> - <key>gr_wavfile_sink</key> - <import>from gnuradio import gr</import> - <make>gr.wavfile_sink($file, $nchan, $samp_rate, $bits_per_sample)</make> - <callback>open($file)</callback> - <param> - <name>File</name> - <key>file</key> - <value></value> - <type>file_save</type> - </param> - <param> - <name>N Channels</name> - <key>nchan</key> - <value>1</value> - <type>int</type> - </param> - <param> - <name>Sample Rate</name> - <key>samp_rate</key> - <value>samp_rate</value> - <type>int</type> - </param> - <param> - <name>Bits per Sample</name> - <key>bits_per_sample</key> - <value>8</value> - <type>int</type> - </param> - <check>1 <= $nchan</check> - <sink> - <name>in</name> - <type>float</type> - <nports>$nchan</nports> - </sink> -</block> diff --git a/grc/blocks/gr_wavfile_source.xml b/grc/blocks/gr_wavfile_source.xml deleted file mode 100644 index 433bb0af21..0000000000 --- a/grc/blocks/gr_wavfile_source.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Wav File Source -################################################### - --> -<block> - <name>Wav File Source</name> - <key>gr_wavfile_source</key> - <import>from gnuradio import gr</import> - <make>gr.wavfile_source($file, $repeat)</make> - <param> - <name>File</name> - <key>file</key> - <value></value> - <type>file_open</type> - </param> - <param> - <name>Repeat</name> - <key>repeat</key> - <value>True</value> - <type>enum</type> - <option> - <name>Yes</name> - <key>True</key> - </option> - <option> - <name>No</name> - <key>False</key> - </option> - </param> - <param> - <name>N Channels</name> - <key>nchan</key> - <value>1</value> - <type>int</type> - </param> - <check>1 <= $nchan</check> - <source> - <name>out</name> - <type>float</type> - <nports>$nchan</nports> - </source> -</block> |