-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPcmInterface.h
238 lines (162 loc) · 2.95 KB
/
PcmInterface.h
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* SoundBase.h
*
* Created on: Jun 2, 2016
* Author: michal
*/
#ifndef PCMINTERFACE_H_
#define PCMINTERFACE_H_
#include <alsa/asoundlib.h>
#include "Logger.h"
#include <iostream>
//#include <thread>
#include <mutex>
#include <memory>
namespace Audio {
enum class Channels : unsigned int
{
mono = 1,
stereo = 2
};
/**
* \ Base class with all configurations methods
*/
class PcmInterface
{
snd_pcm_t* soundDevice { nullptr };
snd_pcm_hw_params_t* hwParams { nullptr };
const char* name { nullptr };
//std::once_flag chooseWriteFunction;
std::function<snd_pcm_sframes_t(void*, size_t)> writeFunctor;
bool isInterleaved();
public:
PcmInterface *pcm {this};
void functionChooser();
auto* getDevice()
{
return soundDevice;
}
auto* getParam()
{
return hwParams;
}
PcmInterface(const char* _name);
/**
* \ Abort functions, make extension if error code is existing
*/
char* decode_err(int err);
const char* decode_snd_err(int err);
void abort(const char* decodedError);
void abort();
/**
* \ Open device
*/
void opendev(snd_pcm_stream_t stream, int mode = 0);
/**
* \ Allocate hardware param memory and set the default values
*/
void paramsAllocateDefault();
/**
* \ Deallocate hardware param memory and set the default values
*/
void paramsFree();
/**
* \ Prepare
*/
void prepare();
/**
* \
*/
int getFormatWidth(snd_pcm_format_t format);
/**
* \
*/
void setAccess(snd_pcm_access_t access);
/**
* \
*/
void setFormat(snd_pcm_format_t format);
/**
* \
*/
void setChannels(Channels channels);
/**
* \
*/
void setRateNear(unsigned int val, int dir = 0);
/**
* \
*/
void setParams(snd_pcm_format_t format, snd_pcm_access_t access, Channels channels,
unsigned int rate, int soft_resample, unsigned int latency);
/**
* \
*/
snd_pcm_sframes_t writeInterleaved(const void* buffer, snd_pcm_uframes_t size);
/**
* \
*/
snd_pcm_sframes_t writeNonInterleaved(void* buffer, snd_pcm_uframes_t size);
/**
* \ Write
*/
snd_pcm_sframes_t write(void* buffer, snd_pcm_uframes_t size);
/**
* \
*/
snd_pcm_sframes_t readInterleaved(void* buffer, snd_pcm_uframes_t size);
/**
* \
*/
snd_pcm_sframes_t readNonInterleaved(void* buffer, snd_pcm_uframes_t size);
/**
* \ Read
*/
snd_pcm_sframes_t read(void* buffer, snd_pcm_uframes_t size);
/**
* \
*/
void recoverStream(int err, int silent);
/**
* \
*/
void recoverStream(snd_pcm_t *pcm, int err, int silent);
/**
* \
*/
void stopPresentingFrames();
/**
* \ Write all parameters
*/
void setParam();
/**
* \
*/
std::string getName() const;
/**
* \
*/
std::string getState() const;
/**
* \
*/
Channels getChannels() const;
/**
* \
*/
unsigned int getRate() const;
/**
* \
*/
snd_pcm_access_t getAccess();
/**
* \
*/
void close();
/*
*
*/
virtual ~PcmInterface();
};
} /* namespace Audio */
#endif /* PCMINTERFACE_H_ */