GNU Radio 3.6.5 C++ API

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