Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / io / gri_wavfile.h
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 <cstdio>
27
28 /*!
29  * \brief Read signal information from a given WAV file.
30  *
31  * \p fp File pointer to an opened, empty file.
32  * \p sample_rate Stores the sample rate [S/s]
33  * \p nchans      Number of channels
34  * \p bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding to
35  *         8 or 16 bit samples, respectively)
36  * \p first_sample_pos Number of the first byte containing a sample. Use this
37  *         with fseek() to jump from the end of the file to the first sample
38  *         when in repeat mode.
39  * \p samples_per_chan Number of samples per channel
40  * \p normalize_fac The normalization factor with which you need to divide the
41  *         integer values of the samples to get them within [-1;1]
42  * \p normalize_shift The value by which the sample values need to be shifted
43  *         after normalization (reason being, 8-bit WAV files store samples as
44  *         unsigned char and 16-bit as signed short int)
45  * \return True on a successful read, false if the file could not be read or is
46  *         not a valid WAV file.
47  */
48 bool
49 gri_wavheader_parse(FILE *fp,
50                     unsigned int &sample_rate,
51                     int &nchans,
52                     int &bytes_per_sample,
53                     int &first_sample_pos,
54                     unsigned int &samples_per_chan);
55
56
57 /*!
58  * \brief Read one sample from an open WAV file at the current position.
59  *
60  * Takes care of endianness.
61  */
62 short int
63 gri_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 not known
70  * a-priori (file and chunk lengths). Use gri_wavheader_complete() to fill
71  * these in.
72  */
73 bool
74 gri_wavheader_write(FILE *fp,
75                  unsigned int sample_rate,
76                  int nchans,
77                  int bytes_per_sample);
78
79 /*!
80  * \brief Write one sample to an open WAV file at the current position.
81  *
82  * Takes care of endianness.
83  */
84 void
85 gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample);
86
87
88 /*!
89  * \brief Complete a WAV header
90  *
91  * Note: The stream position is changed during this function. If anything
92  * needs to be written to the WAV file after calling this function (which
93  * shouldn't happen), you  need to fseek() to the end of the file (or 
94  * whereever).
95  *
96  * \p fp File pointer to an open WAV file with a blank header
97  * \p byte_count Length of all samples written to the file in bytes.
98  */
99 bool
100 gri_wavheader_complete(FILE *fp, unsigned int byte_count);