312 | | // Process all ports that should be handled on a per-packet base |
---|
313 | | // this is MIDI for AMDTP (due to the need of DBC, which is lost |
---|
314 | | // when putting the events in the ringbuffer) |
---|
315 | | // for motu this might also be control data, however as control |
---|
316 | | // data isn't time specific I would also include it in the period |
---|
317 | | // based processing |
---|
318 | | |
---|
319 | | // FIXME: m_tx_dbc probably needs to be initialised to a non-zero |
---|
320 | | // value somehow so MIDI sync is possible. For now we ignore |
---|
321 | | // this issue. |
---|
322 | | if (!encodePacketPorts((quadlet_t *)(data+8), n_events, m_tx_dbc)) { |
---|
323 | | debugWarning("Problem encoding Packet Ports\n"); |
---|
324 | | } |
---|
325 | | |
---|
405 | | |
---|
406 | | |
---|
407 | | #if 0 |
---|
408 | | for ( PortVectorIterator it = m_Ports.begin(); |
---|
409 | | it != m_Ports.end(); |
---|
410 | | ++it ) |
---|
411 | | { |
---|
412 | | if ( ( *it )->getPortType() == Port::E_Midi ) |
---|
413 | | { |
---|
414 | | // we use a timing unit of 10ns |
---|
415 | | // this makes sure that for the max syt interval |
---|
416 | | // we don't have rounding, and keeps the numbers low |
---|
417 | | // we have 1 slot every 8 events |
---|
418 | | // we have syt_interval events per packet |
---|
419 | | // => syt_interval/8 slots per packet |
---|
420 | | // packet rate is 8000pkt/sec => interval=125us |
---|
421 | | // so the slot interval is (1/8000)/(syt_interval/8) |
---|
422 | | // or: 1/(1000 * syt_interval) sec |
---|
423 | | // which is 1e9/(1000*syt_interval) nsec |
---|
424 | | // or 100000/syt_interval 'units' |
---|
425 | | // the event interval is fixed to 320us = 32000 'units' |
---|
426 | | if ( ! ( *it )->useRateControl ( true, ( 100000/m_syt_interval ),32000, false ) ) |
---|
427 | | { |
---|
428 | | debugFatal ( "Could not set signal type to PeriodSignalling" ); |
---|
429 | | return false; |
---|
430 | | } |
---|
431 | | break; |
---|
432 | | } |
---|
433 | | } |
---|
434 | | #endif |
---|
509 | | } |
---|
510 | | |
---|
511 | | /** |
---|
512 | | * @brief encode a packet for the packet-based ports |
---|
513 | | * |
---|
514 | | * @param data Packet data |
---|
515 | | * @param nevents number of events in data (including events of other ports & port types) |
---|
516 | | * @param dbc DataBlockCount value for this packet |
---|
517 | | * @return true if all successfull |
---|
518 | | */ |
---|
519 | | bool MotuTransmitStreamProcessor::encodePacketPorts(quadlet_t *data, unsigned int nevents, |
---|
520 | | unsigned int dbc) { |
---|
521 | | bool ok=true; |
---|
522 | | char byte; |
---|
523 | | |
---|
524 | | // Use char here since the target address won't necessarily be |
---|
525 | | // aligned; use of an unaligned quadlet_t may cause issues on |
---|
526 | | // certain architectures. Besides, the target for MIDI data going |
---|
527 | | // directly to the MOTU isn't structured in quadlets anyway; it is a |
---|
528 | | // sequence of 3 unaligned bytes. |
---|
529 | | unsigned char *target = NULL; |
---|
530 | | |
---|
531 | | for ( PortVectorIterator it = m_PacketPorts.begin(); |
---|
532 | | it != m_PacketPorts.end(); |
---|
533 | | ++it ) { |
---|
534 | | |
---|
535 | | Port *port=static_cast<Port *>(*it); |
---|
536 | | assert(port); // this should not fail!! |
---|
537 | | |
---|
538 | | // Currently the only packet type of events for MOTU |
---|
539 | | // is MIDI in mbla. However in future control data |
---|
540 | | // might also be sent via "packet" events. |
---|
541 | | // assert(pinfo->getFormat()==MotuPortInfo::E_Midi); |
---|
542 | | |
---|
543 | | // FIXME: MIDI output is completely untested at present. |
---|
544 | | switch (port->getPortType()) { |
---|
545 | | case Port::E_Midi: { |
---|
546 | | MotuMidiPort *mp=static_cast<MotuMidiPort *>(*it); |
---|
547 | | |
---|
548 | | // Send a byte if we can. MOTU MIDI data is |
---|
549 | | // sent using a 3-byte sequence starting at |
---|
550 | | // the port's position. For now we'll |
---|
551 | | // always send in the first event of a |
---|
552 | | // packet, but this might need refinement |
---|
553 | | // later. |
---|
554 | | if (mp->canRead()) { |
---|
555 | | mp->readEvent(&byte); |
---|
556 | | target = (unsigned char *)data + mp->getPosition(); |
---|
557 | | *(target++) = 0x01; |
---|
558 | | *(target++) = 0x00; |
---|
559 | | *(target++) = byte; |
---|
560 | | } |
---|
561 | | break; |
---|
562 | | } |
---|
563 | | default: |
---|
564 | | debugOutput(DEBUG_LEVEL_VERBOSE, "Unknown packet-type port type %d\n",port->getPortType()); |
---|
565 | | return ok; |
---|
566 | | } |
---|
567 | | } |
---|
568 | | |
---|
569 | | return ok; |
---|