Changeset 506
- Timestamp:
- 09/27/07 04:24:25 (1 year ago)
- Files:
-
- sweep/branches/sweep-jack-testing/configure.ac (modified) (1 diff)
- sweep/branches/sweep-jack-testing/src/driver.c (modified) (2 diffs)
- sweep/branches/sweep-jack-testing/src/driver.h (modified) (4 diffs)
- sweep/branches/sweep-jack-testing/src/driver_alsa.c (modified) (2 diffs)
- sweep/branches/sweep-jack-testing/src/driver_jack.c (modified) (6 diffs)
- sweep/branches/sweep-jack-testing/src/driver_jack.h (deleted)
- sweep/branches/sweep-jack-testing/src/driver_oss.c (modified) (2 diffs)
- sweep/branches/sweep-jack-testing/src/driver_solaris.c (modified) (3 diffs)
- sweep/branches/sweep-jack-testing/src/play.c (modified) (10 diffs)
- sweep/branches/sweep-jack-testing/src/play.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sweep/branches/sweep-jack-testing/configure.ac
r505 r506 328 328 [ ac_enable_alsa=no ]) 329 329 330 if test "x${ac_enable_alsa}" != xno ; then330 if test "x${ac_enable_alsa}" != xno && test "x${ac_enable_jack_playback}" = xno; then 331 331 332 332 PKG_CHECK_MODULES(ALSA, alsa >= 1.0.0, sweep/branches/sweep-jack-testing/src/driver.c
r505 r506 752 752 } 753 753 754 gboolean 755 device_has_callback_driver(void) 756 { 757 if (pref->is_callback_driver == NULL) 758 return FALSE; 759 else 760 return pref->is_callback_driver(); 761 } 762 763 sw_callback_data_t * 764 driver_get_callback_data (void) 765 { 766 if (pref->get_callback_data) 767 return pref->get_callback_data(); 768 else 769 return NULL; 770 } 771 772 754 773 void 755 774 init_devices (void) … … 764 783 pref = driver_jack; 765 784 #endif 785 786 pref = driver_jack; 766 787 play_mutex = g_mutex_new (); 767 788 sweep/branches/sweep-jack-testing/src/driver.h
r505 r506 30 30 typedef struct _sw_handle sw_handle; 31 31 typedef struct _sw_driver sw_driver; 32 typedef struct _sw_callback_data_t sw_callback_data_t; 32 33 33 34 struct _sw_handle { … … 37 38 int driver_rate; 38 39 void * custom_data; 40 }; 41 42 struct _sw_callback_data_t { 43 sw_framecount_t count; 44 int inactive_writes; 45 GList * gl; 46 sw_head * head; 47 sw_format * f; 48 int max_driver_chans; 49 50 gboolean use_monitor; 51 52 #ifdef RECORD_DEMO_FILES 53 gchar * filename; 54 SNDFILE * sndfile; 55 SF_INFO sfinfo; 56 #endif 57 39 58 }; 40 59 … … 53 72 void (*drain) (sw_handle * handle); 54 73 void (*close) (sw_handle * handle); 55 74 /* FIXME simple boolean instead ? */ 75 gboolean (*is_callback_driver) (void); 76 /* FIXME this may not be necessary. look at it again later */ 77 sw_callback_data_t * (*get_callback_data) (void); 78 /* FIXME specify prefix only and use macro to generate keys? */ 56 79 char * primary_device_key; 57 80 char * monitor_device_key; … … 130 153 device_close (sw_handle * handle); 131 154 155 gboolean 156 device_has_callback_driver(void); 157 158 sw_callback_data_t * 159 driver_get_callback_data (void); 160 132 161 void 133 162 init_devices (void); sweep/branches/sweep-jack-testing/src/driver_alsa.c
r505 r506 459 459 alsa_device_drain, 460 460 alsa_device_close, 461 NULL, 462 NULL, 461 463 "alsa_primary_device", 462 464 "alsa_monitor_device", … … 467 469 468 470 static sw_driver _driver_alsa = { 469 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL 471 NULL, 472 NULL, 473 NULL, 474 NULL, 475 NULL, 476 NULL, 477 NULL, 478 NULL, 479 NULL, 480 NULL, 481 NULL, 482 NULL, 483 NULL, 484 NULL, 485 NULL, 486 NULL, 487 NULL 470 488 }; 471 489 sweep/branches/sweep-jack-testing/src/driver_jack.c
r369 r506 47 47 #include "play.h" 48 48 #include "preferences.h" 49 #include "driver_jack.h"50 49 51 50 #ifdef DRIVER_JACK … … 53 52 #include <jack/jack.h> 54 53 55 jack_process_data_t *process_data = NULL;54 sw_callback_data_t *process_data = NULL; 56 55 57 56 jack_client_t *jack_client = NULL; … … 61 60 jack_port_t *port_l, *port_r; 62 61 } sw_jack_handle_t; 62 63 static int 64 jack_process_callback (jack_nframes_t nframes, void *data); 63 65 64 66 static GList * … … 84 86 gint rate; 85 87 gint use_monitor; 86 87 jack_client = jack_client_new( "sweep" ); 88 89 if (jack_client == NULL) { 90 91 // popup_msgbox("Error", MSGBOX_OK, 120000, MSGBOX_OK, 92 // "Could not open Jack Client"); 93 return 1; /* do something with this later. like offer to try again */ 88 if (process_data == NULL) { 89 process_data = g_new0(sw_callback_data_t, 1); 90 jack_client = jack_client_new( "sweep" ); 91 92 if (jack_client == NULL) { 93 94 // popup_msgbox("Error", MSGBOX_OK, 120000, MSGBOX_OK, 95 // "Could not open Jack Client"); 96 return 1; /* do something with this later. like offer to try again */ 97 } 98 rate = (gint) jack_get_sample_rate(jack_client); 99 100 /* 101 * register a pair of input, output and conditionally, monitor ports. 102 * the port names could easily be made configurable. 103 */ 104 if (!handle_in) { 105 jack_data_in = g_malloc0 (sizeof (sw_jack_handle_t)); 106 jack_data_in->port_l = jack_port_register (jack_client, "input_left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); 107 jack_data_in->port_r = jack_port_register (jack_client, "input_right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); 108 handle_in = g_malloc0 (sizeof (sw_handle)); 109 handle_in->driver_flags = O_RDONLY; 110 handle_in->custom_data = jack_data_in; 111 handle_in->driver_rate = rate; 112 handle_in->driver_channels = channels; 113 } 114 if (!handle_out){ 115 jack_data_out = g_malloc0 (sizeof (sw_jack_handle_t)); 116 jack_data_out->port_l = jack_port_register (jack_client, "output_left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 117 jack_data_out->port_r = jack_port_register (jack_client, "output_right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 118 handle_out = g_malloc0 (sizeof (sw_handle)); 119 handle_out->driver_flags = O_WRONLY; 120 handle_out->custom_data = jack_data_out; 121 handle_out->driver_rate = rate; 122 handle_out->driver_channels = channels; 123 } 124 125 use_monitor = monitor_active(); 126 127 if (!handle_monitor && use_monitor){ 128 jack_data_monitor = g_malloc0 (sizeof (sw_jack_handle_t)); 129 jack_data_monitor->port_l = jack_port_register (jack_client, "monitor_left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 130 jack_data_monitor->port_r = jack_port_register (jack_client, "monitor_right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 131 handle_monitor = g_malloc0 (sizeof (sw_handle)); 132 handle_monitor->driver_flags = O_WRONLY; 133 handle_monitor->custom_data = jack_data_monitor; 134 handle_monitor->driver_rate = rate; 135 handle_monitor->driver_channels = channels; 136 } 137 else if (handle_monitor && !use_monitor){ 138 139 /* FIXME: remove unwanted monitor ports if they exist. */ 140 } 141 // FIXME: check the ports.... 142 143 jack_set_process_callback( jack_client, jack_process_callback, process_data ); 144 jack_activate( jack_client ); 145 return 0; 94 146 } 95 rate = (gint) jack_get_sample_rate(jack_client); 96 97 /* 98 * register a pair of input, output and conditionally, monitor ports. 99 * the port names could easily be made configurable. 100 */ 101 if (!handle_in) { 102 jack_data_in = g_malloc0 (sizeof (sw_jack_handle_t)); 103 jack_data_in->port_l = jack_port_register (jack_client, "input_left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); 104 jack_data_in->port_r = jack_port_register (jack_client, "input_right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); 105 handle_in = g_malloc0 (sizeof (sw_handle)); 106 handle_in->driver_flags = O_RDONLY; 107 handle_in->custom_data = jack_data_in; 108 handle_in->driver_rate = rate; 109 handle_in->driver_channels = channels; 110 } 111 if (!handle_out){ 112 jack_data_out = g_malloc0 (sizeof (sw_jack_handle_t)); 113 jack_data_out->port_l = jack_port_register (jack_client, "output_left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 114 jack_data_out->port_r = jack_port_register (jack_client, "output_right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 115 handle_out = g_malloc0 (sizeof (sw_handle)); 116 handle_out->driver_flags = O_WRONLY; 117 handle_out->custom_data = jack_data_out; 118 handle_out->driver_rate = rate; 119 handle_out->driver_channels = channels; 120 } 121 122 use_monitor = monitor_active(); 123 124 if (!handle_monitor && use_monitor){ 125 jack_data_monitor = g_malloc0 (sizeof (sw_jack_handle_t)); 126 jack_data_monitor->port_l = jack_port_register (jack_client, "monitor_left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 127 jack_data_monitor->port_r = jack_port_register (jack_client, "monitor_right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 128 handle_monitor = g_malloc0 (sizeof (sw_handle)); 129 handle_monitor->driver_flags = O_WRONLY; 130 handle_monitor->custom_data = jack_data_monitor; 131 handle_monitor->driver_rate = rate; 132 handle_monitor->driver_channels = channels; 133 } 134 else if (handle_monitor && !use_monitor){ 135 136 /* FIXME: remove unwanted monitor ports if they exist. */ 137 } 138 // FIXME: check the ports.... 139 if (process_data == NULL) { 140 process_data = g_malloc0( sizeof( jack_process_data_t ) ); 141 jack_set_process_callback( jack_client, process_callback, process_data ); 142 jack_activate( jack_client ); 143 } 144 return 0; 147 return 0; 145 148 } 146 149 … … 269 272 } 270 273 274 static int 275 jack_process_callback (jack_nframes_t nframes, void *data) 276 { 277 return sweep_playback_callback (nframes, data); 278 } 279 280 gboolean 281 jack_is_callback_driver (void) 282 { 283 return TRUE; 284 } 285 286 sw_callback_data_t * 287 jack_get_callback_data (void) 288 { 289 return process_data; 290 } 291 292 271 293 static sw_driver _driver_jack = { 272 294 jack_get_names, … … 281 303 jack_device_flush, 282 304 jack_device_drain, 283 jack_device_close 305 jack_device_close, 306 jack_is_callback_driver, 307 jack_get_callback_data 284 308 }; 285 309 sweep/branches/sweep-jack-testing/src/driver_oss.c
r505 r506 446 446 drain_dev_dsp, 447 447 close_dev_dsp, 448 NULL, 449 NULL, 448 450 "oss_primary_device", 449 451 "oss_monitor_device", … … 454 456 455 457 static sw_driver _driver_oss = { 456 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 458 NULL, 459 NULL, 460 NULL, 461 NULL, 462 NULL, 463 NULL, 464 NULL, 465 NULL, 466 NULL, 467 NULL, 468 NULL, 469 NULL, 470 NULL, 471 NULL, 472 NULL, 473 NULL, 474 NULL 457 475 }; 458 476 sweep/branches/sweep-jack-testing/src/driver_solaris.c
r505 r506 116 116 117 117 static sw_driver _driver_solaris = { 118 NULL, /* config */118 NULL, /* config */ 119 119 open_dev_audio, 120 120 NULL, /* device_startup unused in this driver */ 121 121 setup_dev_audio, 122 NULL,122 NULL, 123 123 write_dev_audio, 124 124 reset_dev_audio, … … 126 126 drain_dev_audio, 127 127 close_dev_audio, 128 NULL, 129 NULL, 128 130 "solaris_primary_device", 129 131 "solaris_monitor_device", … … 134 136 135 137 static sw_driver _driver_solaris = { 136 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL 138 NULL, 139 NULL, 140 NULL, 141 NULL, 142 NULL, 143 NULL, 144 NULL, 145 NULL, 146 NULL, 147 NULL, 148 NULL, 149 NULL, 150 NULL, 151 NULL, 152 NULL, 153 NULL, 154 NULL 137 155 }; 138 156 sweep/branches/sweep-jack-testing/src/play.c
r505 r506 38 38 #include <pthread.h> 39 39 40 #ifdef DRIVER_JACK41 #include "jack/jack.h"42 #endif43 44 40 #ifdef RECORD_DEMO_FILES 45 41 #include <sndfile.h> … … 61 57 #include "preferences.h" 62 58 #include "sample-display.h" 63 #include "driver_jack.h"64 59 65 60 /*#define DEBUG*/ … … 86 81 static int pbuf_chans = 0, devbuf_chans = 0; 87 82 88 #ifdef DRIVER_JACK 89 extern jack_process_data_t *process_data; 90 #endif 83 91 84 /* 92 85 * update_playmarker () … … 942 935 } 943 936 944 #ifdef DRIVER_JACK 945 946 947 948 int process_callback( jack_nframes_t nframes, void *data ) { 949 struct jack_process_data *jack_data = data; 937 int sweep_playback_callback( guint32 nframes, void *data ) { 938 sw_callback_data_t *cb_data = data; 950 939 951 940 if (!main_handle) return 0; … … 953 942 //jack_data->inactive_writes++; 954 943 } else { 955 jack_data->inactive_writes = 0;944 cb_data->inactive_writes = 0; 956 945 } 957 946 958 947 g_mutex_lock (play_mutex); 959 if ( jack_data->use_monitor) {948 if (cb_data->use_monitor) { 960 949 prepare_to_play_heads (active_monitor_heads, monitor_handle); 961 950 prepare_to_play_heads (active_main_heads, main_handle); … … 966 955 g_mutex_unlock (play_mutex); 967 956 968 if ( jack_data->use_monitor) {969 jack_data->count = nframes * monitor_handle->driver_channels;970 memset (devbuf, 0, jack_data->count * sizeof (sw_audio_t));957 if (cb_data->use_monitor) { 958 cb_data->count = nframes * monitor_handle->driver_channels; 959 memset (devbuf, 0, cb_data->count * sizeof (sw_audio_t)); 971 960 play_heads (&active_monitor_heads, monitor_handle, nframes); 972 device_write (monitor_handle, devbuf, jack_data->count, -1 /* offset reference */);961 device_write (monitor_handle, devbuf, cb_data->count, -1 /* offset reference */); 973 962 /* should the main device still play when the monitor is toggled? */ 974 jack_data->count = nframes * main_handle->driver_channels;975 memset (devbuf, 0, jack_data->count * sizeof (sw_audio_t));963 cb_data->count = nframes * main_handle->driver_channels; 964 memset (devbuf, 0, cb_data->count * sizeof (sw_audio_t)); 976 965 play_heads (&active_main_heads, main_handle, nframes); 977 device_write (main_handle, devbuf, jack_data->count, -1 /* offset reference */);966 device_write (main_handle, devbuf, cb_data->count, -1 /* offset reference */); 978 967 } else { 979 jack_data->count = nframes * main_handle->driver_channels;980 memset (devbuf, 0, jack_data->count * sizeof (sw_audio_t));968 cb_data->count = nframes * main_handle->driver_channels; 969 memset (devbuf, 0, cb_data->count * sizeof (sw_audio_t)); 981 970 play_heads (&active_monitor_heads, main_handle, nframes); 982 971 play_heads (&active_main_heads, main_handle, nframes); 983 device_write (main_handle, devbuf, jack_data->count, -1 /* offset reference */);972 device_write (main_handle, devbuf, cb_data->count, -1 /* offset reference */); 984 973 } 985 974 986 975 #ifdef RECORD_DEMO_FILES 987 976 if (sndfile) 988 sf_writef_float ( jack_data->sndfile, devbuf, jack_data->count / main_handle->driver_channels);977 sf_writef_float (cb_data->sndfile, devbuf, cb_data->count / main_handle->driver_channels); 989 978 #endif 990 979 … … 1000 989 } 1001 990 1002 static void init_play_thread() { 991 /* if we remerge this and sweep_playback_callback() then 992 * we don't need to fetch the process data somehow. 993 * however, i don't know whether this was broken out for a good reason. 994 * (not realtime safe perhaps?) 995 */ 996 997 static void init_playback_callback(void) { 1003 998 if (!active_main_heads && !active_monitor_heads) return; 1004 1005 process_data->use_monitor = (monitor_handle != NULL); 1006 1007 if (process_data->use_monitor) { 1008 if ((process_data->gl = active_monitor_heads)) { 1009 process_data->head = (sw_head *)process_data->gl->data; 1010 process_data->f = process_data->head->sample->sounddata->format; 999 1000 sw_callback_data_t *callback_data = driver_get_callback_data(); 1001 if (callback_data == NULL) 1002 return; 1003 1004 callback_data->use_monitor = (monitor_handle != NULL); 1005 1006 if (callback_data->use_monitor) { 1007 if ((callback_data->gl = active_monitor_heads)) { 1008 callback_data->head = (sw_head *)callback_data->gl->data; 1009 callback_data->f = callback_data->head->sample->sounddata->format; 1011 1010 1012 device_setup (monitor_handle, process_data->f);1013 } else if (( process_data->gl = active_main_heads)) {1014 process_data->head = (sw_head *)process_data->gl->data;1015 process_data->f = process_data->head->sample->sounddata->format;1011 device_setup (monitor_handle, callback_data->f); 1012 } else if ((callback_data->gl = active_main_heads)) { 1013 callback_data->head = (sw_head *)callback_data->gl->data; 1014 callback_data->f = callback_data->head->sample->sounddata->format; 1016 1015 1017 device_setup (monitor_handle, process_data->f);1018 } 1019 } 1020 1021 if (( process_data->gl = active_main_heads)) {1022 process_data->head = (sw_head *)process_data->gl->data;1023 process_data->f = process_data->head->sample->sounddata->format;1024 1025 device_setup (main_handle, process_data->f);1016 device_setup (monitor_handle, callback_data->f); 1017 } 1018 } 1019 1020 if ((callback_data->gl = active_main_heads)) { 1021 callback_data->head = (sw_head *)callback_data->gl->data; 1022 callback_data->f = callback_data->head->sample->sounddata->format; 1023 1024 device_setup (main_handle, callback_data->f); 1026 1025 1027 1026 #ifdef RECORD_DEMO_FILES 1028 process_data->filename = generate_demo_filename ();1029 process_data->sfinfo.samplerate = process_data->f->rate;1030 process_data->sfinfo.channels = handle->driver_channels;1031 process_data->sfinfo.format = SF_FORMAT_AU | SF_FORMAT_FLOAT | SF_ENDIAN_CPU;1032 process_data->sndfile = sf_open (process_data->filename, SFM_WRITE, &sfinfo);1033 if ( process_data->sndfile == NULL) sf_perror (NULL);1034 else printf ("Writing to %s\n", process_data->filename);1035 #endif 1036 } else if (( process_data->gl = active_monitor_heads)) {1037 process_data->head = (sw_head *)process_data->gl->data;1038 process_data->f = process_data->head->sample->sounddata->format;1039 1040 device_setup (main_handle, process_data->f);1027 callback_data->filename = generate_demo_filename (); 1028 callback_data->sfinfo.samplerate = callback_data->f->rate; 1029 callback_data->sfinfo.channels = handle->driver_channels; 1030 callback_data->sfinfo.format = SF_FORMAT_AU | SF_FORMAT_FLOAT | SF_ENDIAN_CPU; 1031 callback_data->sndfile = sf_open (callback_data->filename, SFM_WRITE, &sfinfo); 1032 if (callback_data->sndfile == NULL) sf_perror (NULL); 1033 else printf ("Writing to %s\n", callback_data->filename); 1034 #endif 1035 } else if ((callback_data->gl = active_monitor_heads)) { 1036 callback_data->head = (sw_head *)callback_data->gl->data; 1037 callback_data->f = callback_data->head->sample->sounddata->format; 1038 1039 device_setup (main_handle, callback_data->f); 1041 1040 } else { 1042 1041 return; 1043 1042 } 1044 1043 1045 if ( process_data->use_monitor) {1046 process_data->max_driver_chans = MAX (main_handle->driver_channels,1044 if (callback_data->use_monitor) { 1045 callback_data->max_driver_chans = MAX (main_handle->driver_channels, 1047 1046 monitor_handle->driver_channels); 1048 1047 } else { 1049 process_data->max_driver_chans = main_handle->driver_channels;1050 } 1051 1052 if ( process_data->max_driver_chans > devbuf_chans) {1048 callback_data->max_driver_chans = main_handle->driver_channels; 1049 } 1050 1051 if (callback_data->max_driver_chans > devbuf_chans) { 1053 1052 devbuf = g_realloc (devbuf, 1054 MAX_PSIZ * process_data->max_driver_chans * sizeof (sw_audio_t));1055 devbuf_chans = process_data->max_driver_chans;1053 MAX_PSIZ * callback_data->max_driver_chans * sizeof (sw_audio_t)); 1054 devbuf_chans = callback_data->max_driver_chans; 1056 1055 } 1057 1056 … … 1062 1061 { 1063 1062 sw_handle * h; 1064 if (player_thread == -1) { 1063 1064 if (player_thread == (pthread_t) -1) { 1065 1065 if ((h = device_open (0, O_WRONLY)) != NULL) { 1066 1066 main_handle = h; … … 1070 1070 monitor_handle = NULL; 1071 1071 } 1072 1073 init_play_thread(); 1074 player_thread = 0; 1072 1073 1074 if (device_has_callback_driver()) { 1075 init_playback_callback(); 1076 player_thread = (pthread_t) 0; 1077 } else { 1078 pthread_create (&player_thread, 1079 NULL, 1080 (void *) (*play_active_heads), 1081 NULL); 1082 } 1075 1083 return TRUE; 1076 1084 } else { … … 1078 1086 } 1079 1087 } 1080 }1081 1082 #else1083 1084 static gboolean1085 ensure_playing (void)1086 {1087 sw_handle * h;1088 if (player_thread == (pthread_t) -1) {1089 if ((h = device_open (0, O_WRONLY)) != NULL) {1090 main_handle = h;1091 if (monitor_active() == TRUE) {1092 monitor_handle = device_open (1, O_WRONLY);1093 } else {1094 monitor_handle = NULL;1095 }1096 1097 pthread_create (&player_thread, NULL, (void *) (*play_active_heads),1098 NULL);1099 return TRUE;1100 } else {1101 return FALSE;1102 }1103 }1104 1105 1088 return TRUE; 1106 1089 } 1107 #endif 1090 1108 1091 1109 1092 void sweep/branches/sweep-jack-testing/src/play.h
r505 r506 23 23 24 24 #include "sweep_app.h" 25 #ifdef DRIVER_JACK 25 26 26 int 27 process_callback(jack_nframes_t nframes, void *data); 28 29 #include <jack/jack.h> 30 #endif 27 sweep_playback_callback(guint32 nframes, void *data); 31 28 32 29 void
