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