File: audio.h

package info (click to toggle)
aeolus 0.8.4-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 536 kB
  • ctags: 1,478
  • sloc: cpp: 9,335; makefile: 56
file content (157 lines) | stat: -rw-r--r-- 3,912 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
    Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/


#ifndef __AUDIO_H
#define __AUDIO_H


#include <stdlib.h>
#include <clthreads.h>
#ifdef __linux__
#include <clalsadrv.h>
#endif
#include <jack/jack.h>
#include "asection.h"
#include "division.h"
#include "lfqueue.h"
#include "reverb.h"
#include "global.h"


class Audio : public A_thread
{
public:

    Audio (const char *jname, Lfq_u32 *qnote, Lfq_u32 *qcomm);
    virtual ~Audio (void);
#ifdef __linux__
    void  init_alsa (const char *device, int fsamp, int fsize, int nfrag);
#endif
    void  init_jack (const char *server, bool bform, Lfq_u8 *qmidi);
    void  start (void);

    const char  *appname (void) const { return _appname; }
    uint16_t    *midimap (void) const { return (uint16_t *) _midimap; }
    int  policy (void) const { return _policy; }
    int  abspri (void) const { return _abspri; }
    int  relpri (void) const { return _relpri; }

private:
   
    enum { VOLUME, REVSIZE, REVTIME, STPOSIT };

    void init_audio (void);
#ifdef __linux__
    void close_alsa (void);
#endif
    void close_jack (void);
    virtual void thr_main (void);
    void jack_shutdown (void);
    int  jack_callback (jack_nframes_t);
    void proc_jmidi (int);
    void proc_queue (Lfq_u32 *);
    void proc_synth (int);
    void proc_keys1 (void);
    void proc_keys2 (void);
    void proc_mesg (void);

    void key_off (int n, int b)
    {
        _keymap [n] &= ~b;
        _keymap [n] |= 128;
    }

    void key_on (int n, int b)
    {
        _keymap [n] |= b | 128;
    }

    void cond_key_off (int m, int b)
    {
	int            i;
	unsigned char  *p;

	for (i = 0, p = _keymap; i < NNOTES; i++, p++)
	{
            if (*p & m)
	    {
                *p &= ~b;
		*p |= 128;
	    }
	}
    }

    void cond_key_on (int m, int b)
    {
	int            i;
	unsigned char  *p;

	for (i = 0, p = _keymap; i < NNOTES; i++, p++)
	{
            if (*p & m)
	    {
                *p |= b | 128;
	    }
	}
    }

    static void jack_static_shutdown (void *);
    static int  jack_static_callback (jack_nframes_t, void *);

    const char     *_appname;
    uint16_t        _midimap [16];
    Lfq_u32        *_qnote; 
    Lfq_u32        *_qcomm; 
    Lfq_u8         *_qmidi;
    volatile bool   _running;
#ifdef __linux__
    Alsa_driver    *_alsa_handle;
#endif
    jack_client_t  *_jack_handle;
    jack_port_t    *_jack_opport [8];
    jack_port_t    *_jack_midipt;
    int             _policy;
    int             _abspri;
    int             _relpri;
    int             _jmidi_count;
    int             _jmidi_index;
    void           *_jmidi_pdata;
    int             _hold;
    bool            _bform;
    int             _nplay;
    unsigned int    _fsamp;
    unsigned int    _fsize;
    int             _nasect;
    int             _ndivis;
    Asection       *_asectp [NASECT];
    Division       *_divisp [NDIVIS];
    Reverb          _reverb;
    float          *_outbuf [8];
    unsigned char   _keymap [NNOTES];
    Fparm           _audiopar [4];
    float           _revsize;
    float           _revtime;

    static const char *_ports_stereo [2];
    static const char *_ports_ambis1 [4];
};


#endif