Changeset 294

Show
Ignore:
Timestamp:
07/19/06 00:05:56 (16 years ago)
Author:
jwoithe
Message:

More device sync tests.

Files:

Legend:

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

    r291 r294  
    129129// FIXME: some tests - attempt to recover sync after loss due to missed cycles 
    130130static signed int next_cycle = -1; 
    131 static suseconds_t last_us = -1; 
    132 struct timeval tv; 
    133 gettimeofday(&tv, NULL); 
     131//static suseconds_t last_us = -1; 
     132//struct timeval tv; 
     133//gettimeofday(&tv, NULL); 
    134134if (!m_disabled && next_cycle>=0 && cycle!=next_cycle) { 
    135135  debugOutput(DEBUG_LEVEL_VERBOSE, "tx cycle miss: %d requested, %d expected\n",cycle,next_cycle); 
    136136  debugOutput(DEBUG_LEVEL_VERBOSE, "tx stream: cycle=%d, ofs=%g\n",m_cycle_count, m_cycle_ofs); 
    137   // Try to pick up the transmit sequence as best we can.  This only works 
    138   // some of the time for some reason. 
    139 //  m_cycle_count = -1; 
    140 debugOutput(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)); 
     137//debugOutput(DEBUG_LEVEL_VERBOSE, "now=%d, last call=%d, diff=%d\n", 
     138//  tv.tv_usec, last_us, tv.tv_usec>last_us?(tv.tv_usec-last_us):(1000000-last_us+tv.tv_usec)); 
    142139 
    143140#if 0 
     141// This "simple" way out doesn't work, probably because there's no 
     142// guarantee that ofs 0 in the current cycle is anywhere near an audio 
     143// sample point. 
    144144m_cycle_count = cycle; 
    145145m_cycle_ofs = 0.0; 
    146146m_tx_dbc = 0; 
    147147#else 
     148float ftmp; 
     149 
     150// Calculate values of m_cycle_{count,ofs} which would be present 
     151// for this cycle if the missed cycles hadn't been missed. 
     152// These mathematical gymnastics *should* be functionally equivalent to 
     153// the loop below.  Once it has proven correct it can replace the loop 
     154// since it will be much faster most of the time. 
     155signed int n_missed = (cycle>next_cycle)?cycle-next_cycle:8000-next_cycle+cycle; 
     156signed int ma = ((n_events/2)+n_missed*3072.0/m_sph_ofs_dll->get())/n_events; 
     157ma*=n_events; 
     158ftmp = m_cycle_ofs+ma*m_sph_ofs_dll->get(); 
     159//m_cycle_count = (int)(m_cycle_count+ftmp/3072) % 8000; 
     160//m_cycle_ofs = fmod(ftmp, 3072); 
     161//m_tx_dbc = (m_tx_dbc + ma) & 0xff; 
     162debugOutput(DEBUG_LEVEL_VERBOSE, " calc %d: count=%d, ofs=%g\n", 
     163  ma, 
     164  (int)(m_cycle_count+ftmp/3072) % 8000, 
     165  fmod(ftmp,3072) 
     166); 
     167 
    148168signed int ccount, fcount; 
    149169 
     
    156176    } 
    157177    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     } 
     178 
     179//    for (fcount=0; fcount<n_events; fcount++) { 
     180//      m_cycle_ofs += m_sph_ofs_dll->get(); 
     181//      if (m_cycle_ofs >= 3072) { 
     182//        m_cycle_ofs -= 3072; 
     183//        if (++m_cycle_count > 7999) 
     184//          m_cycle_count -= 8000; 
     185//      } 
     186//    } 
     187// Replace the above for loop with direct calculations to 
     188// improve efficiency. 
     189    ftmp = m_cycle_ofs+n_events*m_sph_ofs_dll->get(); 
     190    m_cycle_count += ftmp/3072; 
     191    m_cycle_ofs = fmod(ftmp, 3072); 
     192 
    168193    if (++ccount == 8000) 
    169194      ccount = 0; 
    170195  } 
     196  m_tx_dbc &= 0xff; 
     197  m_cycle_count %= 8000; 
     198 
    171199#endif 
    172200  debugOutput(DEBUG_LEVEL_VERBOSE, "  resuming with cyclecount=%d, cycleofs=%g (dll=%g)\n", 
     
    177205else 
    178206  next_cycle = -1; 
    179 last_us = tv.tv_usec; 
     207//last_us = tv.tv_usec; 
    180208 
    181209        // Increment the dbc (data block count).  This is only done if the