2
Copyright (C) 2006-2010 Fons Adriaensen <fons@linuxaudio.org>
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.
25
//-------------------------------------------------------------------------------------------------------
28
Jclient::Jclient (const char *jname) :
39
Jclient::~Jclient (void)
41
if (_jack_client) close_jack ();
45
void Jclient::init_jack (void)
50
if ((_jack_client = jack_client_open (_jname, (jack_options_t) 0, &s)) == 0)
52
fprintf (stderr, "Can't connect to JACK\n");
56
jack_set_process_callback (_jack_client, jack_static_process, (void *) this);
57
jack_on_shutdown (_jack_client, jack_static_shutdown, (void *) this);
59
for (i = 0; i < 8; i++)
61
_jack_ipports [i] = jack_port_register (_jack_client, ipp_names [i], JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
63
for (i = 0; i < 10; i++)
65
_jack_opports [i] = jack_port_register (_jack_client, opp_names [i], JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
68
if (jack_activate (_jack_client))
70
fprintf(stderr, "Can't activate JACK.\n");
74
_jname = jack_get_client_name (_jack_client);
75
_fsamp = jack_get_sample_rate (_jack_client);
76
_fsize = jack_get_buffer_size (_jack_client);
82
void Jclient::close_jack ()
84
jack_deactivate (_jack_client);
85
jack_client_close (_jack_client);
89
void Jclient::jack_static_shutdown (void *arg)
91
return ((Jclient *) arg)->jack_shutdown ();
95
void Jclient::jack_shutdown (void)
97
send_event (EV_EXIT, 1);
101
int Jclient::jack_static_process (jack_nframes_t nframes, void *arg)
103
return ((Jclient *) arg)->jack_process (nframes);
107
void Jclient::init_proc ()
114
_dvoldb = 200.0f * _fsize / _fsamp;
115
_abproc.init (_fsamp, _fsize, _psize);
116
_virtmic.set_fsam (_fsamp);
117
Kmeterdsp::init (_fsamp, _fsize, 0.5f, 15.0f);
121
int Jclient::jack_process (jack_nframes_t nframes)
124
float *p [4], *q [4];
126
switch (e = get_event_nowait ())
138
if (nframes != _fsize) return 0;
140
for (j = 0; j < 4; j++)
142
p [j] = (float *) jack_port_get_buffer (_jack_ipports [j], nframes);
143
q [j] = (float *) jack_port_get_buffer (_jack_opports [j], nframes);
146
if (_state == S_IDLE || _abproc.cerror ())
148
for (j = 0; j < 4; j++)
150
if (_meter == METER_INP) _kmdsp [j].reset ();
151
memset (q [j], 0, nframes * sizeof (float));
156
if (_meter == METER_INP) measure (nframes, p);
157
_abproc.process (nframes, p, q);
159
monitor (nframes, q);
165
void Jclient::monitor (unsigned int n, float *p [4])
168
float g, d, t, *q [4];
170
// Select monitor source.
171
for (j = 0; j < 4; j++)
173
if (_monit == MONIT_EXT) p [j] = (float *) jack_port_get_buffer (_jack_ipports [4 + j], n);
174
q [j] = (float *) jack_port_get_buffer (_jack_opports [4 + j], n);
177
// Update level meters.
178
if (_meter == METER_MON) measure (n, p);
180
// Check volume change.
182
d = _voldb1 - _voldb0;
183
if (fabsf (d) > 0.1f)
185
if (d > _dvoldb) d = _dvoldb;
186
else if (d < -_dvoldb) d = -_dvoldb;
188
t = (_voldb0 < -80.0f) ? 0 : powf (10.0f, 0.05f * _voldb0);
189
d = (t - g) / _fsize + 1e-30f;
195
for (i = 0; i < n; i++)
198
q [0][i] = p [0][i] * g;
199
q [1][i] = p [1][i] * g;
200
q [2][i] = p [2][i] * g;
201
q [3][i] = p [3][i] * g;
204
// Create stereo output.
205
_virtmic.process (n, q [0], q [1], q [2], q [3],
206
(float *) jack_port_get_buffer (_jack_opports [8], n),
207
(float *) jack_port_get_buffer (_jack_opports [9], n));
211
void Jclient::measure (unsigned int n, float *p [4])
215
for (i = 0; i < 4; i++)
217
_kmdsp [i].process (p [i], n);
222
//-------------------------------------------------------------------------------------------------------
225
const char *Jclient::ipp_names [8] =
238
const char *Jclient::opp_names [10] =
253
//-------------------------------------------------------------------------------------------------------