Changeset 284

Show
Ignore:
Timestamp:
07/03/06 16:23:50 (16 years ago)
Author:
jwoithe
Message:

More MOTU iso transmission work. Things are now partially operational.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libfreebob-2.0/src/libstreaming/MotuStreamProcessor.cpp

    r283 r284  
    8787#define CYCLE_DELAY 1 
    8888 
     89// FIXME: currently data is not sent when the stream is disabled.  The 
     90// trouble is that the MOTU actually needs zero data explicitly sent from 
     91// the moment its iso receive channel is activated; failure to do so can 
     92// result in a high pitch audio signal (approx 10 kHz) in channels which 
     93// have had non-zero data in the past.  Things need to be changed around so 
     94// this can be done; essentially the tests on m_disabled disappear from 
     95// almost everywhere.  Instead, m_disabled will determine whether data is 
     96// fetched from the event buffer or whether zero data is generated. 
     97// 
     98// The other thing which needs to be worked out is close-down. 
     99// Experimentation has shown that 2 or so zero packets need to be sent so no 
     100// high-pitched noises are emitted at closedown and subsequent restart.  In 
     101// the proof-of-concept code this was done by manually calling 
     102// raw1394_loop_iterate() from the iso shutdown function.  Under freebob a 
     103// similar thing needs to be done from the respective function in the Motu 
     104// AvDevice object, but the precise way of doing so without causing issues 
     105// is yet to be determined. 
     106// 
     107// Finally, every so often sync seems to be missed on startup, and because 
     108// this code can't recover a sync the problem remains indefinitely.  The 
     109// cause of this needs to be identified.  It may be the result of not 
     110// running with RT privileges for this initial testing phase. 
     111 
    89112        enum raw1394_iso_disposition retval = RAW1394_ISO_OK; 
    90113        quadlet_t *quadlet = (quadlet_t *)data; 
     
    102125         
    103126        // Initialise the cycle counter if this is the first time 
    104         // iso data has been requested
    105         if (m_cycle_count < 0) { 
     127        // iso data has been requested with the stream enabled
     128        if (!m_disabled && m_cycle_count<0) { 
    106129                m_cycle_count = cycle; 
    107130                m_cycle_ofs = 0.0; 
     
    113136        *tag = 1;      // All MOTU packets have a CIP-like header 
    114137 
    115 // FIXME: for now always just return NULL packets 
    116 //*length = 0; 
    117 //*tag = 0; 
    118 //*sy = 0; 
    119 //freebob_ringbuffer_read_advance(m_event_buffer, 6*m_event_size); 
    120 //incrementFrameCounter(6); 
    121 //return RAW1394_ISO_OK; 
    122          
    123138        debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "get packet...\n"); 
    124          
     139 
    125140        // Size of a single data frame in quadlets 
    126141        unsigned dbs = m_event_size / 4; 
     
    138153        // have a DBC of n_events, which matches what is observed from other 
    139154        // systems. 
    140         if (!m_disabled && m_cycle_count<=cycle) { 
     155        if (!m_disabled && cycle>=m_cycle_count) { 
    141156                m_tx_dbc += n_events; 
    142157                if (m_tx_dbc > 0xff) 
     
    157172        // ahead of the ieee1394 cycle timer, we send a data-less packet 
    158173        // with only the 8 byte CIP-like header set up previously. 
    159         if (m_disabled || m_cycle_count>cycle) { 
     174        // FIXME: in disabled state, need to send a stream of zero audio data, 
     175        // not "no data".  Otherwise MOTU will emit an (approx) 10 kHz signal. 
     176        if (m_disabled || cycle<m_cycle_count) { 
    160177                return RAW1394_ISO_OK; 
    161178        } 
     
    182199                *length += read_size; 
    183200 
    184 #if 0 
    185 if (cycle<=10) { 
    186   fprintf(stderr,"cycle %d, sending %d/%d (dbs %d)\n",cycle, 
    187     m_cycle_count, (int)m_cycle_ofs, dbs); 
    188 } 
    189 #endif 
    190201                // Set up each frames's SPH.  Note that the (int) typecast 
    191202                // appears to do rounding. 
     
    195206                        *quadlet = htonl( (((m_cycle_count+CYCLE_DELAY)%8000)<<12) +  
    196207                                        (int)m_cycle_ofs); 
     208// FIXME: remove this hacked in 1 kHz test signal to analog-1 
     209{ 
     210signed int val; 
     211val = 0x7fffff*sin(1000.0*2.0*M_PI*(m_cycle_count+((m_cycle_ofs)/3072.0))/8000.0); 
     212*(data+8+i*m_event_size+16) = (val >> 16) & 0xff; 
     213*(data+8+i*m_event_size+17) = (val >> 8) & 0xff; 
     214*(data+8+i*m_event_size+18) = val & 0xff; 
     215} 
    197216                        m_cycle_ofs += m_sph_ofs_dll->get(); 
    198217                        if (m_cycle_ofs >= 3072) { 
     
    213232} 
    214233#endif 
    215 #if 0 
    216 int j, glitch=0; 
    217 j=0; 
    218 while (j<n_events && !glitch) { 
    219   glitch=*(data+8+j*dbs*4+22)!=0 || *(data+8+j*dbs*4+23)!=0 ||*(data+8+j*dbs*4+24)!=0; 
    220   j++; 
    221 } 
    222 if (glitch) { 
    223   for (j=0; j<n_events; j++) { 
    224     for (i=0; i<27; i++) 
    225       fprintf(stderr,"%02hhx ",*(data+8+j*dbs*4+i)); 
    226     fprintf(stderr,"\n"); 
    227   } 
    228   fprintf(stderr,"\n"); 
    229 } 
    230 #endif 
    231  
    232  
    233234                // Process all ports that should be handled on a per-packet base 
    234235                // this is MIDI for AMDTP (due to the need of DBC, which is lost  
     
    677678        case Port::E_Int24: 
    678679        case Port::E_Float: 
    679 // send silence to all but selected analog channels 
     680// send silence to all outputs for now 
    680681                for (j = 0; j < nevents; j++) { 
    681 signed int val; 
    682 if (p->getPosition() == 16) { 
    683   val = 0x7fffff*sin(1000.0*2.0*M_PI*(m_cycle_count+((m_cycle_ofs+j*512)/3072.0))/8000.0); 
    684 //val = 0; 
    685 //  fprintf(stderr,".%d.",val); 
    686 } else 
     682signed int val = 0; 
    687683  val = 0; 
    688684                        *target = (val >> 16) & 0xff;