GNU Radio 3.5.3.1 C++ API
gr_wavfile_source.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004,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 #ifndef INCLUDED_GR_WAVFILE_SOURCE_H
24 #define INCLUDED_GR_WAVFILE_SOURCE_H
25 
26 #include <gr_core_api.h>
27 #include <gr_sync_block.h>
28 #include <cstdio> // for FILE
29 
30 class gr_wavfile_source;
32 
34 gr_make_wavfile_source (const char *filename, bool repeat = false);
35 
36 /*!
37  * \brief Read stream from a Microsoft PCM (.wav) file, output floats
38  *
39  * Unless otherwise called, values are within [-1;1].
40  * Check gr_make_wavfile_source() for extra info.
41  *
42  * \ingroup source_blk
43  */
44 
46 {
47 private:
48  friend GR_CORE_API gr_wavfile_source_sptr gr_make_wavfile_source (const char *filename,
49  bool repeat);
50  gr_wavfile_source(const char *filename, bool repeat);
51 
52  FILE *d_fp;
53  bool d_repeat;
54 
55  unsigned d_sample_rate;
56  int d_nchans;
57  int d_bytes_per_sample;
58  int d_first_sample_pos;
59  unsigned d_samples_per_chan;
60  unsigned d_sample_idx;
61  int d_normalize_shift;
62  int d_normalize_fac;
63 
64  /*!
65  * \brief Convert an integer sample value to a float value within [-1;1]
66  */
67  float convert_to_float(short int sample);
68 
69 public:
71 
72  int work(int noutput_items,
73  gr_vector_const_void_star &input_items,
74  gr_vector_void_star &output_items);
75 
76  /*!
77  * \brief Read the sample rate as specified in the wav file header
78  */
79  unsigned int sample_rate() const { return d_sample_rate; };
80 
81  /*!
82  * \brief Return the number of bits per sample as specified in the wav
83  * file header. Only 8 or 16 bit are supported here.
84  */
85  int bits_per_sample() const { return d_bytes_per_sample * 8; };
86 
87  /*!
88  * \brief Return the number of channels in the wav file as specified in
89  * the wav file header. This is also the max number of outputs you can
90  * have.
91  */
92  int channels() const { return d_nchans; };
93 };
94 
95 #endif /* INCLUDED_GR_WAVFILE_SOURCE_H */