[PD-cvs] pd/src s_audio_jack.c,1.5.4.1,1.5.4.2

Tim Blechmann timblech at users.sourceforge.net
Sun Feb 27 13:06:54 CET 2005


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29602

Modified Files:
      Tag: devel_0_38
	s_audio_jack.c 
Log Message:
wait in pd's scheduler instead of waiting for a conditional
indenting to match pd's coding style 

Index: s_audio_jack.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_audio_jack.c,v
retrieving revision 1.5.4.1
retrieving revision 1.5.4.2
diff -C2 -d -r1.5.4.1 -r1.5.4.2
*** s_audio_jack.c	10 Nov 2004 13:47:09 -0000	1.5.4.1
--- s_audio_jack.c	27 Feb 2005 12:06:52 -0000	1.5.4.2
***************
*** 35,72 ****
  pthread_cond_t jack_sem;
  
- 
  static int
  process (jack_nframes_t nframes, void *arg)
  {
!         int j;
!         float *out; 
!         float *in;
          
          
!         if (nframes > JACK_OUT_MAX) jack_out_max = nframes;
!         else jack_out_max = JACK_OUT_MAX;
!         if (jack_filled >= nframes) {
!                 if (jack_filled != nframes) fprintf(stderr,"Partial read");
  
!                 for (j = 0; j < sys_outchannels;  j++) {
!                         out = jack_port_get_buffer (output_port[j], nframes);
!                         memcpy(out, jack_outbuf + (j * BUF_JACK), sizeof (float) * nframes);
!                 }
!                 for (j = 0; j < sys_inchannels; j++) {
!                         in = jack_port_get_buffer( input_port[j], nframes);
!                         memcpy(jack_inbuf + (j * BUF_JACK), in, sizeof (float) * nframes);
!                 }
!                 jack_filled -= nframes;
!         } else { /* PD could not keep up ! */
!              if (jack_started) jack_dio_error = 1;
!              for (j = 0; j < outport_count;  j++) {
!                   out = jack_port_get_buffer (output_port[j], nframes);
!                   memset(out, 0, sizeof (float) * nframes); 
!              }
!              memset(jack_outbuf,0,sizeof(jack_outbuf));
!              jack_filled = 0;
!         }
!         pthread_cond_broadcast(&jack_sem);
!         return 0;
  }
  
--- 35,72 ----
  pthread_cond_t jack_sem;
  
  static int
  process (jack_nframes_t nframes, void *arg)
  {
! 	int j;
! 	float *out; 
! 	float *in;
          
          
! 	if (nframes > JACK_OUT_MAX) jack_out_max = nframes;
! 	else jack_out_max = JACK_OUT_MAX;
! 	if (jack_filled >= nframes) {
! 		if (jack_filled != nframes) fprintf(stderr,"Partial read");
  
! 		for (j = 0; j < sys_outchannels;  j++) {
! 			out = jack_port_get_buffer (output_port[j], nframes);
! 			memcpy(out, jack_outbuf + (j * BUF_JACK), sizeof (float) * nframes);
! 		}
! 		for (j = 0; j < sys_inchannels; j++) {
! 			in = jack_port_get_buffer( input_port[j], nframes);
! 			memcpy(jack_inbuf + (j * BUF_JACK), in, sizeof (float) * nframes);
! 		}
! 		jack_filled -= nframes;
! 	} else { /* PD could not keep up ! */
! 		if (jack_started) jack_dio_error = 1;
! 		for (j = 0; j < outport_count;  j++) {
! 			out = jack_port_get_buffer (output_port[j], nframes);
! 			memset(out, 0, sizeof (float) * nframes); 
! 		}
! 		memset(jack_outbuf,0,sizeof(jack_outbuf));
! 		jack_filled = 0;
! 	}
! 	/* tb: wait in the scheduler
! 	 * pthread_cond_broadcast(&jack_sem); */
! 	return 0;
  }
  
