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,
50 unsigned int debug = 0);
65 void printinfo (void);
69 snd_pcm_sframes_t pcm_wait (void);
70 int pcm_idle (int len);
72 int play_init (snd_pcm_uframes_t len);
73 void clear_chan (int chan, int len);
74 void play_chan (int chan, const float *src, int len, int step = 1);
75 int play_done (int len);
77 int capt_init (snd_pcm_uframes_t len);
78 void capt_chan (int chan, float *dst, int len, int step = 1);
79 int capt_done (int len);
83 return snd_pcm_avail (_play_handle);
88 return snd_pcm_avail (_capt_handle);
94 snd_pcm_delay (_play_handle, &k);
101 snd_pcm_delay (_capt_handle, &k);
105 float play_xrun (void) const { return _play_xrun; }
106 float capt_xrun (void) const { return _capt_xrun; }
108 int state (void) const { return _state; }
109 size_t fsize (void) const { return _fsize; }
110 uint32_t fsamp (void) const { return _fsamp; }
111 uint32_t nfrag (void) const { return _nfrag; }
112 uint32_t nplay (void) const { return _play_nchan; }
113 uint32_t ncapt (void) const { return _capt_nchan; }
114 snd_pcm_t *play_handle (void) const { return _play_handle; }
115 snd_pcm_t *capt_handle (void) const { return _capt_handle; }
120 typedef char *(Alsa_pcmi::*clear_function)(char *, int);
121 typedef char *(Alsa_pcmi::*play_function)(const float *, char *, int, int);
122 typedef const char *(Alsa_pcmi::*capt_function) (const char *, float *, int, int);
124 enum { MAXPFD = 16, MAXCHAN = 64 };
126 void initialise (const char *play_name, const char *capt_name, const char *ctrl_name);
127 int set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int *nchan);
128 int set_swpar (snd_pcm_t *handle, snd_pcm_sw_params_t *swpar, const char *sname);
130 float xruncheck (snd_pcm_status_t *stat);
132 char *clear_32 (char *dst, int nfrm);
133 char *clear_24 (char *dst, int nfrm);
134 char *clear_16 (char *dst, int nfrm);
136 char *play_float (const float *src, char *dst, int nfrm, int step);
137 char *play_32 (const float *src, char *dst, int nfrm, int step);
138 char *play_24 (const float *src, char *dst, int nfrm, int step);
139 char *play_16 (const float *src, char *dst, int nfrm, int step);
140 char *play_32swap (const float *src, char *dst, int nfrm, int step);
141 char *play_24swap (const float *src, char *dst, int nfrm, int step);
142 char *play_16swap (const float *src, char *dst, int nfrm, int step);
144 const char *capt_float (const char *src, float *dst, int nfrm, int step);
145 const char *capt_32 (const char *src, float *dst, int nfrm, int step);
146 const char *capt_24 (const char *src, float *dst, int nfrm, int step);
147 const char *capt_16 (const char *src, float *dst, int nfrm, int step);
148 const char *capt_32swap (const char *src, float *dst, int nfrm, int step);
149 const char *capt_24swap (const char *src, float *dst, int nfrm, int step);
150 const char *capt_16swap (const char *src, float *dst, int nfrm, int step);
153 snd_pcm_uframes_t _fsize;
157 snd_pcm_t *_play_handle;
158 snd_pcm_t *_capt_handle;
159 snd_ctl_t *_ctrl_handle;
160 snd_pcm_hw_params_t *_play_hwpar;
161 snd_pcm_sw_params_t *_play_swpar;
162 snd_pcm_hw_params_t *_capt_hwpar;
163 snd_pcm_sw_params_t *_capt_swpar;
164 snd_pcm_format_t _play_format;
165 snd_pcm_format_t _capt_format;
166 snd_pcm_access_t _play_access;
167 snd_pcm_access_t _capt_access;
168 unsigned int _play_nchan;
169 unsigned int _capt_nchan;
175 struct pollfd _poll_fd [MAXPFD];
176 snd_pcm_uframes_t _capt_offs;
177 snd_pcm_uframes_t _play_offs;
180 char *_play_ptr [MAXCHAN];
181 const char *_capt_ptr [MAXCHAN];
182 clear_function _clear_func;
183 play_function _play_func;
184 capt_function _capt_func;