1 /************************************************************************
3 IMPORTANT NOTE : this file contains two clearly delimited sections :
4 the ARCHITECTURE section (in two parts) and the USER section. Each section
5 is governed by its own copyright and license. Please check individually
6 each section for license and copyright information.
7 *************************************************************************/
9 /*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/
11 /************************************************************************
12 FAUST Architecture File
13 Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
14 ---------------------------------------------------------------------
15 This Architecture section is free software; you can redistribute it
16 and/or modify it under the terms of the GNU General Public License
17 as published by the Free Software Foundation; either version 3 of
18 the License, or (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; If not, see <http://www.gnu.org/licenses/>.
28 EXCEPTION : As a special exception, you may create a larger work
29 that contains this FAUST architecture section and distribute
30 that work under terms of your choice, so long as this FAUST
31 architecture section is not modified.
34 ************************************************************************
35 ************************************************************************/
37 #ifndef __netjack_dsp__
38 #define __netjack_dsp__
45 class netjackaudio
: public audio
{
48 jack_net_slave_t
* fNet
;
50 std::string fMasterIP
;
53 static void net_shutdown(void *)
55 printf("Network failure, restart...\n");
58 static int net_process(jack_nframes_t buffer_size
,
60 float** audio_input_buffer
,
64 float** audio_output_buffer
,
70 netjackaudio
* obj
= (netjackaudio
*)arg
;
71 obj
->fDsp
->compute(buffer_size
, audio_input_buffer
, audio_output_buffer
);
77 netjackaudio(int celt
, const std::string master_ip
, int master_port
)
78 :fCelt(celt
), fMasterIP(master_ip
), fMasterPort(master_port
)
81 bool init(const char* name
, dsp
* DSP
)
84 jack_slave_t request
= {
90 (fCelt
> 0) ? JackCeltEncoder
: JackFloatEncoder
,
91 (fCelt
> 0) ? fCelt
: 0,
96 if ((fNet
= jack_net_slave_open(fMasterIP
.c_str(), fMasterPort
, name
, &request
, &result
)) == 0) {
97 printf("jack remote server not running ?\n");
101 jack_set_net_slave_process_callback(fNet
, net_process
, this);
102 jack_set_net_slave_shutdown_callback(fNet
, net_shutdown
, 0);
104 fDsp
->init(result
.sample_rate
);
110 if (jack_net_slave_activate(fNet
)) {
111 printf("cannot activate net");
119 jack_net_slave_deactivate(fNet
);
120 jack_net_slave_close(fNet
);
129 /********************END ARCHITECTURE SECTION (part 2/2)****************/