Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16986
Modified Files: Tag: desiredata s_audio_jack.c Log Message: more cleanup
Index: s_audio_jack.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_audio_jack.c,v retrieving revision 1.5.4.8.2.7.2.3 retrieving revision 1.5.4.8.2.7.2.4 diff -C2 -d -r1.5.4.8.2.7.2.3 -r1.5.4.8.2.7.2.4 *** s_audio_jack.c 28 Jun 2007 09:02:32 -0000 1.5.4.8.2.7.2.3 --- s_audio_jack.c 28 Jun 2007 09:08:36 -0000 1.5.4.8.2.7.2.4 *************** *** 103,107 **** sys_dacblocksize); } - /* run dsp */ sched_tick(sys_time + sys_time_per_dsp_tick); --- 103,106 ---- *************** *** 109,119 **** for (j = 0; j < sys_outchannels; j++) { t_sample * out = jack_port_get_buffer (output_port[j], nframes); ! copyblock(out + i * sys_dacblocksize, ! sys_soundout + j * sys_dacblocksize, ! sys_dacblocksize); } /* update peak meters */ ! if (sys_meters) ! sys_peakmeters(); /* clear the output buffer */ zeroblock(sys_soundout, j * sys_dacblocksize); --- 108,115 ---- for (j = 0; j < sys_outchannels; j++) { t_sample * out = jack_port_get_buffer (output_port[j], nframes); ! copyblock(out + i * sys_dacblocksize, sys_soundout + j * sys_dacblocksize, sys_dacblocksize); } /* update peak meters */ ! if (sys_meters) sys_peakmeters(); /* clear the output buffer */ zeroblock(sys_soundout, j * sys_dacblocksize); *************** *** 124,129 **** }
- - static int jack_srate (jack_nframes_t srate, void *arg) { sys_dacsr = srate; --- 120,123 ---- *************** *** 131,135 **** }
- static int jack_ignore_graph_callback = 0; static t_int jack_shutdown_handler(t_int* none) { --- 125,128 ---- *************** *** 138,146 **** /* clean up */ jack_close_audio(); - /* try to reconnect to jack server */ ! jack_open_audio(sys_inchannels, sys_outchannels,\ ! sys_dacsr, jack_scheduler); ! /* restore last connection state */ jack_restore_connection_state(); --- 131,136 ---- /* clean up */ jack_close_audio(); /* try to reconnect to jack server */ ! jack_open_audio(sys_inchannels, sys_outchannels, sys_dacsr, jack_scheduler); /* restore last connection state */ jack_restore_connection_state(); *************** *** 166,172 **** jack_ports = jack_get_ports( jack_client, "", "", 0 ); regcomp( &port_regex, "^[^:]*", REG_EXTENDED ); - jack_client_names[0] = NULL; - /* Build a list of clients from the list of ports */ for (i=0; jack_ports[i] != NULL; i++) { --- 156,160 ---- *************** *** 174,200 **** regmatch_t match_info; char tmp_client_name[100]; ! ! /* extract the client name from the port name, using a regex ! * that parses the clientname:portname syntax */ regexec( &port_regex, jack_ports[i], 1, &match_info, 0 ); memcpy( tmp_client_name, &jack_ports[i][match_info.rm_so], match_info.rm_eo - match_info.rm_so ); tmp_client_name[ match_info.rm_eo - match_info.rm_so ] = '\0'; - /* do we know about this port's client yet? */ client_seen = 0; ! ! for( j = 0; j < num_clients; j++ ) if( strcmp( tmp_client_name, jack_client_names[j] ) == 0 ) client_seen = 1; - if (!client_seen) { jack_client_names[num_clients] = (char*)getbytes(strlen(tmp_client_name) + 1); - /* The alsa_pcm client should go in spot 0. If this * is the alsa_pcm client AND we are NOT about to put * it in spot 0 put it in spot 0 and move whatever * was already in spot 0 to the end. */ - if (strcmp( "alsa_pcm", tmp_client_name ) == 0 && num_clients > 0) { char* tmp; --- 162,181 ---- regmatch_t match_info; char tmp_client_name[100]; ! /* extract the client name from the port name, using a regex that parses the clientname:portname syntax */ regexec( &port_regex, jack_ports[i], 1, &match_info, 0 ); memcpy( tmp_client_name, &jack_ports[i][match_info.rm_so], match_info.rm_eo - match_info.rm_so ); tmp_client_name[ match_info.rm_eo - match_info.rm_so ] = '\0'; /* do we know about this port's client yet? */ client_seen = 0; ! for (j = 0; j < num_clients; j++) if( strcmp( tmp_client_name, jack_client_names[j] ) == 0 ) client_seen = 1; if (!client_seen) { jack_client_names[num_clients] = (char*)getbytes(strlen(tmp_client_name) + 1); /* The alsa_pcm client should go in spot 0. If this * is the alsa_pcm client AND we are NOT about to put * it in spot 0 put it in spot 0 and move whatever * was already in spot 0 to the end. */ if (strcmp( "alsa_pcm", tmp_client_name ) == 0 && num_clients > 0) { char* tmp; *************** *** 209,229 **** } num_clients++; - } } ! ! /* for (i=0;i<num_clients;i++) post("client: %s",jack_client_names[i]); */ ! ! free( jack_ports ); return jack_client_names; }
! /* ! * Wire up all the ports of one client. ! * ! */ ! ! static int jack_connect_ports(char* client) { ! char regex_pattern[100]; /* its always the same, ... */ int i; const char **jack_ports; --- 190,203 ---- } num_clients++; } } ! /* for (i=0;i<num_clients;i++) post("client: %s",jack_client_names[i]); */ ! free(jack_ports); return jack_client_names; }
! /* Wire up all the ports of one client. */ ! static int jack_connect_ports(char *client) { ! char regex_pattern[100]; /* its always the same, ... */ int i; const char **jack_ports; *************** *** 295,378 **** } jack_get_clients(); ! /* tell the JACK server to call `process()' whenever ! there is work to be done. ! tb: adapted for callback based scheduling ! */ ! if (scheduler == 1) { ! dspticks_per_jacktick = jack_get_buffer_size(jack_client) ! / sys_schedblocksize; ! jack_set_process_callback (jack_client, cb_process, 0); ! } else jack_set_process_callback (jack_client, process, 0); ! ! jack_set_error_function (jack_error); #ifdef JACK_XRUN ! jack_set_xrun_callback (jack_client, jack_xrun, NULL); #endif ! jack_set_graph_order_callback(jack_client, jack_graph_order_callback, NULL); ! /* tell the JACK server to call `srate()' whenever the sample rate of the system changes. */ ! jack_set_sample_rate_callback (jack_client, jack_srate, 0); ! /* tell the JACK server to call `jack_shutdown()' if ! it ever shuts down, either entirely, or if it just decides to stop calling us. */ ! jack_on_shutdown (jack_client, jack_shutdown, 0); ! for (j=0;j<NUM_JACK_PORTS;j++) { ! input_port[j]=NULL; ! output_port[j] = NULL; ! } ! new_jack = 1; ! } ! /* display the current sample rate. once the client is activated ! (see below), you should rely on your own sample rate callback (see above) for this value. */ ! srate = jack_get_sample_rate (jack_client); ! sys_dacsr = srate; ! ! /* create the ports */ ! for (j = 0; j < inchans; j++) { ! sprintf(port_name, "input%d", j); ! if (!input_port[j]) input_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); ! } ! for (j = 0; j < outchans; j++) { ! sprintf(port_name, "output%d", j); ! if (!output_port[j]) output_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); } ! outport_count = outchans; ! ! /* tell the JACK server that we are ready to roll */ ! if (new_jack) { ! if (jack_activate (jack_client)) { fprintf (stderr, "cannot activate client\n"); sys_inchannels = sys_outchannels = 0; ret = 1; ! goto bailout; ! } ! memset(jack_outbuf,0,sizeof(jack_outbuf)); ! if (jack_client_names[0]) jack_connect_ports(jack_client_names[0]); ! pthread_mutex_init(&jack_mutex,NULL); ! pthread_cond_init(&jack_sem,NULL); } ! /* tb: get advance from jack server */ ! sys_schedadvance = (float)jack_port_get_total_latency(jack_client,output_port[0]) * 1000. / sys_dacsr * 1000; ! return 0; bailout: ! /* tb: if we can't start jack, go to traditional scheduler */ ! sys_setscheduler(0); ! return ret; }
void jack_close_audio(void) { ! if (jack_client) { ! int i; ! jack_deactivate(jack_client); ! jack_started = 0; ! jack_client_close(jack_client); ! jack_client = NULL; ! for (i = 0; i <NUM_JACK_PORTS; i++) { ! input_port[i] = NULL; ! output_port[i] = NULL; ! } } }
int jack_send_dacs(void) { ! float * fp; int j; int rtnval = SENDDACS_YES; --- 269,346 ---- } jack_get_clients(); ! /* tell the JACK server to call `process()' whenever there is work to be done. ! tb: adapted for callback based scheduling */ ! if (scheduler == 1) { ! dspticks_per_jacktick = jack_get_buffer_size(jack_client) / sys_schedblocksize; ! jack_set_process_callback (jack_client, cb_process, 0); ! } else jack_set_process_callback (jack_client, process, 0); ! jack_set_error_function (jack_error); #ifdef JACK_XRUN ! jack_set_xrun_callback (jack_client, jack_xrun, NULL); #endif ! jack_set_graph_order_callback(jack_client, jack_graph_order_callback, NULL); ! /* tell the JACK server to call `srate()' whenever the sample rate of the system changes. */ ! jack_set_sample_rate_callback (jack_client, jack_srate, 0); ! /* tell the JACK server to call `jack_shutdown()' if ! it ever shuts down, either entirely, or if it just decides to stop calling us. */ ! jack_on_shutdown (jack_client, jack_shutdown, 0); ! for (j=0;j<NUM_JACK_PORTS;j++) { ! input_port[j]=NULL; ! output_port[j] = NULL; } ! new_jack = 1; ! } ! /* display the current sample rate. once the client is activated ! (see below), you should rely on your own sample rate callback (see above) for this value. */ ! srate = jack_get_sample_rate (jack_client); ! sys_dacsr = srate; ! /* create the ports */ ! for (j = 0; j < inchans; j++) { ! sprintf(port_name, "input%d", j); ! if (!input_port[j]) input_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); ! } ! for (j = 0; j < outchans; j++) { ! sprintf(port_name, "output%d", j); ! if (!output_port[j]) output_port[j] = jack_port_register (jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); ! } ! outport_count = outchans; ! /* tell the JACK server that we are ready to roll */ ! if (new_jack) { ! if (jack_activate (jack_client)) { fprintf (stderr, "cannot activate client\n"); sys_inchannels = sys_outchannels = 0; ret = 1; ! goto bailout; } ! memset(jack_outbuf,0,sizeof(jack_outbuf)); ! if (jack_client_names[0]) jack_connect_ports(jack_client_names[0]); ! pthread_mutex_init(&jack_mutex,NULL); ! pthread_cond_init(&jack_sem,NULL); ! } ! /* tb: get advance from jack server */ ! sys_schedadvance = (float)jack_port_get_total_latency(jack_client,output_port[0]) * 1000. / sys_dacsr * 1000; ! return 0; bailout: ! /* tb: if we can't start jack, go to traditional scheduler */ ! sys_setscheduler(0); ! return ret; }
void jack_close_audio(void) { ! if (jack_client) { ! int i; ! jack_deactivate(jack_client); ! jack_started = 0; ! jack_client_close(jack_client); ! jack_client = NULL; ! for (i = 0; i <NUM_JACK_PORTS; i++) { ! input_port[i] = NULL; ! output_port[i] = NULL; } + } }
int jack_send_dacs(void) { ! float *fp; int j; int rtnval = SENDDACS_YES; *************** *** 423,427 **** }
- /* ports connected to the inputs */ static const char ** jack_in_connections[NUM_JACK_PORTS]; --- 391,394 ----