|
a |
|
b/mpd2src/wavreader.h |
|
|
1 |
/* Copyright (C) 2015 J.F.Dockes
|
|
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
#ifndef _WAV_H_INCLUDED_
|
|
|
19 |
#define _WAV_H_INCLUDED_
|
|
|
20 |
|
|
|
21 |
#include "audioreader.h"
|
|
|
22 |
|
|
|
23 |
#include <string>
|
|
|
24 |
|
|
|
25 |
// This just somewhat encapsulates the code in the original
|
|
|
26 |
// WavSender.cpp The file is still read and converted in memory at
|
|
|
27 |
// once, and held in a memory array
|
|
|
28 |
class WavReader : public AudioReader {
|
|
|
29 |
public:
|
|
|
30 |
WavReader(const std::string& fn)
|
|
|
31 |
: m_fn(fn), m_fp(0), m_data(0), m_subChunk2Size(0), m_dataoffs(0),
|
|
|
32 |
m_index(0), m_tmpbuf(0), m_tmpbufsize(0) {
|
|
|
33 |
}
|
|
|
34 |
~WavReader() {
|
|
|
35 |
if (m_fp)
|
|
|
36 |
fclose(m_fp);
|
|
|
37 |
if (m_data)
|
|
|
38 |
free(m_data);
|
|
|
39 |
if (m_tmpbuf)
|
|
|
40 |
free(m_tmpbuf);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
bool open();
|
|
|
44 |
|
|
|
45 |
// Get pointer to data at offset. Caller is supposed to know how
|
|
|
46 |
// much there is ahead.
|
|
|
47 |
const unsigned char *data(size_t size);
|
|
|
48 |
|
|
|
49 |
unsigned int subChunk2Size() {
|
|
|
50 |
return m_subChunk2Size;
|
|
|
51 |
}
|
|
|
52 |
unsigned int sampleCount() {
|
|
|
53 |
return m_subChunk2Size / bytesPerSample();
|
|
|
54 |
}
|
|
|
55 |
unsigned int totalBytes() {
|
|
|
56 |
return m_subChunk2Size;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
private:
|
|
|
60 |
bool readHeader();
|
|
|
61 |
bool readData();
|
|
|
62 |
|
|
|
63 |
std::string m_fn;
|
|
|
64 |
FILE *m_fp;
|
|
|
65 |
unsigned char *m_data;
|
|
|
66 |
unsigned int m_byteRate;
|
|
|
67 |
unsigned int m_subChunk2Size; // Data segment size in bytes
|
|
|
68 |
off_t m_dataoffs; // Data offset in file
|
|
|
69 |
|
|
|
70 |
off_t m_index; // Current position of reader
|
|
|
71 |
unsigned char *m_tmpbuf;
|
|
|
72 |
size_t m_tmpbufsize;
|
|
|
73 |
};
|
|
|
74 |
|
|
|
75 |
#endif /* _WAV_H_INCLUDED_ */
|