3 * Copyright 2008,2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef INCLUDED_GR_WAVFILE_SINK_H
24 #define INCLUDED_GR_WAVFILE_SINK_H
26 #include <gr_sync_block.h>
27 #include <gr_file_sink_base.h>
28 #include <boost/thread.hpp>
30 class gr_wavfile_sink;
31 typedef boost::shared_ptr<gr_wavfile_sink> gr_wavfile_sink_sptr;
34 * \p filename The .wav file to be opened
35 * \p n_channels Number of channels (2 = stereo or I/Q output)
36 * \p sample_rate Sample rate [S/s]
37 * \p bits_per_sample 16 or 8 bit, default is 16
40 gr_make_wavfile_sink (const char *filename,
42 unsigned int sample_rate,
43 int bits_per_sample = 16);
46 * \brief Read stream from a Microsoft PCM (.wav) file, output floats
48 * Values are within [-1;1].
49 * Check gr_make_wavfile_source() for extra info.
53 class gr_wavfile_sink : public gr_sync_block
56 friend gr_wavfile_sink_sptr gr_make_wavfile_sink (const char *filename,
58 unsigned int sample_rate,
61 gr_wavfile_sink(const char *filename,
63 unsigned int sample_rate,
66 unsigned d_sample_rate;
68 unsigned d_sample_count;
69 int d_bytes_per_sample;
70 int d_bytes_per_sample_new;
73 int d_normalize_shift;
82 * \brief Convert a sample value within [-1;+1] to a corresponding
85 short convert_to_short(float sample);
88 * \brief Writes information to the WAV header which is not available
89 * a-priori (chunk size etc.) and closes the file. Not thread-safe and
90 * assumes d_fp is a valid file pointer, should thus only be called by
99 * \brief Opens a new file and writes a WAV header. Thread-safe.
101 bool open(const char* filename);
104 * \brief Closes the currently active file and completes the WAV
105 * header. Thread-safe.
110 * \brief If any file changes have occurred, update now. This is called
111 * internally by work() and thus doesn't usually need to be called by
117 * \brief Set the sample rate. This will not affect the WAV file
118 * currently opened. Any following open() calls will use this new
121 void set_sample_rate(unsigned int sample_rate);
124 * \brief Set bits per sample. This will not affect the WAV file
125 * currently opened (see set_sample_rate()). If the value is neither
126 * 8 nor 16, the call is ignored and the current value is kept.
128 void set_bits_per_sample(int bits_per_sample);
131 int work(int noutput_items,
132 gr_vector_const_void_star &input_items,
133 gr_vector_void_star &output_items);
137 #endif /* INCLUDED_GR_WAVFILE_SINK_H */