~ubuntu-branches/ubuntu/oneiric/libffado/oneiric

« back to all changes in this revision

Viewing changes to src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Knoth
  • Date: 2011-05-31 17:27:58 UTC
  • mfrom: (8.3.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110531172758-s0bhfz5ufsahm422
Tags: 2.0.99+svn1985-1
Imported Upstream version 2.0.99+svn1985 (Closes: #601659)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include "libutil/ByteSwap.h"
35
35
#include <assert.h>
36
36
#include "libutil/SystemTimeSource.h"
 
37
#include <cstring>
 
38
 
 
39
#define unlikely(x) __builtin_expect((x),0)
37
40
 
38
41
namespace Streaming {
39
42
 
44
47
    , m_dimension( dimension )
45
48
    , m_nb_audio_ports( 0 )
46
49
    , m_nb_midi_ports( 0 )
 
50
    , mb_head( 0 )
 
51
    , mb_tail( 0 )
47
52
{}
48
53
 
49
54
unsigned int
428
433
        if (p.buffer && p.enabled) { 
429
434
            uint32_t *buffer = (quadlet_t *)(p.buffer);
430
435
            buffer += offset;
431
 
            for (j = p.location;j < nevents; j += 8) {
 
436
 
 
437
            /* clear output (to jackd) buffer for MIDI data */
 
438
            memset (buffer, 0, nevents*sizeof(*buffer));
 
439
 
 
440
            for (j = 0; j < nevents; j += 1) {
432
441
                target_event = (quadlet_t *) (data + ((j * m_dimension) + p.position));
433
442
                sample_int = CondSwapFromBus32(*target_event);
434
443
 
435
444
                // FIXME: this assumes that 2X and 3X speed isn't used,
436
445
                // because only the 1X slot is put into the ringbuffer
437
 
                if(IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_1X)) {
 
446
                if(unlikely(IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_1X))) {
438
447
                    sample_int=(sample_int >> 16) & 0x000000FF;
439
448
                    sample_int |= 0x01000000; // flag that there is a midi event present
440
 
                    *buffer = sample_int;
441
 
                    debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "(%p) MIDI [%d]: %08X\n", this, i, sample_int);
442
 
                } else if(IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_2X)
443
 
                       || IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_3X) ) {
444
 
                    debugOutput(DEBUG_LEVEL_VERBOSE, "Midi mode %X not supported.\n", IEC61883_AM824_GET_LABEL(sample_int));
445
 
                } else {
446
 
                    // make sure no event is received
447
 
                    *buffer = 0;
448
 
                }
449
 
                buffer+=8;
 
449
                    midibuffer[mb_head++] = sample_int;
 
450
                    mb_head &= RX_MIDIBUFFER_SIZE-1;
 
451
                    if (unlikely(mb_head == mb_tail)) {
 
452
                        debugWarning("MOTU rx MIDI buffer overflow\n");
 
453
                        /* Dump oldest byte.  This overflow can only happen if the
 
454
                         * rate coming in from the hardware MIDI port grossly
 
455
                         * exceeds the official MIDI baud rate of 31250 bps, so it
 
456
                         * should never occur in practice.
 
457
                         */
 
458
                        mb_tail = (mb_tail + 1) & (RX_MIDIBUFFER_SIZE-1);
 
459
                    }
 
460
 
 
461
                    debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "(%p) MIDI [%d]: %08X\n", this,
 
462
                            i, sample_int);
 
463
                } else if(unlikely((IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_2X)
 
464
                        || IEC61883_AM824_HAS_LABEL(sample_int, IEC61883_AM824_LABEL_MIDI_3X) ))) {
 
465
                    debugOutput(DEBUG_LEVEL_VERBOSE, "Midi mode %X not supported.\n",
 
466
                            IEC61883_AM824_GET_LABEL(sample_int));
 
467
                }
 
468
                /* Write to the buffer if we're at an 8-sample boundary */
 
469
                if (unlikely(0 == j % 8)) {
 
470
                    if (mb_head != mb_tail) {
 
471
                        *buffer = midibuffer[mb_tail++];
 
472
                        mb_tail &= RX_MIDIBUFFER_SIZE-1;
 
473
                    }
 
474
                    buffer += 8;
 
475
                }
450
476
            }
451
477
        }
452
478
    }