GNU Radio 3.5.3.2 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  * \p fp File pointer to an opened, empty file.
00033  * \p sample_rate Stores the sample rate [S/s]
00034  * \p nchans      Number of channels
00035  * \p bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding to
00036  *         8 or 16 bit samples, respectively)
00037  * \p 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 first sample
00039  *         when in repeat mode.
00040  * \p samples_per_chan Number of samples per channel
00041  * \p normalize_fac The normalization factor with which you need to divide the
00042  *         integer values of the samples to get them within [-1;1]
00043  * \p normalize_shift The value by which the sample values need to be shifted
00044  *         after normalization (reason being, 8-bit WAV files store samples as
00045  *         unsigned char and 16-bit as signed short int)
00046  * \return True on a successful read, false if the file could not be read or is
00047  *         not a valid WAV file.
00048  */
00049 bool
00050 gri_wavheader_parse(FILE *fp,
00051                     unsigned int &sample_rate,
00052                     int &nchans,
00053                     int &bytes_per_sample,
00054                     int &first_sample_pos,
00055                     unsigned int &samples_per_chan);
00056 
00057 
00058 /*!
00059  * \brief Read one sample from an open WAV file at the current position.
00060  *
00061  * Takes care of endianness.
00062  */
00063 short int
00064 gri_wav_read_sample(FILE *fp, int bytes_per_sample);
00065 
00066 
00067 /*!
00068  * \brief Write a valid RIFF file header
00069  *
00070  * Note: Some header values are kept blank because they're usually not known
00071  * a-priori (file and chunk lengths). Use gri_wavheader_complete() to fill
00072  * these in.
00073  */
00074 bool
00075 gri_wavheader_write(FILE *fp,
00076                  unsigned int sample_rate,
00077                  int nchans,
00078                  int bytes_per_sample);
00079 
00080 /*!
00081  * \brief Write one sample to an open WAV file at the current position.
00082  *
00083  * Takes care of endianness.
00084  */
00085 void
00086 gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample);
00087 
00088 
00089 /*!
00090  * \brief Complete a WAV header
00091  *
00092  * Note: The stream position is changed during this function. If anything
00093  * needs to be written to the WAV file after calling this function (which
00094  * shouldn't happen), you  need to fseek() to the end of the file (or 
00095  * whereever).
00096  *
00097  * \p fp File pointer to an open WAV file with a blank header
00098  * \p byte_count Length of all samples written to the file in bytes.
00099  */
00100 bool
00101 gri_wavheader_complete(FILE *fp, unsigned int byte_count);