Changeset 577

Show
Ignore:
Timestamp:
08/27/07 16:58:41 (14 years ago)
Author:
jwoithe
Message:

MOTU: more incidental code tidy-ups and reorderings to produce slight increases in efficiency. No functional changes.
MOTU: make the 1kHz test tone independent of sampling frequency.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/libstreaming/MotuStreamProcessor.cpp

    r515 r577  
    121121 
    122122    int fc; 
    123     int64_t ts_head; 
    124123    ffado_timestamp_t ts_tmp; 
    125124    quadlet_t *quadlet = (quadlet_t *)data; 
     
    170169            // initialize the buffer head & tail 
    171170            m_SyncSource->m_data_buffer->getBufferHeadTimestamp(&ts_tmp, &fc); // thread safe 
    172             ts_head = (int64_t)ts_tmp; 
     171            int64_t ts_head = (int64_t)ts_tmp; 
    173172 
    174173            // the number of cycles the sync source lags (> 0) 
     
    232231    // the base timestamp is the one of the next sample in the buffer 
    233232    m_data_buffer->getBufferHeadTimestamp(&ts_tmp, &fc); // thread safe 
    234     ts_head = (int64_t)ts_tmp; 
    235     int64_t timestamp = ts_head; 
     233    int64_t timestamp = (int64_t)ts_tmp; 
    236234 
    237235    // we send a packet some cycles in advance, to avoid the 
     
    251249    ticks_to_advance += (int64_t)cycle_diff * TICKS_PER_CYCLE; 
    252250 
    253  
    254251    // time until the packet is to be sent (if <= 0: send packet) 
    255252    // For Amdtp this looked like 
     
    291288    // shutdown if the buffer is read during this time. 
    292289    if (m_closedown_count!=-1 || m_data_buffer->readFrames(n_events, (char *)(data + 8))) { 
     290        float ticks_per_frame = m_SyncSource->m_data_buffer->getRate(); 
    293291 
    294292#if TESTTONE 
     
    297295        // *never* added during closedown. 
    298296        if (m_closedown_count<0) { 
    299             for (i=0; i<n_events; i++) { 
     297            signed int int_tpf = (int)ticks_per_frame; 
     298            unsigned char *sample = data+8+16; 
     299            for (i=0; i<n_events; i++, sample+=m_event_size) { 
    300300                static signed int a_cx = 0; 
    301                 signed int val; 
    302                 val = (int)(0x7fffff*sin(1000.0*2.0*M_PI*(a_cx/24576000.0))); 
    303                 if ((a_cx+=512) >= 24576000) { 
     301                // Each sample is 3 bytes with MSB in lowest address (ie:  
     302                // network byte order).  After byte order swap, the 24-bit 
     303                // MSB is in the second byte of val. 
     304                signed int val = htonl((int)(0x7fffff*sin((1000.0*2.0*M_PI/24576000.0)*a_cx))); 
     305                memcpy(sample,((char *)&val)+1,3); 
     306                if ((a_cx+=int_tpf) >= 24576000) { 
    304307                    a_cx -= 24576000; 
    305308                } 
    306                 *(data+8+i*m_event_size+16) = (val >> 16) & 0xff; 
    307                 *(data+8+i*m_event_size+17) = (val >> 8) & 0xff; 
    308                 *(data+8+i*m_event_size+18) = val & 0xff; 
    309309            } 
    310310        } 
     
    346346            m_startup_count--; 
    347347 
    348         // Set up each frames's SPH.  Note that the (int) typecast 
    349         // appears to do rounding. 
    350  
    351         float ticks_per_frame = m_SyncSource->m_data_buffer->getRate(); 
     348        // Set up each frames's SPH. 
    352349        for (i=0; i<n_events; i++, quadlet += dbs) { 
    353350//FIXME: not sure which is best for the MOTU