2
Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
#define ALSA_PCM_NEW_HW_PARAMS_API
25
#define ALSA_PCM_NEW_SW_PARAMS_API
28
#include <alsa/asoundlib.h>
36
Alsa_driver (const char *play_name,
37
const char *capt_name,
38
const char *ctrl_name,
40
snd_pcm_uframes_t frsize,
43
Alsa_driver (const char *name,
45
snd_pcm_uframes_t frsize,
53
void printinfo (void);
59
snd_pcm_sframes_t pcm_wait (void);
61
int pcm_idle (snd_pcm_uframes_t len);
63
int play_init (snd_pcm_uframes_t len);
65
void play_chan (int chan, const float *src, snd_pcm_uframes_t len)
67
_play_ptr [chan] = _play_func (src, _play_ptr [chan], _play_step, len);
70
void clear_chan (int chan, snd_pcm_uframes_t len)
72
_play_ptr [chan] = _clear_func (_play_ptr [chan], _play_step, len);
75
int play_done (snd_pcm_uframes_t len)
77
return snd_pcm_mmap_commit (_play_handle, _play_offs, len);
80
int capt_init (snd_pcm_uframes_t len);
82
void capt_chan (int chan, float *dst, snd_pcm_uframes_t len)
84
_capt_ptr [chan] = _capt_func (_capt_ptr [chan], dst, _capt_step, len);
87
int capt_done (snd_pcm_uframes_t len)
89
return snd_pcm_mmap_commit (_capt_handle, _capt_offs, len);
92
int stat (void) { return _stat; }
93
int nplay (void) { return _play_nchan; }
94
int ncapt (void) { return _capt_nchan; }
95
snd_pcm_t *play_handle (void) { return _play_handle; }
96
snd_pcm_t *capt_handle (void) { return _capt_handle; }
101
typedef char *(*clear_function)(char *, int, int);
102
typedef char *(*play_function)(const float *, char *, int, int);
103
typedef const char *(*capt_function) (const char *, float *, int, int);
105
enum { MAXPFD = 16, MAXPLAY = 64, MAXCAPT = 64 };
107
void initialise (const char *play_name,
108
const char *capt_name,
109
const char *ctrl_name,
111
snd_pcm_uframes_t frsize,
112
unsigned int nfrags);
114
int set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int *nchan);
115
int set_swpar (snd_pcm_t *handle, snd_pcm_sw_params_t *swpar, const char *sname);
119
snd_pcm_uframes_t _frsize;
120
unsigned int _nfrags;
121
snd_pcm_t *_play_handle;
122
snd_pcm_t *_capt_handle;
123
snd_ctl_t *_ctrl_handle;
124
snd_pcm_hw_params_t *_play_hwpar;
125
snd_pcm_sw_params_t *_play_swpar;
126
snd_pcm_hw_params_t *_capt_hwpar;
127
snd_pcm_sw_params_t *_capt_swpar;
128
snd_pcm_format_t _play_format;
129
snd_pcm_format_t _capt_format;
130
snd_pcm_access_t _play_access;
131
snd_pcm_access_t _capt_access;
132
unsigned int _play_nchan;
133
unsigned int _capt_nchan;
137
struct pollfd _pfd [MAXPFD];
138
snd_pcm_uframes_t _capt_offs;
139
snd_pcm_uframes_t _play_offs;
142
char *_play_ptr [MAXPLAY];
143
const char *_capt_ptr [MAXCAPT];
147
clear_function _clear_func;
148
play_function _play_func;
149
capt_function _capt_func;
151
static char *clear_32le (char *dst, int step, int nfrm);
152
static char *clear_24le (char *dst, int step, int nfrm);
153
static char *clear_16le (char *dst, int step, int nfrm);
154
static char *play_32le (const float *src, char *dst, int step, int nfrm);
155
static char *play_24le (const float *src, char *dst, int step, int nfrm);
156
static char *play_16le (const float *src, char *dst, int step, int nfrm);
157
static const char *capt_32le (const char *src, float *dst, int step, int nfrm);
158
static const char *capt_24le (const char *src, float *dst, int step, int nfrm);
159
static const char *capt_16le (const char *src, float *dst, int step, int nfrm);