***************
*** 74,79 ****
  jack_srate (jack_nframes_t srate, void *arg)
  {
!         sys_dacsr = srate;
!         return 0;
  }
  
--- 74,79 ----
  jack_srate (jack_nframes_t srate, void *arg)
  {
! 	sys_dacsr = srate;
! 	return 0;
  }
  
***************
*** 81,91 ****
  jack_shutdown (void *arg)
  {
!         /* Ignore for now */
!   //    exit (1);
  }
  
  static int jack_xrun(void* arg) {
!   jack_dio_error = 1;
!   return 0;
  }
  
--- 81,91 ----
  jack_shutdown (void *arg)
  {
! 	/* Ignore for now */
! 	//    exit (1);
  }
  
  static int jack_xrun(void* arg) {
! 	jack_dio_error = 1;
! 	return 0;
  }
  
***************
*** 134,143 ****
              if( strcmp( "alsa_pcm", tmp_client_name ) == 0 && num_clients > 0 )
              {
!               char* tmp;
                  /* alsa_pcm goes in spot 0 */
!               tmp = jack_client_names[ num_clients ];
!               jack_client_names[ num_clients ] = jack_client_names[0];
!               jack_client_names[0] = tmp;
!               strcpy( jack_client_names[0], tmp_client_name);
              }
              else
--- 134,143 ----
              if( strcmp( "alsa_pcm", tmp_client_name ) == 0 && num_clients > 0 )
              {
! 				char* tmp;
                  /* alsa_pcm goes in spot 0 */
! 				tmp = jack_client_names[ num_clients ];
! 				jack_client_names[ num_clients ] = jack_client_names[0];
! 				jack_client_names[0] = tmp;
! 				strcpy( jack_client_names[0], tmp_client_name);
              }
              else
***************
*** 164,200 ****
  static int jack_connect_ports(char* client)
  {
!   char  regex_pattern[100]; /* its always the same, ... */
!   int i;
!   const char **jack_ports;
      
!   if (strlen(client) > 96)  return -1;
  
!   sprintf( regex_pattern, "%s:.*", client );
  
!   jack_ports = jack_get_ports( jack_client, regex_pattern,
!                                NULL, JackPortIsOutput);
!   if (jack_ports) 
!     for (i=0;jack_ports[i] != NULL && i < sys_inchannels;i++)      
!       if (jack_connect (jack_client, jack_ports[i], jack_port_name (input_port[i]))) 
!         fprintf (stderr, "cannot connect input ports %s -> %s\n", jack_ports[i],jack_port_name (input_port[i]));
        
    
    
!   jack_ports = jack_get_ports( jack_client, regex_pattern,
!                                NULL, JackPortIsInput);
!   if (jack_ports) 
!     for (i=0;jack_ports[i] != NULL && i < sys_outchannels;i++)      
!       if (jack_connect (jack_client, jack_port_name (output_port[i]), jack_ports[i])) 
!         fprintf (stderr, "cannot connect output ports %s -> %s\n", jack_port_name (output_port[i]),jack_ports[i]);
    
    
    
!   free(jack_ports);
!   return 0;
  }
  
  
  void jack_error(const char *desc) {
!   return;
  }
  
