Changeset 291

Show
Ignore:
Timestamp:
07/17/06 00:44:27 (18 years ago)
Author:
jwoithe
Message:

Seed the SPH cycle DLL when the receive stream is running but disabled; this
means the DLL has a sensible figure when the transmit stream is enabled.
More testing to work out why device resync (as distinct from rx/tx sync)
doesn't seem to work.

Files:

Legend:

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

    r289 r291  
    103103        m_running = true; 
    104104         
     105        // Initialise the cycle counter if this is the first time 
     106        // iso data has been requested. 
     107        if (!m_disabled && m_cycle_count<0) { 
     108debugOutput(DEBUG_LEVEL_VERBOSE, "tx enabled at cycle %d, dll=%g\n",cycle, 
     109  m_sph_ofs_dll->get()); 
     110                m_cycle_count = cycle; 
     111                m_cycle_ofs = 0.0; 
     112        } 
     113 
     114        // Do housekeeping expected for all packets sent to the MOTU, even 
     115        // for packets containing no audio data. 
     116        *sy = 0x00; 
     117        *tag = 1;      // All MOTU packets have a CIP-like header 
     118 
     119        debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "get packet...\n"); 
     120 
     121        // Size of a single data frame in quadlets 
     122        unsigned dbs = m_event_size / 4; 
     123 
     124        // The number of events expected by the MOTU is solely dependent on 
     125        // the current sample rate.  An 'event' is one sample from all channels 
     126        // plus possibly other midi and control data. 
     127        signed n_events = m_framerate<=48000?8:(m_framerate<=96000?16:32); 
     128 
    105129// FIXME: some tests - attempt to recover sync after loss due to missed cycles 
    106130static signed int next_cycle = -1; 
     131static suseconds_t last_us = -1; 
     132struct timeval tv; 
     133gettimeofday(&tv, NULL); 
    107134if (!m_disabled && next_cycle>=0 && cycle!=next_cycle) { 
    108135  debugOutput(DEBUG_LEVEL_VERBOSE, "tx cycle miss: %d requested, %d expected\n",cycle,next_cycle); 
     136  debugOutput(DEBUG_LEVEL_VERBOSE, "tx stream: cycle=%d, ofs=%g\n",m_cycle_count, m_cycle_ofs); 
    109137  // Try to pick up the transmit sequence as best we can.  This only works 
    110138  // some of the time for some reason. 
    111   m_cycle_count = -1; 
     139//  m_cycle_count = -1; 
     140debugOutput(DEBUG_LEVEL_VERBOSE, "now=%d, last call=%d, diff=%d\n", 
     141  tv.tv_usec, last_us, tv.tv_usec>last_us?(tv.tv_usec-last_us):(1000000-last_us+tv.tv_usec)); 
     142 
     143#if 0 
     144m_cycle_count = cycle; 
     145m_cycle_ofs = 0.0; 
     146m_tx_dbc = 0; 
     147#else 
     148signed int ccount, fcount; 
     149 
     150  ccount = next_cycle; 
     151  while (ccount!=cycle) { 
     152    if (ccount < m_cycle_count) { 
     153      if (++ccount == 8000) 
     154        ccount = 0; 
     155      continue; 
     156    } 
     157    m_tx_dbc += n_events; 
     158    if (m_tx_dbc > 0xff) 
     159      m_tx_dbc -= 0x100; 
     160    for (fcount=0; fcount<n_events; fcount++) { 
     161      m_cycle_ofs += m_sph_ofs_dll->get(); 
     162      if (m_cycle_ofs >= 3072) { 
     163        m_cycle_ofs -= 3072; 
     164        if (++m_cycle_count > 7999) 
     165          m_cycle_count -= 8000; 
     166      } 
     167    } 
     168    if (++ccount == 8000) 
     169      ccount = 0; 
     170  } 
     171#endif 
     172  debugOutput(DEBUG_LEVEL_VERBOSE, "  resuming with cyclecount=%d, cycleofs=%g (dll=%g)\n", 
     173    m_cycle_count, m_cycle_ofs, m_sph_ofs_dll->get()); 
    112174} 
    113175if (!m_disabled) 
     
    115177else 
    116178  next_cycle = -1; 
    117  
    118         // Initialise the cycle counter if this is the first time 
    119         // iso data has been requested. 
    120         if (!m_disabled && m_cycle_count<0) { 
    121                 m_cycle_count = cycle; 
    122                 m_cycle_ofs = 0.0; 
    123         } 
    124  
    125         // Do housekeeping expected for all packets sent to the MOTU, even 
    126         // for packets containing no audio data. 
    127         *sy = 0x00; 
    128         *tag = 1;      // All MOTU packets have a CIP-like header 
    129  
    130         debugOutput( DEBUG_LEVEL_VERY_VERBOSE, "get packet...\n"); 
    131  
    132         // Size of a single data frame in quadlets 
    133         unsigned dbs = m_event_size / 4; 
    134  
    135         // The number of events expected by the MOTU is solely dependent on 
    136         // the current sample rate.  An 'event' is one sample from all channels 
    137         // plus possibly other midi and control data. 
    138         signed n_events = m_framerate<=48000?8:(m_framerate<=96000?16:32); 
     179last_us = tv.tv_usec; 
    139180 
    140181        // Increment the dbc (data block count).  This is only done if the 
     
    793834        // would see if the audio clock was locked to the ieee1394 cycle 
    794835        // timer. 
    795         // FIXME: the value for omega and coeff[0] are more or less copied 
    796         // from the test-dll.cpp code.  They need to be understood and 
    797         // optimised for this process. 
    798         float omega=6.28*0.001; 
     836        // FIXME: the value for the coefficient may be optimisable; the 
     837        // value used currently just mirrors that used in 
     838        // AmdtpReceiveStreamProcessor::putPacket for a similar purpose. 
    799839        float coeffs[1]; 
    800         coeffs[0]=1.41*omega
     840        coeffs[0]=0.0005
    801841        m_sph_ofs_dll = new FreebobUtil::DelayLockedLoop(1, coeffs); 
    802842        m_sph_ofs_dll->setIntegrator(0, 24576000.0/framerate); 
     
    834874//  fprintf(stderr, "sph_ofs_dll=%g\n",m_sph_ofs_dll->get()); 
    835875//} 
     876 
     877// FIXME: more debugging 
     878static signed int last_cycle=-1; 
     879if (last_cycle>=0 && (signed)cycle!=(last_cycle+1)%8000) { 
     880  debugOutput(DEBUG_LEVEL_VERBOSE, "lost rx cycles; received %d, expected %d\n", 
     881    cycle, (last_cycle+1)%8000); 
     882} 
     883last_cycle=cycle; 
    836884 
    837885    // If the packet length is 8 bytes (ie: just a CIP-like header) there is 
     
    855903        // Signal that we're running 
    856904        if (n_events) m_running=true; 
     905 
     906#if 1 
     907        /* FIXME: test whether things are improved by doing this in the 
     908         * actual receive handler.  The advantage is that we don't have to 
     909         * wait until the stream is enabled before the DLL starts tracking.  
     910         * This has the desireable side-effect of having a relatively 
     911         * accurate value in the DLL by the time the transmit stream is 
     912         * enabled.  A disadvantage of having this in here is that it 
     913         * increases the time spent in this function.  Whether this is 
     914         * important in practice remains to be seen.  Ad hoc evidence thus 
     915         * far seems to suggest that it does increase the chances of a 
     916         * faulty startup, but more tests are needed. 
     917         */ 
     918        /* Push cycle offset differences from each event's SPH into the DLL. 
     919         * If this is the very first block received, use the first event to 
     920         * initialise the last cycle offset. 
     921         * FIXME: it might be best to use differences only within the given 
     922         * block rather than keeping a store of the last cycle offset. 
     923         * Otherwise in the event of a lost incoming packet the DLL will 
     924         * have an abnormally large value sent to it.  Perhaps this doesn't 
     925         * matter? 
     926         */ 
     927        unsigned int ev; 
     928        signed int sph_ofs = ntohl(*(quadlet_t *)(data+8)) & 0xfff; 
     929 
     930//      if (m_last_cycle_ofs < 0) { 
     931//              m_last_cycle_ofs = sph_ofs-(int)m_sph_ofs_dll->get(); 
     932//      } 
     933        m_last_cycle_ofs = sph_ofs; 
     934        for (ev=1; ev<n_events; ev++) { 
     935                sph_ofs = ntohl(*(quadlet_t *)(data+8+ev*m_event_size)) & 0xfff; 
     936                m_sph_ofs_dll->put((m_last_cycle_ofs<sph_ofs)? 
     937                        sph_ofs-m_last_cycle_ofs:sph_ofs+3072-m_last_cycle_ofs); 
     938                m_last_cycle_ofs = sph_ofs; 
     939        } 
     940#endif 
     941 
     942 
    857943 
    858944        // Don't process the stream when it is not enabled. 
     
    11341220{ 
    11351221        int problem=0; 
    1136  
     1222#if 0 
    11371223        /* Push cycle offset differences from each event's SPH into the DLL. 
    11381224         * If this is the very first block received, use the first event to 
     
    11561242                m_last_cycle_ofs = sph_ofs; 
    11571243        } 
    1158  
     1244#endif 
    11591245        for ( PortVectorIterator it = m_PeriodPorts.begin(); 
    11601246          it != m_PeriodPorts.end(); 
  • branches/libfreebob-2.0/src/libstreaming/StreamProcessorManager.cpp

    r287 r291  
    448448                m_isoManager->enablePolling(*it); 
    449449        } 
    450          
     450 
    451451        for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
    452452                it != m_TransmitProcessors.end();