Parent: [8ecd7b] (diff)

Download this file

audioreader.h    75 lines (65 with data), 2.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Copyright (C) 2015 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _AUDIOREADER_H_INCLUDED_
#define _AUDIOREADER_H_INCLUDED_
#include <string>
// Base class for things which read audio
class AudioReader {
public:
AudioReader() {
m_numChannels = m_sampleRate = 0;
}
virtual ~AudioReader() {}
virtual bool open() = 0;
virtual void close() = 0;
virtual bool isblocking() {return false;}
virtual bool needswap() {return false;}
// Get pointer to data buffer of specified offset and size.
virtual const unsigned char *data(size_t cnt, ssize_t &nread) = 0;
// Return, compute if necessary, misc audio stream parameters:
virtual unsigned int numChannels() {
return m_numChannels;
}
virtual unsigned int sampleRate() {
return m_sampleRate;
}
virtual unsigned int bitsPerSample() {
return m_bitsPerSample;
}
virtual unsigned int byteRate() {
return m_numChannels * m_sampleRate * m_bitsPerSample / 8;
}
virtual unsigned int bytesPerSample() {
return m_bitsPerSample / 8;
}
virtual unsigned int bytesPerFrame() {
return bytesPerSample() * m_numChannels;
}
virtual unsigned int sampleCount() {
return 0;
}
protected:
void setAudioParams(int sampleRate, int bitsPerSample, int chans) {
m_numChannels = chans;
m_sampleRate = sampleRate;
m_bitsPerSample = bitsPerSample;
}
unsigned int m_numChannels;
unsigned int m_sampleRate; // sampling frequency, Hz
unsigned int m_bitsPerSample;
};
#endif /* _AUDIOREADER_H_INCLUDED_ */