--- 164,200 ----
  static int jack_connect_ports(char* client)
  {
! 	char  regex_pattern[100]; /* its always the same, ... */
! 	int i;
! 	const char **jack_ports;
      
! 	if (strlen(client) > 96)  return -1;
  
! 	sprintf( regex_pattern, "%s:.*", client );
  
! 	jack_ports = jack_get_ports( jack_client, regex_pattern,
! 								 NULL, JackPortIsOutput);
! 	if (jack_ports) 
! 		for (i=0;jack_ports[i] != NULL && i < sys_inchannels;i++)      
! 			if (jack_connect (jack_client, jack_ports[i], jack_port_name (input_port[i]))) 
! 				fprintf (stderr, "cannot connect input ports %s -> %s\n", jack_ports[i],jack_port_name (input_port[i]));
        
    
    
! 	jack_ports = jack_get_ports( jack_client, regex_pattern,
! 								 NULL, JackPortIsInput);
! 	if (jack_ports) 
! 		for (i=0;jack_ports[i] != NULL && i < sys_outchannels;i++)      
! 			if (jack_connect (jack_client, jack_port_name (output_port[i]), jack_ports[i])) 
! 				fprintf (stderr, "cannot connect output ports %s -> %s\n", jack_port_name (output_port[i]),jack_ports[i]);
    
    
    
! 	free(jack_ports);
! 	return 0;
  }
  
  
  void jack_error(const char *desc) {
! 	return;
  }
  
