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