Changeset 430
- Timestamp:
- 03/05/07 21:47:17 (17 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/streaming-rework/src/libstreaming/MotuStreamProcessor.cpp
r428 r430 52 52 // A macro to extract specific bits from a native endian quadlet 53 53 #define get_bits(_d,_start,_len) (((_d)>>((_start)-(_len)+1)) & ((1<<(_len))-1)) 54 55 // Convert an SPH timestamp as received from the MOTU to a full timestamp in ticks. 56 static inline uint32_t sphRecvToFullTicks(uint32_t sph, uint32_t ct_now) { 57 58 uint32_t timestamp = CYCLE_TIMER_TO_TICKS(sph & 0x1ffffff); 59 uint32_t now_cycles = CYCLE_TIMER_GET_CYCLES(ct_now); 60 61 uint32_t ts_sec = CYCLE_TIMER_GET_SECS(ct_now); 62 // If the cycles have wrapped, correct ts_sec so it represents when timestamp 63 // was received. The timestamps sent by the MOTU are always 1 or two cycles 64 // in advance of the cycle timer (reasons unknown at this stage). In addition, 65 // iso buffering can delay the arrival of packets for quite a number of cycles 66 // (have seen a delay >12 cycles). 67 if (abs(CYCLE_TIMER_GET_CYCLES(sph) - now_cycles) > 1000) { 68 debugOutput(DEBUG_LEVEL_VERBOSE, "now=%d, ct=%d\n", now_cycles, CYCLE_TIMER_GET_CYCLES(sph)); 69 if (ts_sec) 70 ts_sec--; 71 else 72 ts_sec = 127; 73 } 74 return timestamp + ts_sec*TICKS_PER_SECOND; 75 } 76 77 // Convert a full timestamp into an SPH timestamp as required by the MOTU 78 static inline uint32_t fullTicksToSph(uint32_t timestamp) { 79 return timestamp & 0x1ffffff; 80 } 54 81 55 82 /* transmit */ … … 233 260 // We could (and silently junk the contents) if it turned out to be 234 261 // more helpful. 235 262 263 //if (!m_is_disabled && m_running) 264 // return RAW1394_ISO_OK; 265 //else 236 266 return RAW1394_ISO_DEFER; 237 267 } … … 284 314 float ticks_per_frame = m_SyncSource->m_data_buffer->getRate(); 285 315 for (i=0; i<n_events; i++, quadlet += dbs) { 286 unsigned int ts_frame = ts; 316 // unsigned int ts_frame = ts; 317 unsigned int ts_frame = timestamp; 287 318 ts_frame += (unsigned int)((float)i * ticks_per_frame); 288 *quadlet = htonl( TICKS_TO_CYCLE_TIMER(ts_frame) ); 319 *quadlet = htonl( TICKS_TO_CYCLE_TIMER(ts_frame) & 0x1ffffff); 320 if (cycle==0) { 321 debugOutput(DEBUG_LEVEL_VERBOSE,"%d %d %d\n", 322 TICKS_TO_SECS(ts_frame), 323 TICKS_TO_CYCLES(ts_frame), 324 TICKS_TO_OFFSET(ts_frame)); 325 } 326 #if TESTTONE 327 // FIXME: remove this hacked in 1 kHz test signal to 328 // analog-1 when testing is complete. Note that the tone is 329 // *never* added during closedown. 330 if (m_closedown_count<0) { 331 static signed int a_cx = 0; 332 signed int val; 333 val = (int)(0x7fffff*sin(1000.0*2.0*M_PI*(a_cx/24576000.0))); 334 if ((a_cx+=512) >= 24576000) { 335 a_cx -= 24576000; 336 } 337 *(data+8+i*m_event_size+16) = (val >> 16) & 0xff; 338 *(data+8+i*m_event_size+17) = (val >> 8) & 0xff; 339 *(data+8+i*m_event_size+18) = val & 0xff; 340 } 341 #endif 342 289 343 } 290 344 … … 421 475 422 476 // FIXME: check if the timestamp wraps at one second 423 m_data_buffer->setWrapValue( TICKS_PER_SECOND);477 m_data_buffer->setWrapValue(128L*TICKS_PER_SECOND); 424 478 425 479 m_data_buffer->prepare(); … … 971 1025 //uint32_t first_sph = ntohl(*(quadlet_t *)(data+8+(event_length*(n_events-1)))); 972 1026 // m_last_timestamp = ((first_sph & 0x1fff000)>>12)*3072 + (first_sph & 0xfff); 973 m_last_timestamp = CYCLE_TIMER_TO_TICKS(first_sph & 0x1ffffff); 1027 // m_last_timestamp = CYCLE_TIMER_TO_TICKS(first_sph & 0x1ffffff); 1028 m_last_timestamp = sphRecvToFullTicks(first_sph, m_handler->getCycleTimer()); 974 1029 975 1030 // Signal that we're running … … 997 1052 // set the timestamp as if there will be a sample put into 998 1053 // the buffer by the next packet. 999 if (ts > TICKS_PER_SECOND)1000 ts -= TICKS_PER_SECOND;1054 if (ts >= 128L* TICKS_PER_SECOND) 1055 ts -= 128L*TICKS_PER_SECOND; 1001 1056 m_data_buffer->setBufferTailTimestamp(ts); 1002 1057 //debugOutput(DEBUG_LEVEL_VERBOSE,"%p, last ts=%lld, ts=%lld, lts2=%lld\n", m_data_buffer, m_last_timestamp, ts, m_last_timestamp2); … … 1104 1159 m_data_buffer->setNominalRate(m_ticks_per_frame); 1105 1160 1106 m_data_buffer->setWrapValue( TICKS_PER_SECOND);1161 m_data_buffer->setWrapValue(128L*TICKS_PER_SECOND); 1107 1162 1108 1163 m_data_buffer->prepare();