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
|
// ----------------------------------------------------------------------------
//
// Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
//
// 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 3 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, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
#ifndef _ZITA_ALSA_PCMI_H_
#define _ZITA_ALSA_PCMI_H_
#define ALSA_PCM_NEW_HW_PARAMS_API
#define ALSA_PCM_NEW_SW_PARAMS_API
#include <alsa/asoundlib.h>
#define ZITA_ALSA_PCMI_MAJOR_VERSION 0
#define ZITA_ALSA_PCMI_MINOR_VERSION 2
#include <stdint.h>
extern int zita_alsa_pcmi_major_version (void);
extern int zita_alsa_pcmi_minor_version (void);
class Alsa_pcmi
{
public:
Alsa_pcmi (
const char *play_name,
const char *capt_name,
const char *ctrl_name,
unsigned int rate,
unsigned int frsize,
unsigned int play_nfrags,
unsigned int capt_nfrags,
unsigned int debug = 0);
~Alsa_pcmi (void);
enum
{
DEBUG_INIT = 1,
DEBUG_STAT = 2,
DEBUG_WAIT = 4,
DEBUG_DATA = 8,
DEBUG_ALL = 15,
FORCE_16B = 256,
FORCE_2CH = 512
};
void printinfo (void);
int pcm_start (void);
int pcm_stop (void);
snd_pcm_sframes_t pcm_wait (void);
int pcm_idle (int len);
int play_init (snd_pcm_uframes_t len);
void clear_chan (int chan, int len);
void play_chan (int chan, const float *src, int len, int step = 1);
int play_done (int len);
int capt_init (snd_pcm_uframes_t len);
void capt_chan (int chan, float *dst, int len, int step = 1);
int capt_done (int len);
int play_avail (void)
{
return snd_pcm_avail (_play_handle);
}
int capt_avail (void)
{
return snd_pcm_avail (_capt_handle);
}
int play_delay (void)
{
long k;
snd_pcm_delay (_play_handle, &k);
return k;
}
int capt_delay (void)
{
long k;
snd_pcm_delay (_capt_handle, &k);
return k;
}
float play_xrun (void) const { return _play_xrun; }
float capt_xrun (void) const { return _capt_xrun; }
int state (void) const { return _state; }
size_t fsize (void) const { return _fsize; }
uint32_t fsamp (void) const { return _fsamp; }
uint32_t play_nfrag (void) const { return _play_nfrag; }
uint32_t capt_nfrag (void) const { return _capt_nfrag; }
uint32_t nplay (void) const { return _play_nchan; }
uint32_t ncapt (void) const { return _capt_nchan; }
snd_pcm_t *play_handle (void) const { return _play_handle; }
snd_pcm_t *capt_handle (void) const { return _capt_handle; }
private:
typedef char *(Alsa_pcmi::*clear_function)(char *, int);
typedef char *(Alsa_pcmi::*play_function)(const float *, char *, int, int);
typedef const char *(Alsa_pcmi::*capt_function) (const char *, float *, int, int);
enum { MAXPFD = 16, MAXCHAN = 128 };
void initialise (const char *play_name, const char *capt_name, const char *ctrl_name);
int set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int nfrag, unsigned int *nchan);
int set_swpar (snd_pcm_t *handle, snd_pcm_sw_params_t *swpar, const char *sname);
int recover (void);
float xruncheck (snd_pcm_status_t *stat);
char *clear_32 (char *dst, int nfrm);
char *clear_24 (char *dst, int nfrm);
char *clear_16 (char *dst, int nfrm);
char *play_float (const float *src, char *dst, int nfrm, int step);
char *play_32 (const float *src, char *dst, int nfrm, int step);
char *play_24 (const float *src, char *dst, int nfrm, int step);
char *play_16 (const float *src, char *dst, int nfrm, int step);
char *play_32swap (const float *src, char *dst, int nfrm, int step);
char *play_24swap (const float *src, char *dst, int nfrm, int step);
char *play_16swap (const float *src, char *dst, int nfrm, int step);
const char *capt_float (const char *src, float *dst, int nfrm, int step);
const char *capt_32 (const char *src, float *dst, int nfrm, int step);
const char *capt_24 (const char *src, float *dst, int nfrm, int step);
const char *capt_16 (const char *src, float *dst, int nfrm, int step);
const char *capt_32swap (const char *src, float *dst, int nfrm, int step);
const char *capt_24swap (const char *src, float *dst, int nfrm, int step);
const char *capt_16swap (const char *src, float *dst, int nfrm, int step);
unsigned int _fsamp;
snd_pcm_uframes_t _fsize;
unsigned int _play_nfrag;
unsigned int _capt_nfrag;
unsigned int _debug;
int _state;
snd_pcm_t *_play_handle;
snd_pcm_t *_capt_handle;
snd_ctl_t *_ctrl_handle;
snd_pcm_hw_params_t *_play_hwpar;
snd_pcm_sw_params_t *_play_swpar;
snd_pcm_hw_params_t *_capt_hwpar;
snd_pcm_sw_params_t *_capt_swpar;
snd_pcm_format_t _play_format;
snd_pcm_format_t _capt_format;
snd_pcm_access_t _play_access;
snd_pcm_access_t _capt_access;
unsigned int _play_nchan;
unsigned int _capt_nchan;
float _play_xrun;
float _capt_xrun;
bool _synced;
int _play_npfd;
int _capt_npfd;
struct pollfd _poll_fd [MAXPFD];
snd_pcm_uframes_t _capt_offs;
snd_pcm_uframes_t _play_offs;
int _play_step;
int _capt_step;
char *_play_ptr [MAXCHAN];
const char *_capt_ptr [MAXCHAN];
clear_function _clear_func;
play_function _play_func;
capt_function _capt_func;
void *_dummy [16];
};
#endif
|