2 Copyright (C) 2009 Grame
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.
32 jack_net_slave_t
* net
;
34 static void signal_handler(int sig
)
36 jack_net_slave_close(net
);
37 fprintf(stderr
, "signal received, exiting ...\n");
45 "usage: jack_net_slave \n"
46 " [ -C capture channels (default = 2)]\n"
47 " [ -P playback channels (default = 2) ]\n"
48 " [ -a hostname (default = %s) ]\n"
49 " [ -p port (default = %d)]\n", DEFAULT_MULTICAST_IP
, DEFAULT_PORT
);
52 static void net_shutdown(void* data
)
54 printf("Restarting...\n");
57 static int net_process(jack_nframes_t buffer_size
,
59 float** audio_input_buffer
,
61 void** midi_input_buffer
,
63 float** audio_output_buffer
,
65 void** midi_output_buffer
,
70 // Copy input to output
71 for (i
= 0; i
< audio_input
; i
++) {
72 memcpy(audio_output_buffer
[i
], audio_input_buffer
[i
], buffer_size
* sizeof(float));
78 main (int argc
, char *argv
[])
82 int udp_port
= DEFAULT_PORT
;
83 const char* multicast_ip
= DEFAULT_MULTICAST_IP
;
84 const char *options
= "C:P:a:p:h";
88 struct option long_options
[] =
90 {"audio input", 1, 0, 'C'},
91 {"audio output", 1, 0, 'P'},
92 {"hostname", 1, 0, 'a'},
97 while ((opt
= getopt_long (argc
, argv
, options
, long_options
, &option_index
)) != EOF
) {
102 audio_input
= atoi(optarg
);
106 audio_output
= atoi(optarg
);
110 multicast_ip
= strdup(optarg
);
114 udp_port
= atoi(optarg
);
123 jack_slave_t request
= { audio_input
, audio_output
, 0, 0, DEFAULT_MTU
, -1, JackFloatEncoder
, 0, 2 };
124 jack_master_t result
;
126 printf("Waiting for a master...\n");
128 if ((net
= jack_net_slave_open(multicast_ip
, udp_port
, "net_slave", &request
, &result
)) == 0) {
129 fprintf(stderr
, "JACK server not running?\n");
133 printf("Master is found and running...\n");
135 jack_set_net_slave_process_callback(net
, net_process
, NULL
);
136 jack_set_net_slave_shutdown_callback(net
, net_shutdown
, NULL
);
138 if (jack_net_slave_activate(net
) != 0) {
139 fprintf(stderr
, "Cannot activate slave client\n");
143 /* install a signal handler to properly quits jack client */
145 signal(SIGINT
, signal_handler
);
146 signal(SIGABRT
, signal_handler
);
147 signal(SIGTERM
, signal_handler
);
149 signal(SIGQUIT
, signal_handler
);
150 signal(SIGTERM
, signal_handler
);
151 signal(SIGHUP
, signal_handler
);
152 signal(SIGINT
, signal_handler
);
155 /* run until interrupted */
164 // Wait for application end
165 jack_net_slave_deactivate(net
);
166 jack_net_slave_close(net
);