***************
*** 204,315 ****
  
  {
!         int j;
!         char port_name[80] = "";
!         int client_iterator = 0;
!         int new_jack = 0;
!         int srate;
  
!         jack_dio_error = 0;
          
!         if ((inchans == 0) && (outchans == 0)) return 0;
  
!         if (outchans > NUM_JACK_PORTS) {
!                 fprintf(stderr,"%d output ports not supported, setting to %d\n",outchans, NUM_JACK_PORTS);
!                 outchans = NUM_JACK_PORTS;
!         }
  
!         if (inchans > NUM_JACK_PORTS) {
!                 fprintf(stderr,"%d input ports not supported, setting to %d\n",inchans, NUM_JACK_PORTS);
!                 inchans = NUM_JACK_PORTS;
!         }
  
!         /* try to become a client of the JACK server (we allow two pd's)*/
!         if (!jack_client) {
!           do {
              sprintf(port_name,"pure_data_%d",client_iterator);
              client_iterator++;
!           } while (((jack_client = jack_client_new (port_name)) == 0) && client_iterator < 2);
          
            
!           if (!jack_client) { // jack spits out enough messages already, do not warn
              sys_inchannels = sys_outchannels = 0;
              return 1;
!           }
            
!           jack_get_clients();
  
!           /* tell the JACK server to call `process()' whenever
!              there is work to be done.
!           */
            
!           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
            
!           /* 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;
              return 1;
!           }
            
!           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);
!         }
!         return 0;
  }
  
--- 204,315 ----
  
  {
! 	int j;
! 	char port_name[80] = "";
! 	int client_iterator = 0;
! 	int new_jack = 0;
! 	int srate;
  
! 	jack_dio_error = 0;
          
! 	if ((inchans == 0) && (outchans == 0)) return 0;
  
! 	if (outchans > NUM_JACK_PORTS) {
! 		fprintf(stderr,"%d output ports not supported, setting to %d\n",outchans, NUM_JACK_PORTS);
! 		outchans = NUM_JACK_PORTS;
! 	}
  
! 	if (inchans > NUM_JACK_PORTS) {
! 		fprintf(stderr,"%d input ports not supported, setting to %d\n",inchans, NUM_JACK_PORTS);
! 		inchans = NUM_JACK_PORTS;
! 	}
  
! 	/* try to become a client of the JACK server (we allow two pd's)*/
! 	if (!jack_client) {
! 		do {
              sprintf(port_name,"pure_data_%d",client_iterator);
              client_iterator++;
! 		} while (((jack_client = jack_client_new (port_name)) == 0) && client_iterator < 2);
          
            
! 		if (!jack_client) { // jack spits out enough messages already, do not warn
              sys_inchannels = sys_outchannels = 0;
              return 1;
! 		}
            
! 		jack_get_clients();
  
! 		/* tell the JACK server to call `process()' whenever
! 		   there is work to be done.
! 		*/
            
! 		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
            
! 		/* 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;
              return 1;
! 		}
            
! 		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);
! 	}
! 	return 0;
  }
  
***************
*** 317,321 ****
  
  {
!         jack_started = 0;
  }
  
--- 317,321 ----
  
  {
! 	jack_started = 0;
  }
  
***************
*** 323,369 ****
  
  {
!         float * fp;
!         int j;
!         int rtnval =  SENDDACS_YES;
!         int timenow;
!         int timeref = sys_getrealtime();
!                 
!         if (!jack_client) return SENDDACS_NO;
  
!         if (!sys_inchannels && !sys_outchannels) return (SENDDACS_NO); 
  
!         if (jack_dio_error) {
!                 sys_log_error(ERR_RESYNC);
!                 jack_dio_error = 0;
!         }
!         if (jack_filled >= jack_out_max)
!           pthread_cond_wait(&jack_sem,&jack_mutex);
!           
!         jack_started = 1;
  
!         fp = sys_soundout;
!         for (j = 0; j < sys_outchannels; j++) {
!                 memcpy(jack_outbuf + (j * BUF_JACK) + jack_filled,fp, sys_dacblocksize*sizeof(float));
!                 fp += sys_dacblocksize;  
!         }
!         fp = sys_soundin;
!         for (j = 0; j < sys_inchannels; j++) {
!                 memcpy(fp, jack_inbuf + (j * BUF_JACK) + jack_filled, sys_dacblocksize*sizeof(float));
!                 fp += sys_dacblocksize;
!         }
  
!         if ((timenow = sys_getrealtime()) - timeref > 0.002)
!           {
!             rtnval = SENDDACS_SLEPT;
!           }
!                           
!         memset(sys_soundout,0,sys_dacblocksize*sizeof(float)*sys_outchannels);
!         jack_filled += sys_dacblocksize;
!         return rtnval;
  }
  
  void jack_getdevs(char *indevlist, int *nindevs,
!     char *outdevlist, int *noutdevs, int *canmulti, 
!         int maxndev, int devdescsize)
  {
      int i, ndev;
--- 323,371 ----
  
  {
! 	float * fp;
! 	int j;
! 	int rtnval =  SENDDACS_YES;
! 	int timenow;
! 	int timeref = sys_getrealtime();
  
! 	if (!jack_client) return SENDDACS_NO;
  
! 	if (!sys_inchannels && !sys_outchannels) return (SENDDACS_NO); 
  
! 	if (jack_dio_error) {
! 		sys_log_error(ERR_RESYNC);
! 		jack_dio_error = 0;
! 	}
! 	if (jack_filled >= jack_out_max)
! 		return SENDDACS_NO;
! 	/* tb: wait in the scheduler
! 	 * pthread_cond_wait(&jack_sem,&jack_mutex); */
  
! 	jack_started = 1;
! 
! 	fp = sys_soundout;
! 	for (j = 0; j < sys_outchannels; j++) {
! 		memcpy(jack_outbuf + (j * BUF_JACK) + jack_filled,fp, sys_dacblocksize*sizeof(float));
! 		fp += sys_dacblocksize;  
! 	}
! 	fp = sys_soundin;
! 	for (j = 0; j < sys_inchannels; j++) {
! 		memcpy(fp, jack_inbuf + (j * BUF_JACK) + jack_filled, sys_dacblocksize*sizeof(float));
! 		fp += sys_dacblocksize;
! 	}
! 
! 	if ((timenow = sys_getrealtime()) - timeref > 0.002)
! 	{
! 		rtnval = SENDDACS_SLEPT;
! 	}
! 
! 	memset(sys_soundout,0,sys_dacblocksize*sizeof(float)*sys_outchannels);
! 	jack_filled += sys_dacblocksize;
! 	return rtnval;
  }
  
  void jack_getdevs(char *indevlist, int *nindevs,
! 				  char *outdevlist, int *noutdevs, int *canmulti, 
! 				  int maxndev, int devdescsize)
  {
      int i, ndev;





More information about the Pd-cvs mailing list