00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include <errno.h>
00022 #include <unistd.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025
00026 #include <jack/jack.h>
00027
00028 jack_port_t *input_port;
00029 jack_port_t *output_port;
00030 jack_client_t *client;
00031
00032
00033 volatile enum {
00034 Init,
00035 Run,
00036 Exit
00037 } client_state = Init;
00038
00046 int
00047 process (jack_nframes_t nframes, void *arg)
00048 {
00049 jack_default_audio_sample_t *in, *out;
00050 jack_transport_state_t ts = jack_transport_query(client, NULL);
00051
00052 if (ts == JackTransportRolling) {
00053
00054 if (client_state == Init)
00055 client_state = Run;
00056
00057 in = jack_port_get_buffer (input_port, nframes);
00058 out = jack_port_get_buffer (output_port, nframes);
00059 memcpy (out, in,
00060 sizeof (jack_default_audio_sample_t) * nframes);
00061
00062 } else if (ts == JackTransportStopped) {
00063
00064 if (client_state == Run)
00065 client_state = Exit;
00066 }
00067
00068 return 0;
00069 }
00070
00075 void
00076 jack_shutdown (void *arg)
00077 {
00078 exit (1);
00079 }
00080
00081 int
00082 main (int argc, char *argv[])
00083 {
00084 const char **ports;
00085 const char *client_name;
00086 const char *server_name = NULL;
00087 jack_options_t options = JackNullOption;
00088 jack_status_t status;
00089
00090 if (argc >= 2) {
00091 client_name = argv[1];
00092 if (argc >= 3) {
00093 server_name = argv[2];
00094 options |= JackServerName;
00095 }
00096 } else {
00097 client_name = strrchr(argv[0], '/');
00098 if (client_name == 0) {
00099 client_name = argv[0];
00100 } else {
00101 client_name++;
00102 }
00103 }
00104
00105
00106
00107 client = jack_client_open (client_name, options, &status, server_name);
00108 if (client == NULL) {
00109 fprintf (stderr, "jack_client_open() failed, "
00110 "status = 0x%2.0x\n", status);
00111 if (status & JackServerFailed) {
00112 fprintf (stderr, "Unable to connect to JACK server\n");
00113 }
00114 exit (1);
00115 }
00116 if (status & JackServerStarted) {
00117 fprintf (stderr, "JACK server started\n");
00118 }
00119 if (status & JackNameNotUnique) {
00120 client_name = jack_get_client_name(client);
00121 fprintf (stderr, "unique name `%s' assigned\n", client_name);
00122 }
00123
00124
00125
00126
00127
00128 jack_set_process_callback (client, process, 0);
00129
00130
00131
00132
00133
00134
00135 jack_on_shutdown (client, jack_shutdown, 0);
00136
00137
00138
00139
00140 printf ("engine sample rate: %" PRIu32 "\n",
00141 jack_get_sample_rate (client));
00142
00143
00144
00145 input_port = jack_port_register (client, "input",
00146 JACK_DEFAULT_AUDIO_TYPE,
00147 JackPortIsInput, 0);
00148 output_port = jack_port_register (client, "output",
00149 JACK_DEFAULT_AUDIO_TYPE,
00150 JackPortIsOutput, 0);
00151
00152 if ((input_port == NULL) || (output_port == NULL)) {
00153 fprintf(stderr, "no more JACK ports available\n");
00154 exit (1);
00155 }
00156
00157
00158
00159
00160 if (jack_activate (client)) {
00161 fprintf (stderr, "cannot activate client");
00162 exit (1);
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 ports = jack_get_ports (client, NULL, NULL,
00174 JackPortIsPhysical|JackPortIsOutput);
00175 if (ports == NULL) {
00176 fprintf(stderr, "no physical capture ports\n");
00177 exit (1);
00178 }
00179
00180 if (jack_connect (client, ports[0], jack_port_name (input_port))) {
00181 fprintf (stderr, "cannot connect input ports\n");
00182 }
00183
00184 free (ports);
00185
00186 ports = jack_get_ports (client, NULL, NULL,
00187 JackPortIsPhysical|JackPortIsInput);
00188 if (ports == NULL) {
00189 fprintf(stderr, "no physical playback ports\n");
00190 exit (1);
00191 }
00192
00193 if (jack_connect (client, jack_port_name (output_port), ports[0])) {
00194 fprintf (stderr, "cannot connect output ports\n");
00195 }
00196
00197 free (ports);
00198
00199
00200
00201 while (client_state != Exit) {
00202 sleep (1);
00203 }
00204
00205 jack_client_close (client);
00206 exit (0);
00207 }