GNU Radio 3.6.3 C++ API
gri_wavfile.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22 
23 // This file stores all the RIFF file type knowledge for the gr_wavfile_*
24 // blocks.
25 
26 #include <gr_core_api.h>
27 #include <cstdio>
28 
29 /*!
30  * \brief Read signal information from a given WAV file.
31  *
32  * \param[in] fp File pointer to an opened, empty file.
33  * \param[out] sample_rate Stores the sample rate [S/s]
34  * \param[out] nchans Number of channels
35  * \param[out] bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding o
36  * 8 or 16 bit samples, respectively)
37  * \param[out] first_sample_pos Number of the first byte containing a sample. Use this
38  * with fseek() to jump from the end of the file to the
39  * first sample when in repeat mode.
40  * \param[out] samples_per_chan Number of samples per channel
41  * \return True on a successful read, false if the file could not be read or is
42  * not a valid WAV file.
43  */
44 bool
45 gri_wavheader_parse(FILE *fp,
46  unsigned int &sample_rate,
47  int &nchans,
48  int &bytes_per_sample,
49  int &first_sample_pos,
50  unsigned int &samples_per_chan);
51 
52 
53 /*!
54  * \brief Read one sample from an open WAV file at the current position.
55  *
56  * Takes care of endianness.
57  */
58 short int
59 gri_wav_read_sample(FILE *fp, int bytes_per_sample);
60 
61 
62 /*!
63  * \brief Write a valid RIFF file header
64  *
65  * Note: Some header values are kept blank because they're usually not known
66  * a-priori (file and chunk lengths). Use gri_wavheader_complete() to fill
67  * these in.
68  */
69 bool
70 gri_wavheader_write(FILE *fp,
71  unsigned int sample_rate,
72  int nchans,
73  int bytes_per_sample);
74 
75 /*!
76  * \brief Write one sample to an open WAV file at the current position.
77  *
78  * Takes care of endianness.
79  */
80 void
81 gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample);
82 
83 
84 /*!
85  * \brief Complete a WAV header
86  *
87  * Note: The stream position is changed during this function. If anything
88  * needs to be written to the WAV file after calling this function (which
89  * shouldn't happen), you need to fseek() to the end of the file (or
90  * whereever).
91  *
92  * \param[in] fp File pointer to an open WAV file with a blank header
93  * \param[in] byte_count Length of all samples written to the file in bytes.
94  */
95 bool
96 gri_wavheader_complete(FILE *fp, unsigned int byte_count);