gr_wavfile_sink.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2008 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_GR_WAVFILE_SINK_H
00024 #define INCLUDED_GR_WAVFILE_SINK_H
00025 
00026 #include <gr_sync_block.h>
00027 #include <gr_file_sink_base.h>
00028 #include <omnithread.h>
00029 
00030 class gr_wavfile_sink;
00031 typedef boost::shared_ptr<gr_wavfile_sink> gr_wavfile_sink_sptr;
00032 
00033 /*
00034  * \p filename The .wav file to be opened
00035  * \p n_channels Number of channels (2 = stereo or I/Q output)
00036  * \p sample_rate Sample rate [S/s]
00037  * \p bits_per_sample 16 or 8 bit, default is 16
00038  */
00039 gr_wavfile_sink_sptr
00040 gr_make_wavfile_sink (const char *filename,
00041                       int n_channels,
00042                       unsigned int sample_rate,
00043                       int bits_per_sample = 16);
00044 
00053 class gr_wavfile_sink : public gr_sync_block
00054 {
00055 private:
00056   friend gr_wavfile_sink_sptr gr_make_wavfile_sink (const char *filename,
00057                                                     int n_channels,
00058                                                     unsigned int sample_rate,
00059                                                     int bits_per_sample);
00060 
00061   gr_wavfile_sink(const char *filename,
00062                   int n_channels,
00063                   unsigned int sample_rate,
00064                   int bits_per_sample);
00065 
00066   unsigned d_sample_rate;
00067   int d_nchans;
00068   unsigned d_sample_count;
00069   int d_bytes_per_sample;
00070   int d_bytes_per_sample_new;
00071   int d_max_sample_val;
00072   int d_min_sample_val;
00073   int d_normalize_shift;
00074   int d_normalize_fac;
00075 
00076   FILE *d_fp;
00077   FILE *d_new_fp;
00078   bool d_updated;
00079   omni_mutex d_mutex;
00080   
00085   short convert_to_short(float sample);
00086 
00093   void close_wav();
00094 
00095 public:
00096   ~gr_wavfile_sink ();
00097 
00101   bool open(const char* filename);
00102 
00107   void close();
00108 
00114   void do_update();
00115   
00121   void set_sample_rate(unsigned int sample_rate);
00122   
00128   void set_bits_per_sample(int bits_per_sample);
00129   
00130   
00131   int work(int noutput_items,
00132            gr_vector_const_void_star &input_items,
00133            gr_vector_void_star &output_items);
00134   
00135 };
00136 
00137 #endif /* INCLUDED_GR_WAVFILE_SINK_H */

Generated on Thu Mar 5 09:01:12 2009 for GNU Radio 3.1.3 by  doxygen 1.5.8