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

« back to all changes in this revision

Viewing changes to 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-2006 Fons Adriaensen <fons.adriaensen@skynet.be>
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        *name,
37
 
                 unsigned int       rate,
38
 
                 snd_pcm_uframes_t  frsize,
39
 
                 unsigned int       nfrags,
40
 
                 bool               play,
41
 
                 bool               capt,
42
 
                 bool               ctrl);
43
 
 
44
 
    ~Alsa_driver (void);  
45
 
 
46
 
    void printinfo (void);
47
 
 
48
 
    int pcm_start (void);
49
 
 
50
 
    int pcm_stop (void);
51
 
 
52
 
    snd_pcm_sframes_t pcm_wait (void);
53
 
 
54
 
    int pcm_idle (snd_pcm_uframes_t len);
55
 
 
56
 
    int play_init (snd_pcm_uframes_t len);
57
 
 
58
 
    void play_chan (int chan, const float *src, snd_pcm_uframes_t len)
59
 
    {
60
 
         _play_ptr [chan] = _play_func (src, _play_ptr [chan], _play_step, len);
61
 
    }
62
 
 
63
 
    void clear_chan (int chan, snd_pcm_uframes_t len)
64
 
    {
65
 
         _play_ptr [chan] = _clear_func (_play_ptr [chan], _play_step, len);
66
 
    }
67
 
 
68
 
    int play_done (snd_pcm_uframes_t len)
69
 
    {
70
 
        return snd_pcm_mmap_commit (_play_handle, _play_offs, len);
71
 
    }
72
 
 
73
 
    int capt_init (snd_pcm_uframes_t len);
74
 
 
75
 
    void capt_chan  (int chan, float *dst, snd_pcm_uframes_t len)
76
 
    {
77
 
         _capt_ptr [chan] = _capt_func  (_capt_ptr [chan], dst, _capt_step, len);
78
 
    }
79
 
 
80
 
    int capt_done (snd_pcm_uframes_t len)
81
 
    {
82
 
        return snd_pcm_mmap_commit (_capt_handle, _capt_offs, len);
83
 
    }
84
 
 
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; }
90
 
    
91
 
 
92
 
private:
93
 
 
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);
97
 
 
98
 
    enum { MAXPFD = 8, MAXPLAY = 32, MAXCAPT = 32 };
99
 
 
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);
102
 
    int recover (void);
103
 
 
104
 
    unsigned int           _rate;
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;
120
 
    int                    _play_npfd;
121
 
    int                    _capt_npfd;
122
 
    bool                   _synced;
123
 
    struct pollfd          _pfd [MAXPFD];
124
 
    snd_pcm_uframes_t      _capt_offs;
125
 
    snd_pcm_uframes_t      _play_offs;
126
 
    int                    _play_step;
127
 
    int                    _capt_step;
128
 
    char                  *_play_ptr [MAXPLAY];
129
 
    const char            *_capt_ptr [MAXCAPT];
130
 
    int                    _stat;
131
 
    int                    _pcnt;
132
 
    bool                   _xrun;
133
 
    clear_function         _clear_func;
134
 
    play_function          _play_func;
135
 
    capt_function          _capt_func;
136
 
 
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);
146
 
};
147
 
 
148
 
 
149
 
 
150
 
#endif
151