Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15034
Modified Files:
Tag: devel_0_38
s_audio_jack.c
Log Message:
callback based scheduling
Index: s_audio_jack.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_audio_jack.c,v
retrieving revision 1.5.4.2
retrieving revision 1.5.4.3
diff -C2 -d -r1.5.4.2 -r1.5.4.3
*** s_audio_jack.c 27 Feb 2005 12:06:52 -0000 1.5.4.2
--- s_audio_jack.c 8 Apr 2005 12:44:05 -0000 1.5.4.3
***************
*** 8,11 ****
--- 8,12 ----
#include <string.h>
#include <m_pd.h>
+ #include "m_simd.h"
#include <s_stuff.h>
#include <jack/jack.h>
***************
*** 31,38 ****
static int jack_dio_error;
-
pthread_mutex_t jack_mutex;
pthread_cond_t jack_sem;
static int
process (jack_nframes_t nframes, void *arg)
--- 32,41 ----
static int jack_dio_error;
pthread_mutex_t jack_mutex;
pthread_cond_t jack_sem;
+ extern int sys_keepsched;
+ extern int sys_callbackscheduler;
+
static int
process (jack_nframes_t nframes, void *arg)
***************
*** 41,46 ****
float *out;
float *in;
!
!
if (nframes > JACK_OUT_MAX) jack_out_max = nframes;
else jack_out_max = JACK_OUT_MAX;
--- 44,48 ----
float *out;
float *in;
!
if (nframes > JACK_OUT_MAX) jack_out_max = nframes;
else jack_out_max = JACK_OUT_MAX;
***************
*** 66,74 ****
jack_filled = 0;
}
! /* tb: wait in the scheduler
! * pthread_cond_broadcast(&jack_sem); */
return 0;
}
static int
jack_srate (jack_nframes_t srate, void *arg)
--- 68,128 ----
jack_filled = 0;
}
! /* tb: wait in the scheduler */
! /* pthread_cond_broadcast(&jack_sem); */
! return 0;
! }
!
!
! void sys_peakmeters(void);
! extern int sys_meters; /* true if we're metering */
! extern float sys_inmax; /* max input amplitude */
! extern float sys_outmax; /* max output amplitude */
!
! static int dspticks_per_jacktick;
! static void (*copyblock)(t_sample *dst,t_sample *src,int n);
! static void (*zeroblock)(t_sample *dst,int n);
!
! static int cb_process (jack_nframes_t nframes, void *arg)
! {
! int i,j;
!
! sys_lock();
! for (i = 0; i != dspticks_per_jacktick; ++i)
! {
! /* get sound from the inputs */
! for (j = 0; j < sys_inchannels; j++)
! {
! t_sample * in = jack_port_get_buffer(input_port[j], nframes);
! copyvec_simd(sys_soundin + j * sys_dacblocksize,
! in + i * sys_dacblocksize,
! sys_dacblocksize);
! }
!
! /* run dsp */
! sched_tick(sys_time + sys_time_per_dsp_tick);
!
! /* send sound to the output */
! for (j = 0; j < sys_outchannels; j++)
! {
! t_sample * out = jack_port_get_buffer (output_port[j], nframes);
! copyvec_simd(out + i * sys_dacblocksize,
! sys_soundout + j * sys_dacblocksize,
! sys_dacblocksize);
! }
!
! /* update peak meters */
! if (sys_meters)
! sys_peakmeters();
!
! /* clear the output buffer */
! zerovec_simd(sys_soundout, j * sys_dacblocksize);
! }
! sys_unlock();
!
return 0;
}
+
+
static int
jack_srate (jack_nframes_t srate, void *arg)
***************
*** 97,101 ****
int num_clients = 0;
regex_t port_regex;
! jack_ports = jack_get_ports( jack_client, "", "", 0 );
regcomp( &port_regex, "^[^:]*", REG_EXTENDED );
--- 151,155 ----
int num_clients = 0;
regex_t port_regex;
! jack_ports = jack_get_ports( jack_client, "", "", 0 );
regcomp( &port_regex, "^[^:]*", REG_EXTENDED );
***************
*** 201,206 ****
int
! jack_open_audio(int inchans, int outchans, int rate)
!
{
int j;
--- 255,259 ----
int
! jack_open_audio(int inchans, int outchans, int rate, int scheduler)
{
int j;
***************
*** 224,227 ****
--- 277,289 ----
}
+ if (jack_client && sys_callbackscheduler != scheduler)
+ {
+ jack_client_close(jack_client);
+ jack_client = NULL;
+ }
+
+ sys_keepsched = 0;
+ sys_callbackscheduler = scheduler;
+
/* try to become a client of the JACK server (we allow two pd's)*/
if (!jack_client) {
***************
*** 241,248 ****
/* 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);
--- 303,314 ----
/* tell the JACK server to call `process()' whenever
there is work to be done.
+ tb: adapted for callback based scheduling
*/
! if (scheduler == 1)
! jack_set_process_callback (jack_client, cb_process, 0);
! else
! jack_set_process_callback (jack_client, process, 0);
!
!
jack_set_error_function (jack_error);
***************
*** 311,314 ****
--- 377,401 ----
pthread_cond_init(&jack_sem,NULL);
}
+
+ if (scheduler)
+ dspticks_per_jacktick = jack_get_buffer_size(jack_client)
+ / sys_schedblocksize;
+
+ /* tb: get advance from jack server */
+ sys_schedadvance = (float)jack_port_get_total_latency(jack_client,output_port[0])
+ * 1000. / sys_dacsr * 1000;
+
+ /* set block copy/zero functions */
+ if(SIMD_CHKCNT(sys_dacblocksize) && simd_runtime_check())
+ {
+ copyblock = (void (*)(t_sample *,t_sample *,int))©vec_simd;
+ zeroblock = &zerovec_simd;
+ }
+ else
+ {
+ copyblock = (void (*)(t_sample *,t_sample *,int))©vec;
+ zeroblock = &zerovec;
+ }
+
return 0;
}
***************
*** 317,321 ****
--- 404,411 ----
{
+ jack_client_deactivate(jack_client);
jack_started = 0;
+ jack_client_close(jack_client);
+ jack_client = NULL;
}
***************
*** 339,344 ****
if (jack_filled >= jack_out_max)
return SENDDACS_NO;
! /* tb: wait in the scheduler
! * pthread_cond_wait(&jack_sem,&jack_mutex); */
jack_started = 1;
--- 429,434 ----
if (jack_filled >= jack_out_max)
return SENDDACS_NO;
! /* tb: wait in the scheduler */
! /* pthread_cond_wait(&jack_sem,&jack_mutex); */
jack_started = 1;