Ardour  9.0-pre0-582-g084a23a80d
zita-alsa-pcmi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2022 Fons Adriaensen <fons@linuxaudio.org>
3  * Copyright (C) 2014-2022 Robin Gareus <robin@gareus.org>
4  *
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.
9  *
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.
14  *
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/>.
17  */
18 
19 #ifndef _ZITA_ALSA_PCMI_H_
20 #define _ZITA_ALSA_PCMI_H_
21 
22 #define ALSA_PCM_NEW_HW_PARAMS_API
23 #define ALSA_PCM_NEW_SW_PARAMS_API
24 
25 #include <alsa/asoundlib.h>
26 #include <stdint.h>
27 
28 class Alsa_pcmi
29 {
30 public:
32  const char* play_name,
33  const char* capt_name,
34  const char* ctrl_name,
35  unsigned int rate,
36  unsigned int frsize,
37  unsigned int play_nfrags,
38  unsigned int capt_nfrags,
39  unsigned int debug = 0);
40 
41  ~Alsa_pcmi (void);
42 
43  enum {
44  DEBUG_INIT = 0x001,
45  DEBUG_STAT = 0x002,
46  DEBUG_WAIT = 0x004,
47  DEBUG_DATA = 0x008,
48  DEBUG_ALL = 0x00f, // 15
49  FORCE_16B = 0x100, // 256,
50  FORCE_2CH = 0x200, // 512
51  TRY_INTLVD = 0x400, // 1024
52  };
53 
54  void printinfo (void);
55 
56  int pcm_start (void);
57  int pcm_stop (void);
58  int pcm_idle (int len);
59 
60  snd_pcm_sframes_t pcm_wait (void);
61 
62  int play_init (snd_pcm_uframes_t len);
63  void clear_chan (int chan, int len);
64  void play_chan (int chan, const float* src, int len, int step = 1);
65  int play_done (int len);
66 
67  int capt_init (snd_pcm_uframes_t len);
68  void capt_chan (int chan, float* dst, int len, int step = 1);
69  int capt_done (int len);
70 
71  int play_avail (void)
72  {
73  return snd_pcm_avail (_play_handle);
74  }
75 
76  int capt_avail (void)
77  {
78  return snd_pcm_avail (_capt_handle);
79  }
80 
81  int play_delay (void)
82  {
83  long k;
84  snd_pcm_delay (_play_handle, &k);
85  return k;
86  }
87 
88  int capt_delay (void)
89  {
90  long k;
91  snd_pcm_delay (_capt_handle, &k);
92  return k;
93  }
94 
95  float play_xrun (void) const { return _play_xrun; }
96  float capt_xrun (void) const { return _capt_xrun; }
97 
98  int state (void) const { return _state; }
99  size_t fsize (void) const { return _fsize; }
100  uint32_t fsamp (void) const { return _fsamp; }
101 
102  uint32_t play_nfrag (void) const { return _play_nfrag; }
103  uint32_t capt_nfrag (void) const { return _capt_nfrag; }
104 
105  uint32_t nplay (void) const { return _play_nchan; }
106  uint32_t ncapt (void) const { return _capt_nchan; }
107 
108  snd_pcm_t* play_handle (void) const { return _play_handle; }
109  snd_pcm_t* capt_handle (void) const { return _capt_handle; }
110 
111 private:
112  typedef char* (Alsa_pcmi::*clear_function) (char*, int);
113  typedef char* (Alsa_pcmi::*play_function) (const float*, char*, int, int);
114  typedef const char* (Alsa_pcmi::*capt_function) (const char*, float*, int, int);
115 
116  enum { MAXPFD = 16,
117  MAXCHAN = 128 };
118 
119  void initialise (const char* play_name, const char* capt_name, const char* ctrl_name);
120  int set_hwpar (snd_pcm_t* handle, snd_pcm_hw_params_t* hwpar, const char* sname, unsigned int nfrag, unsigned int* nchan);
121  int set_swpar (snd_pcm_t* handle, snd_pcm_sw_params_t* swpar, const char* sname);
122  int recover (void);
123  float xruncheck (snd_pcm_status_t* stat);
124 
125  char* clear_32 (char* dst, int nfrm);
126  char* clear_24 (char* dst, int nfrm);
127  char* clear_16 (char* dst, int nfrm);
128 
129  char* play_floatne (const float* src, char* dst, int nfrm, int step);
130  char* play_floatre (const float* src, char* dst, int nfrm, int step);
131  char* play_32le (const float* src, char* dst, int nfrm, int step);
132  char* play_24le (const float* src, char* dst, int nfrm, int step);
133  char* play_16le (const float* src, char* dst, int nfrm, int step);
134  char* play_32be (const float* src, char* dst, int nfrm, int step);
135  char* play_24be (const float* src, char* dst, int nfrm, int step);
136  char* play_16be (const float* src, char* dst, int nfrm, int step);
137 
138  const char* capt_floatne (const char* src, float* dst, int nfrm, int step);
139  const char* capt_floatre (const char* src, float* dst, int nfrm, int step);
140  const char* capt_32le (const char* src, float* dst, int nfrm, int step);
141  const char* capt_24le (const char* src, float* dst, int nfrm, int step);
142  const char* capt_16le (const char* src, float* dst, int nfrm, int step);
143  const char* capt_32be (const char* src, float* dst, int nfrm, int step);
144  const char* capt_24be (const char* src, float* dst, int nfrm, int step);
145  const char* capt_16be (const char* src, float* dst, int nfrm, int step);
146 
147  unsigned int _fsamp;
148  snd_pcm_uframes_t _fsize;
149  unsigned int _play_nfrag;
150  unsigned int _real_nfrag;
151  unsigned int _capt_nfrag;
152  unsigned int _debug;
153  int _state;
154  snd_pcm_t* _play_handle;
155  snd_pcm_t* _capt_handle;
156  snd_ctl_t* _ctrl_handle;
157  snd_pcm_hw_params_t* _play_hwpar;
158  snd_pcm_sw_params_t* _play_swpar;
159  snd_pcm_hw_params_t* _capt_hwpar;
160  snd_pcm_sw_params_t* _capt_swpar;
161  snd_pcm_format_t _play_format;
162  snd_pcm_format_t _capt_format;
163  snd_pcm_access_t _play_access;
164  snd_pcm_access_t _capt_access;
165  unsigned int _play_nchan;
166  unsigned int _capt_nchan;
167  float _play_xrun;
168  float _capt_xrun;
169  bool _synced;
172  struct pollfd _poll_fd[MAXPFD];
173  snd_pcm_uframes_t _capt_offs;
174  snd_pcm_uframes_t _play_offs;
178  const char* _capt_ptr[MAXCHAN];
182  void* _dummy[16];
183 };
184 
185 #endif
const char * capt_24le(const char *src, float *dst, int nfrm, int step)
unsigned int _fsamp
char * play_24be(const float *src, char *dst, int nfrm, int step)
unsigned int _real_nfrag
snd_pcm_access_t _play_access
void printinfo(void)
const char * capt_floatre(const char *src, float *dst, int nfrm, int step)
char * play_32le(const float *src, char *dst, int nfrm, int step)
void initialise(const char *play_name, const char *capt_name, const char *ctrl_name)
unsigned int _play_nchan
snd_pcm_sframes_t pcm_wait(void)
snd_ctl_t * _ctrl_handle
const char * capt_24be(const char *src, float *dst, int nfrm, int step)
snd_pcm_sw_params_t * _play_swpar
int play_done(int len)
snd_pcm_uframes_t _play_offs
int capt_avail(void)
int pcm_idle(int len)
snd_pcm_t * capt_handle(void) const
capt_function _capt_func
~Alsa_pcmi(void)
int set_hwpar(snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int nfrag, unsigned int *nchan)
const char * capt_32be(const char *src, float *dst, int nfrm, int step)
char *(Alsa_pcmi::* play_function)(const float *, char *, int, int)
int set_swpar(snd_pcm_t *handle, snd_pcm_sw_params_t *swpar, const char *sname)
int play_delay(void)
const char * _capt_ptr[MAXCHAN]
char * play_floatne(const float *src, char *dst, int nfrm, int step)
play_function _play_func
int capt_init(snd_pcm_uframes_t len)
size_t fsize(void) const
float xruncheck(snd_pcm_status_t *stat)
snd_pcm_hw_params_t * _play_hwpar
unsigned int _debug
char * _play_ptr[MAXCHAN]
snd_pcm_t * _capt_handle
float _capt_xrun
const char * capt_32le(const char *src, float *dst, int nfrm, int step)
int pcm_stop(void)
unsigned int _capt_nchan
unsigned int _play_nfrag
char *(Alsa_pcmi::* clear_function)(char *, int)
uint32_t nplay(void) const
const char * capt_floatne(const char *src, float *dst, int nfrm, int step)
snd_pcm_format_t _play_format
int pcm_start(void)
snd_pcm_format_t _capt_format
clear_function _clear_func
float play_xrun(void) const
char * play_16be(const float *src, char *dst, int nfrm, int step)
snd_pcm_uframes_t _fsize
struct pollfd _poll_fd[MAXPFD]
uint32_t play_nfrag(void) const
snd_pcm_t * _play_handle
float _play_xrun
char * play_floatre(const float *src, char *dst, int nfrm, int step)
char * clear_32(char *dst, int nfrm)
char * clear_24(char *dst, int nfrm)
void clear_chan(int chan, int len)
int play_avail(void)
uint32_t ncapt(void) const
void * _dummy[16]
char * clear_16(char *dst, int nfrm)
const char * capt_16le(const char *src, float *dst, int nfrm, int step)
int capt_delay(void)
const char *(Alsa_pcmi::* capt_function)(const char *, float *, int, int)
const char * capt_16be(const char *src, float *dst, int nfrm, int step)
int recover(void)
snd_pcm_uframes_t _capt_offs
snd_pcm_sw_params_t * _capt_swpar
int state(void) const
char * play_24le(const float *src, char *dst, int nfrm, int step)
void capt_chan(int chan, float *dst, int len, int step=1)
snd_pcm_access_t _capt_access
unsigned int _capt_nfrag
uint32_t fsamp(void) const
float capt_xrun(void) const
int play_init(snd_pcm_uframes_t len)
int capt_done(int len)
snd_pcm_hw_params_t * _capt_hwpar
snd_pcm_t * play_handle(void) const
char * play_32be(const float *src, char *dst, int nfrm, int step)
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)
void play_chan(int chan, const float *src, int len, int step=1)
uint32_t capt_nfrag(void) const
char * play_16le(const float *src, char *dst, int nfrm, int step)
Transmitter debug