GNU Radio 3.6.5 C++ API

wavfile.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2008,2013 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 // This file stores all the RIFF file type knowledge for the gr_wavfile_*
00024 // blocks.
00025 
00026 #include <blocks/api.h>
00027 #include <cstdio>
00028 
00029 namespace gr {
00030   namespace blocks {
00031 
00032     /*!
00033      * \brief Read signal information from a given WAV file.
00034      *
00035      * \param[in]  fp          File pointer to an opened, empty file.
00036      * \param[out] sample_rate Stores the sample rate [S/s]
00037      * \param[out] nchans      Number of channels
00038      * \param[out] bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding o
00039      *                              8 or 16 bit samples, respectively)
00040      * \param[out] first_sample_pos Number of the first byte containing a sample. Use this
00041      *                              with fseek() to jump from the end of the file to the
00042      *                              first sample when in repeat mode.
00043      * \param[out] samples_per_chan Number of samples per channel
00044      * \return True on a successful read, false if the file could not be read or is
00045      *         not a valid WAV file.
00046      */
00047     bool
00048     wavheader_parse(FILE *fp,
00049                     unsigned int &sample_rate,
00050                     int &nchans,
00051                     int &bytes_per_sample,
00052                     int &first_sample_pos,
00053                     unsigned int &samples_per_chan);
00054 
00055     /*!
00056      * \brief Read one sample from an open WAV file at the current position.
00057      *
00058      * \details
00059      * Takes care of endianness.
00060      */
00061     short int
00062     wav_read_sample(FILE *fp, int bytes_per_sample);
00063 
00064     
00065     /*!
00066      * \brief Write a valid RIFF file header
00067      *
00068      * Note: Some header values are kept blank because they're usually
00069      * not known a-priori (file and chunk lengths). Use
00070      * gri_wavheader_complete() to fill these in.
00071      */
00072     bool
00073     wavheader_write(FILE *fp,
00074                     unsigned int sample_rate,
00075                     int nchans,
00076                     int bytes_per_sample);
00077 
00078     /*!
00079      * \brief Write one sample to an open WAV file at the current position.
00080      *
00081      * \details
00082      * Takes care of endianness.
00083      */
00084     void
00085     wav_write_sample(FILE *fp, short int sample, int bytes_per_sample);
00086 
00087 
00088     /*!
00089      * \brief Complete a WAV header
00090      *
00091      * \details
00092      * Note: The stream position is changed during this function. If
00093      * anything needs to be written to the WAV file after calling this
00094      * function (which shouldn't happen), you need to fseek() to the
00095      * end of the file (or whereever).
00096      *
00097      * \param[in] fp         File pointer to an open WAV file with a blank header
00098      * \param[in] byte_count Length of all samples written to the file in bytes.
00099      */
00100     bool
00101     wavheader_complete(FILE *fp, unsigned int byte_count);
00102 
00103   } /* namespace blocks */
00104 } /* namespace gr */