~ubuntu-branches/debian/stretch/clalsadrv/stretch

« back to all changes in this revision

Viewing changes to libs/clalsadrv.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-04-17 12:25:13 UTC
  • mfrom: (1.1.4 upstream) (2.1.4 experimental)
  • Revision ID: james.westby@ubuntu.com-20100417122513-vsy32s4vwo8vgzvs
Tags: 2.0.0-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
 
3
    
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
17
*/
 
18
 
 
19
 
 
20
#ifndef __CLALSADRV_H
 
21
#define __CLALSADRV_H
 
22
 
 
23
 
 
24
#define ALSA_PCM_NEW_HW_PARAMS_API
 
25
#define ALSA_PCM_NEW_SW_PARAMS_API
 
26
 
 
27
 
 
28
#include <alsa/asoundlib.h>
 
29
 
 
30
 
 
31
 
 
32
class Alsa_driver
 
33
{
 
34
public:
 
35
 
 
36
    Alsa_driver (const char        *play_name,
 
37
                 const char        *capt_name,
 
38
                 const char        *ctrl_name,
 
39
                 unsigned int       rate,
 
40
                 snd_pcm_uframes_t  frsize,
 
41
                 unsigned int       nfrags);
 
42
 
 
43
    Alsa_driver (const char        *name,
 
44
                 unsigned int       rate,
 
45
                 snd_pcm_uframes_t  frsize,
 
46
                 unsigned int       nfrags,
 
47
                 bool               play,
 
48
                 bool               capt,
 
49
                 bool               ctrl);
 
50
 
 
51
    ~Alsa_driver (void);  
 
52
 
 
53
    void printinfo (void);
 
54
 
 
55
    int pcm_start (void);
 
56
 
 
57
    int pcm_stop (void);
 
58
 
 
59
    snd_pcm_sframes_t pcm_wait (void);
 
60
 
 
61
    int pcm_idle (snd_pcm_uframes_t len);
 
62
 
 
63
    int play_init (snd_pcm_uframes_t len);
 
64
 
 
65
    void play_chan (int chan, const float *src, snd_pcm_uframes_t len)
 
66
    {
 
67
         _play_ptr [chan] = _play_func (src, _play_ptr [chan], _play_step, len);
 
68
    }
 
69
 
 
70
    void clear_chan (int chan, snd_pcm_uframes_t len)
 
71
    {
 
72
         _play_ptr [chan] = _clear_func (_play_ptr [chan], _play_step, len);
 
73
    }
 
74
 
 
75
    int play_done (snd_pcm_uframes_t len)
 
76
    {
 
77
        return snd_pcm_mmap_commit (_play_handle, _play_offs, len);
 
78
    }
 
79
 
 
80
    int capt_init (snd_pcm_uframes_t len);
 
81
 
 
82
    void capt_chan  (int chan, float *dst, snd_pcm_uframes_t len)
 
83
    {
 
84
         _capt_ptr [chan] = _capt_func  (_capt_ptr [chan], dst, _capt_step, len);
 
85
    }
 
86
 
 
87
    int capt_done (snd_pcm_uframes_t len)
 
88
    {
 
89
        return snd_pcm_mmap_commit (_capt_handle, _capt_offs, len);
 
90
    }
 
91
 
 
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; }
 
97
    
 
98
 
 
99
private:
 
100
 
 
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);
 
104
 
 
105
    enum { MAXPFD = 16, MAXPLAY = 64, MAXCAPT = 64 };
 
106
 
 
107
    void initialise (const char        *play_name,
 
108
                     const char        *capt_name,
 
109
                     const char        *ctrl_name,
 
110
                     unsigned int       rate,
 
111
                     snd_pcm_uframes_t  frsize,
 
112
                     unsigned int       nfrags);
 
113
 
 
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);
 
116
    int recover (void);
 
117
 
 
118
    unsigned int           _rate;
 
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;
 
134
    int                    _play_npfd;
 
135
    int                    _capt_npfd;
 
136
    bool                   _synced;
 
137
    struct pollfd          _pfd [MAXPFD];
 
138
    snd_pcm_uframes_t      _capt_offs;
 
139
    snd_pcm_uframes_t      _play_offs;
 
140
    int                    _play_step;
 
141
    int                    _capt_step;
 
142
    char                  *_play_ptr [MAXPLAY];
 
143
    const char            *_capt_ptr [MAXCAPT];
 
144
    int                    _stat;
 
145
    int                    _pcnt;
 
146
    bool                   _xrun;
 
147
    clear_function         _clear_func;
 
148
    play_function          _play_func;
 
149
    capt_function          _capt_func;
 
150
 
 
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);
 
160
};
 
161
 
 
162
 
 
163
 
 
164
#endif
 
165