Changeset c201306
- Timestamp:
- Sep 25, 2009, 9:53:40 PM (15 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- ebbf5a0
- Parents:
- 04ceeab
- Location:
- ext
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ext/jackio.c
r04ceeab rc201306 22 22 23 23 #if HAVE_JACK 24 #include <jack/jack.h>25 24 #include "aubio_priv.h" 26 25 #include "jackio.h" … … 32 31 #define AUBIO_JACK_NEEDS_CONVERSION 33 32 #endif 33 34 #define RINGBUFFER_SIZE 1024*sizeof(jack_midi_event_t) 34 35 35 36 /** … … 62 63 /** jack output midi channels */ 63 64 uint_t omidichan; 65 /** midi output ringbuffer */ 66 jack_ringbuffer_t *midi_out_ring; 64 67 /** jack samplerate (Hz) */ 65 68 uint_t samplerate; … … 78 81 aubio_jack_t * 79 82 new_aubio_jack (uint_t ichan, uint_t ochan, 80 uint_t imidichan, uint_t omidichan, 81 aubio_process_func_t callback) 83 uint_t imidichan, uint_t omidichan, aubio_process_func_t callback) 82 84 { 83 85 aubio_jack_t *jack_setup = aubio_jack_alloc (ichan, ochan, … … 93 95 } 94 96 97 if (jack_setup->omidichan) { 98 jack_setup->midi_out_ring = jack_ringbuffer_create (RINGBUFFER_SIZE); 99 100 if (jack_setup->midi_out_ring == NULL) { 101 AUBIO_ERR ("Failed creating jack midi output ringbuffer."); 102 AUBIO_QUIT (AUBIO_FAIL); 103 } 104 105 jack_ringbuffer_mlock (jack_setup->midi_out_ring); 106 } 107 95 108 /* set callbacks */ 96 109 jack_set_process_callback (jack_setup->client, aubio_jack_process, … … 138 151 139 152 beach: 140 AUBIO_ERR ("failed registering port \"%s:%s\"!\n", 141 client_name, name); 153 AUBIO_ERR ("failed registering port \"%s:%s\"!\n", client_name, name); 142 154 jack_client_close (jack_setup->client); 143 155 AUBIO_QUIT (AUBIO_FAIL); … … 173 185 jack_setup->ichan = ichan; 174 186 jack_setup->ochan = ochan; 187 jack_setup->imidichan = imidichan; 188 jack_setup->omidichan = omidichan; 175 189 jack_setup->oports = AUBIO_ARRAY (jack_port_t *, ichan + imidichan); 176 190 jack_setup->iports = AUBIO_ARRAY (jack_port_t *, ochan + omidichan); … … 195 209 aubio_jack_free (aubio_jack_t * jack_setup) 196 210 { 211 if (jack_setup->omidichan && jack_setup->midi_out_ring) { 212 jack_ringbuffer_free (jack_setup->midi_out_ring); 213 } 197 214 AUBIO_FREE (jack_setup->oports); 198 215 AUBIO_FREE (jack_setup->iports); … … 210 227 AUBIO_QUIT (AUBIO_OK); 211 228 } 229 230 static void process_midi_output (aubio_jack_t * dev, jack_nframes_t nframes); 212 231 213 232 static int … … 242 261 } 243 262 #endif 263 264 /* now process midi stuff */ 265 if (dev->omidichan) { 266 process_midi_output (dev, nframes); 267 } 268 244 269 return 0; 245 270 } 246 271 272 void 273 aubio_jack_midi_event_write (aubio_jack_t * dev, jack_midi_event_t * event) 274 { 275 int written; 276 277 if (jack_ringbuffer_write_space (dev->midi_out_ring) < sizeof (*event)) { 278 AUBIO_ERR ("Not enough space to write midi output, midi event lost!\n"); 279 return; 280 } 281 282 written = jack_ringbuffer_write (dev->midi_out_ring, 283 (char *) event, sizeof (*event)); 284 285 if (written != sizeof (*event)) { 286 AUBIO_WRN ("Call to jack_ringbuffer_write failed, midi event lost! \n"); 287 } 288 } 289 290 static void 291 process_midi_output (aubio_jack_t * dev, jack_nframes_t nframes) 292 { 293 int read, sendtime; 294 jack_midi_event_t ev; 295 unsigned char *buffer; 296 jack_nframes_t last_frame_time = jack_last_frame_time (dev->client); 297 // TODO for each omidichan 298 void *port_buffer = jack_port_get_buffer (dev->oports[dev->ochan], nframes); 299 300 if (port_buffer == NULL) { 301 AUBIO_WRN ("Failed to get jack midi output port, will not send anything\n"); 302 return; 303 } 304 305 jack_midi_clear_buffer (port_buffer); 306 307 // TODO add rate_limit 308 309 while (jack_ringbuffer_read_space (dev->midi_out_ring)) { 310 read = jack_ringbuffer_peek (dev->midi_out_ring, (char *) &ev, sizeof (ev)); 311 312 if (read != sizeof (ev)) { 313 AUBIO_WRN ("Short read from the ringbuffer, possible note loss.\n"); 314 jack_ringbuffer_read_advance (dev->midi_out_ring, read); 315 continue; 316 } 317 318 sendtime = ev.time + nframes - last_frame_time; 319 320 /* send time is after current period, will do this one later */ 321 if (sendtime >= (int) nframes) { 322 break; 323 } 324 325 if (sendtime < 0) { 326 sendtime = 0; 327 } 328 329 jack_ringbuffer_read_advance (dev->midi_out_ring, sizeof (ev)); 330 331 buffer = jack_midi_event_reserve (port_buffer, sendtime, ev.size); 332 333 if (buffer == NULL) { 334 AUBIO_WRN ("Call to jack_midi_event_reserve failed, note lost.\n"); 335 break; 336 } 337 338 AUBIO_MEMCPY (buffer, ev.buffer, ev.size); 339 } 340 } 247 341 248 342 #endif /* HAVE_JACK */ -
ext/jackio.h
r04ceeab rc201306 34 34 #endif 35 35 36 #include <jack/jack.h> 37 #include <jack/midiport.h> 38 #include <jack/ringbuffer.h> 39 36 40 /** jack object */ 37 41 typedef struct _aubio_jack_t aubio_jack_t; … … 49 53 void aubio_jack_close (aubio_jack_t * jack_setup); 50 54 55 /** write a jack_midi_event_t to the midi output ringbuffer */ 56 void aubio_jack_midi_event_write (aubio_jack_t * jack_setup, 57 jack_midi_event_t * event); 58 51 59 #ifdef __cplusplus 52 60 }
Note: See TracChangeset
for help on using the changeset viewer.