2
Copyright (C) 2003-2006 Fons Adriaensen <fons.adriaensen@skynet.be>
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 *name,
38
snd_pcm_uframes_t frsize,
46
void printinfo (void);
52
snd_pcm_sframes_t pcm_wait (void);
54
int pcm_idle (snd_pcm_uframes_t len);
56
int play_init (snd_pcm_uframes_t len);
58
void play_chan (int chan, const float *src, snd_pcm_uframes_t len)
60
_play_ptr [chan] = _play_func (src, _play_ptr [chan], _play_step, len);
63
void clear_chan (int chan, snd_pcm_uframes_t len)
65
_play_ptr [chan] = _clear_func (_play_ptr [chan], _play_step, len);
68
int play_done (snd_pcm_uframes_t len)
70
return snd_pcm_mmap_commit (_play_handle, _play_offs, len);
73
int capt_init (snd_pcm_uframes_t len);
75
void capt_chan (int chan, float *dst, snd_pcm_uframes_t len)
77
_capt_ptr [chan] = _capt_func (_capt_ptr [chan], dst, _capt_step, len);
80
int capt_done (snd_pcm_uframes_t len)
82
return snd_pcm_mmap_commit (_capt_handle, _capt_offs, len);
85
int stat (void) { return _stat; }
86
int nplay (void) { return _play_nchan; }
87
int ncapt (void) { return _capt_nchan; }
88
snd_pcm_t *play_handle (void) { return _play_handle; }
89
snd_pcm_t *capt_handle (void) { return _capt_handle; }
94
typedef char *(*clear_function)(char *, int, int);
95
typedef char *(*play_function)(const float *, char *, int, int);
96
typedef const char *(*capt_function) (const char *, float *, int, int);
98
enum { MAXPFD = 8, MAXPLAY = 32, MAXCAPT = 32 };
100
int set_hwpar (snd_pcm_t *handle, snd_pcm_hw_params_t *hwpar, const char *sname, unsigned int *nchan);
101
int set_swpar (snd_pcm_t *handle, snd_pcm_sw_params_t *swpar, const char *sname);
105
snd_pcm_uframes_t _frsize;
106
unsigned int _nfrags;
107
snd_pcm_format_t _play_format;
108
snd_pcm_format_t _capt_format;
109
snd_pcm_access_t _play_access;
110
snd_pcm_access_t _capt_access;
111
snd_pcm_t *_play_handle;
112
snd_pcm_t *_capt_handle;
113
snd_ctl_t *_ctrl_handle;
114
snd_pcm_hw_params_t *_play_hwpar;
115
snd_pcm_sw_params_t *_play_swpar;
116
snd_pcm_hw_params_t *_capt_hwpar;
117
snd_pcm_sw_params_t *_capt_swpar;
118
unsigned int _play_nchan;
119
unsigned int _capt_nchan;
123
struct pollfd _pfd [MAXPFD];
124
snd_pcm_uframes_t _capt_offs;
125
snd_pcm_uframes_t _play_offs;
128
char *_play_ptr [MAXPLAY];
129
const char *_capt_ptr [MAXCAPT];
133
clear_function _clear_func;
134
play_function _play_func;
135
capt_function _capt_func;
137
static char *clear_32le (char *dst, int step, int nfrm);
138
static char *clear_24le (char *dst, int step, int nfrm);
139
static char *clear_16le (char *dst, int step, int nfrm);
140
static char *play_32le (const float *src, char *dst, int step, int nfrm);
141
static char *play_24le (const float *src, char *dst, int step, int nfrm);
142
static char *play_16le (const float *src, char *dst, int step, int nfrm);
143
static const char *capt_32le (const char *src, float *dst, int step, int nfrm);
144
static const char *capt_24le (const char *src, float *dst, int step, int nfrm);
145
static const char *capt_16le (const char *src, float *dst, int step, int nfrm);