1 // ----------------------------------------------------------------------------
3 // Copyright (C) 2006-2012 Fons Adriaensen <fons@linuxaudio.org>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // ----------------------------------------------------------------------------
21 #ifndef _ZITA_ALSA_PCMI_H_
22 #define _ZITA_ALSA_PCMI_H_
25 #define ALSA_PCM_NEW_HW_PARAMS_API
26 #define ALSA_PCM_NEW_SW_PARAMS_API
27 #include <alsa/asoundlib.h>
30 #define ZITA_ALSA_PCMI_MAJOR_VERSION 0
31 #define ZITA_ALSA_PCMI_MINOR_VERSION 2
35 extern int zita_alsa_pcmi_major_version (void);
36 extern int zita_alsa_pcmi_minor_version (void);
44 const char *play_name,
45 const char *capt_name,
46 const char *ctrl_name,
49 unsigned int play_nfrags,
50 unsigned int capt_nfrags,
51 unsigned int debug = 0);
66 void printinfo (void);
70 snd_pcm_sframes_t pcm_wait (void);
71 int pcm_idle (int len);
73 int play_init (snd_pcm_uframes_t len);
74 void clear_chan (int chan, int len);
75 void play_chan (int chan, const float *src, int len, int step = 1);
76 int play_done (int len);
78 int capt_init (snd_pcm_uframes_t len);
79 void capt_chan (int chan, float *dst, int len, int step = 1);
80 int capt_done (int len);
84 return snd_pcm_avail (_play_handle);
89 return snd_pcm_avail (_capt_handle);
95 snd_pcm_delay (_play_handle, &k);
102 snd_pcm_delay (_capt_handle, &k);
106 float play_xrun (void) const { return _play_xrun; }
107 float capt_xrun (void) const { return _capt_xrun; }
109 int state (void) const { return _state; }
110 size_t fsize (void) const { return _fsize; }
111 uint32_t fsamp (void) const { return _fsamp; }
112 uint32_t play_nfrag (void) const { return _play_nfrag; }
113 uint32_t capt_nfrag (void) const { return _capt_nfrag; }
114 uint32_t nplay (void) const { return _play_nchan; }
115 uint32_t ncapt (void) const { return _capt_nchan; }
116 snd_pcm_t *play_handle (void) const { return _play_handle; }
117 snd_pcm_t *capt_handle (void) const { return _capt_handle; }
122 typedef char *(Alsa_pcmi::*clear_function)(char *, int);
123 typedef char *(Alsa_pcmi::*play_function)(const float *, char *, int, int);
124 typedef const char *(Alsa_pcmi::*capt_function) (const char *, float *, int, int);
126 enum { MAXPFD = 16, MAXCHAN = 64 };
128 void initialise (const char *play_name, const char *capt_name, const char *ctrl_name);
129 int set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int nfrag, unsigned int *nchan);
130 int set_swpar (snd_pcm_t *handle, snd_pcm_sw_params_t *swpar, const char *sname);
132 float xruncheck (snd_pcm_status_t *stat);
134 char *clear_32 (char *dst, int nfrm);
135 char *clear_24 (char *dst, int nfrm);
136 char *clear_16 (char *dst, int nfrm);
138 char *play_float (const float *src, char *dst, int nfrm, int step);
139 char *play_32 (const float *src, char *dst, int nfrm, int step);
140 char *play_24 (const float *src, char *dst, int nfrm, int step);
141 char *play_16 (const float *src, char *dst, int nfrm, int step);
142 char *play_32swap (const float *src, char *dst, int nfrm, int step);
143 char *play_24swap (const float *src, char *dst, int nfrm, int step);
144 char *play_16swap (const float *src, char *dst, int nfrm, int step);
146 const char *capt_float (const char *src, float *dst, int nfrm, int step);
147 const char *capt_32 (const char *src, float *dst, int nfrm, int step);
148 const char *capt_24 (const char *src, float *dst, int nfrm, int step);
149 const char *capt_16 (const char *src, float *dst, int nfrm, int step);
150 const char *capt_32swap (const char *src, float *dst, int nfrm, int step);
151 const char *capt_24swap (const char *src, float *dst, int nfrm, int step);
152 const char *capt_16swap (const char *src, float *dst, int nfrm, int step);
155 snd_pcm_uframes_t _fsize;
156 unsigned int _play_nfrag;
157 unsigned int _capt_nfrag;
160 snd_pcm_t *_play_handle;
161 snd_pcm_t *_capt_handle;
162 snd_ctl_t *_ctrl_handle;
163 snd_pcm_hw_params_t *_play_hwpar;
164 snd_pcm_sw_params_t *_play_swpar;
165 snd_pcm_hw_params_t *_capt_hwpar;
166 snd_pcm_sw_params_t *_capt_swpar;
167 snd_pcm_format_t _play_format;
168 snd_pcm_format_t _capt_format;
169 snd_pcm_access_t _play_access;
170 snd_pcm_access_t _capt_access;
171 unsigned int _play_nchan;
172 unsigned int _capt_nchan;
178 struct pollfd _poll_fd [MAXPFD];
179 snd_pcm_uframes_t _capt_offs;
180 snd_pcm_uframes_t _play_offs;
183 char *_play_ptr [MAXCHAN];
184 const char *_capt_ptr [MAXCHAN];
185 clear_function _clear_func;
186 play_function _play_func;
187 capt_function _capt_func;