Changeset 1525
- Timestamp:
- 03/28/09 14:24:21 (15 years ago)
- Files:
-
- branches/libffado-2.0/config.h.in (modified) (2 diffs)
- branches/libffado-2.0/src/genericavc/avc_avdevice.cpp (modified) (4 diffs)
- branches/libffado-2.0/src/libieee1394/CycleTimerHelper.cpp (modified) (13 diffs)
- branches/libffado-2.0/src/libieee1394/CycleTimerHelper.h (modified) (1 diff)
- branches/libffado-2.0/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp (modified) (1 diff)
- branches/libffado-2.0/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp (modified) (7 diffs)
- branches/libffado-2.0/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.h (modified) (2 diffs)
- branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.cpp (modified) (8 diffs)
- branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.h (modified) (2 diffs)
- branches/libffado-2.0/src/libutil/Configuration.cpp (modified) (2 diffs)
- branches/libffado-2.0/src/libutil/Configuration.h (modified) (2 diffs)
- branches/libffado-2.0/src/libutil/TimestampedBuffer.cpp (modified) (5 diffs)
- branches/libffado-2.0/src/libutil/TimestampedBuffer.h (modified) (1 diff)
- branches/libffado-2.0/src/motu/motu_avdevice.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/libffado-2.0/config.h.in
r1496 r1525 108 108 #define IEEE1394SERVICE_USE_CYCLETIMER_DLL 1 109 109 #define IEEE1394SERVICE_CYCLETIMER_DLL_UPDATE_INTERVAL_USEC 200000 110 #define IEEE1394SERVICE_CYCLETIMER_DLL_BANDWIDTH_HZ 0.5 110 111 #define IEEE1394SERVICE_MAX_FIREWIRE_PORTS 4 111 112 #define IEEE1394SERVICE_MIN_SPLIT_TIMEOUT_USECS 1000000 … … 205 206 #define STREAMPROCESSORMANAGER_DYNAMIC_SYNC_DELAY 0 206 207 207 // FIXME: note that it will probably be better to use a DLL bandwidth that is 208 // dependant on the sample rate 209 #define TIMESTAMPEDBUFFER_DLL_BANDWIDTH (0.01) 208 // the default bandwidth of the stream processor timestamp DLL 209 #define STREAMPROCESSOR_DLL_BW_HZ 0.1 210 210 211 211 // -- AMDTP options -- // branches/libffado-2.0/src/genericavc/avc_avdevice.cpp
r1414 r1525 529 529 } 530 530 531 // get the device specific and/or global SP configuration 532 Util::Configuration &config = getDeviceManager().getConfiguration(); 533 // base value is the config.h value 534 float recv_sp_dll_bw = STREAMPROCESSOR_DLL_BW_HZ; 535 float xmit_sp_dll_bw = STREAMPROCESSOR_DLL_BW_HZ; 536 537 int xmit_max_cycles_early_transmit = AMDTP_MAX_CYCLES_TO_TRANSMIT_EARLY; 538 int xmit_transfer_delay = AMDTP_TRANSMIT_TRANSFER_DELAY; 539 int xmit_min_cycles_before_presentation = AMDTP_MIN_CYCLES_BEFORE_PRESENTATION; 540 541 // we can override that globally 542 config.getValueForSetting("streaming.common.recv_sp_dll_bw", recv_sp_dll_bw); 543 config.getValueForSetting("streaming.common.xmit_sp_dll_bw", xmit_sp_dll_bw); 544 config.getValueForSetting("streaming.amdtp.xmit_max_cycles_early_transmit", xmit_max_cycles_early_transmit); 545 config.getValueForSetting("streaming.amdtp.xmit_transfer_delay", xmit_transfer_delay); 546 config.getValueForSetting("streaming.amdtp.xmit_min_cycles_before_presentation", xmit_min_cycles_before_presentation); 547 548 // or override in the device section 549 uint32_t vendorid = getConfigRom().getNodeVendorId(); 550 uint32_t modelid = getConfigRom().getModelId(); 551 config.getValueForDeviceSetting(vendorid, modelid, "recv_sp_dll_bw", recv_sp_dll_bw); 552 config.getValueForDeviceSetting(vendorid, modelid, "xmit_sp_dll_bw", xmit_sp_dll_bw); 553 config.getValueForDeviceSetting(vendorid, modelid, "xmit_max_cycles_early_transmit", xmit_max_cycles_early_transmit); 554 config.getValueForDeviceSetting(vendorid, modelid, "xmit_transfer_delay", xmit_transfer_delay); 555 config.getValueForDeviceSetting(vendorid, modelid, "xmit_min_cycles_before_presentation", xmit_min_cycles_before_presentation); 556 557 // initialize the SP's 531 558 debugOutput( DEBUG_LEVEL_VERBOSE, "Initializing receive processor...\n"); 532 559 // create & add streamprocessors … … 549 576 Streaming::Port::E_Capture)) { 550 577 debugFatal("Could not add plug to processor!\n"); 578 delete p; 579 return false; 580 } 581 582 if(!p->setDllBandwidth(recv_sp_dll_bw)) { 583 debugFatal("Could not set DLL bandwidth\n"); 551 584 delete p; 552 585 return false; … … 568 601 #if AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT 569 602 // FIXME: it seems that some BeBoB devices can't handle NO-DATA without payload 603 // FIXME: make this a config value too 570 604 t->sendPayloadForNoDataPackets(true); 571 605 #endif 606 607 // transmit control parameters 608 t->setMaxCyclesToTransmitEarly(xmit_max_cycles_early_transmit); 609 t->setTransferDelay(xmit_transfer_delay); 610 t->setMinCyclesBeforePresentation(xmit_min_cycles_before_presentation); 611 572 612 p=t; 573 613 } … … 586 626 return false; 587 627 } 628 if(!p->setDllBandwidth(recv_sp_dll_bw)) { 629 debugFatal("Could not set DLL bandwidth\n"); 630 delete p; 631 return false; 632 } 588 633 } else { 589 634 if (!addPlugToProcessor(*inputPlug, p, 590 635 Streaming::Port::E_Playback)) { 591 636 debugFatal("Could not add plug to processor!\n"); 637 return false; 638 } 639 if(!p->setDllBandwidth(xmit_sp_dll_bw)) { 640 debugFatal("Could not set DLL bandwidth\n"); 641 delete p; 592 642 return false; 593 643 } branches/libffado-2.0/src/libieee1394/CycleTimerHelper.cpp
r1524 r1525 32 32 33 33 #define DLL_PI (3.141592653589793238) 34 #define DLL_2PI (2 * DLL_PI) 34 35 #define DLL_SQRT2 (1.414213562373095049) 35 36 // the high-bandwidth coefficients are used37 // to speed up inital tracking38 #define DLL_BANDWIDTH_HIGH (0.1)39 #define DLL_OMEGA_HIGH (2.0*DLL_PI*DLL_BANDWIDTH_HIGH)40 #define DLL_COEFF_B_HIGH (DLL_SQRT2 * DLL_OMEGA_HIGH)41 #define DLL_COEFF_C_HIGH (DLL_OMEGA_HIGH * DLL_OMEGA_HIGH)42 43 // the low-bandwidth coefficients are used once we have a44 // good estimate of the internal parameters45 #define DLL_BANDWIDTH (0.1)46 #define DLL_OMEGA (2.0*DLL_PI*DLL_BANDWIDTH)47 #define DLL_COEFF_B (DLL_SQRT2 * DLL_OMEGA)48 #define DLL_COEFF_C (DLL_OMEGA * DLL_OMEGA)49 50 // is 1 sec51 #define UPDATES_WITH_HIGH_BANDWIDTH \52 (1000000 / IEEE1394SERVICE_CYCLETIMER_DLL_UPDATE_INTERVAL_USEC)53 36 54 37 IMPL_DEBUG_MODULE( CycleTimerHelper, CycleTimerHelper, DEBUG_LEVEL_NORMAL ); … … 68 51 , m_cycle_timer_prev ( 0 ) 69 52 , m_cycle_timer_ticks_prev ( 0 ) 70 , m_high_bw_updates ( UPDATES_WITH_HIGH_BANDWIDTH )71 53 , m_current_shadow_idx ( 0 ) 72 54 , m_Thread ( NULL ) … … 78 60 { 79 61 debugOutput( DEBUG_LEVEL_VERBOSE, "Create %p...\n", this); 62 63 double bw_rel = IEEE1394SERVICE_CYCLETIMER_DLL_BANDWIDTH_HZ*((double)update_period_us)/1e6; 64 m_dll_coeff_b = bw_rel * (DLL_SQRT2 * DLL_2PI); 65 m_dll_coeff_c = bw_rel * bw_rel * DLL_2PI * DLL_2PI; 66 80 67 } 81 68 … … 94 81 , m_cycle_timer_prev ( 0 ) 95 82 , m_cycle_timer_ticks_prev ( 0 ) 96 , m_high_bw_updates ( UPDATES_WITH_HIGH_BANDWIDTH )97 83 , m_current_shadow_idx ( 0 ) 98 84 , m_Thread ( NULL ) … … 104 90 { 105 91 debugOutput( DEBUG_LEVEL_VERBOSE, "Create %p...\n", this); 92 93 double bw_rel = IEEE1394SERVICE_CYCLETIMER_DLL_BANDWIDTH_HZ*((double)update_period_us)/1e6; 94 m_dll_coeff_b = bw_rel * (DLL_SQRT2 * DLL_2PI); 95 m_dll_coeff_c = bw_rel * bw_rel * DLL_2PI * DLL_2PI; 106 96 } 107 97 … … 189 179 debugOutput( DEBUG_LEVEL_VERBOSE, "requesting DLL re-init...\n" ); 190 180 Util::SystemTimeSource::SleepUsecRelative(1000); // some time to settle 191 m_high_bw_updates = UPDATES_WITH_HIGH_BANDWIDTH;192 181 if(!initDLL()) { 193 182 debugError("(%p) Could not init DLL\n", this); … … 283 272 uint64_t cycle_timer_ticks; 284 273 274 double bw_rel = m_dll_coeff_b / (DLL_SQRT2 * DLL_2PI); 275 double bw_abs = bw_rel / (m_usecs_per_update / 1e6); 276 if (bw_rel > 0.5) { 277 double bw_max = 0.5 / (m_usecs_per_update / 1e6); 278 debugWarning("Specified DLL bandwidth too high (%f > %f), reducing to max." 279 " Increase the DLL update rate to increase the max DLL bandwidth\n", bw_abs, bw_max); 280 281 bw_rel = 0.49; 282 bw_abs = bw_rel / (m_usecs_per_update / 1e6); 283 m_dll_coeff_b = bw_rel * (DLL_SQRT2 * DLL_2PI); 284 m_dll_coeff_c = bw_rel * bw_rel * DLL_2PI * DLL_2PI; 285 } 286 285 287 if(!readCycleTimerWithRetry(&cycle_timer, &local_time, 10)) { 286 288 debugError("Could not read cycle timer register\n"); … … 305 307 m_next_time_ticks = addTicks( (uint64_t)m_current_time_ticks, (uint64_t)m_dll_e2); 306 308 debugOutput(DEBUG_LEVEL_VERBOSE, " (%p) First run\n", this); 309 debugOutput(DEBUG_LEVEL_VERBOSE, " DLL bandwidth: %f Hz (rel: %f)\n", 310 bw_abs, bw_rel); 307 311 debugOutput(DEBUG_LEVEL_VERBOSE, 308 312 " usecs/update: %lu, ticks/update: %lu, m_dll_e2: %f\n", … … 383 387 384 388 // check for unrealistic CTR reads (NEC controller does that sometimes) 385 not_good = (-err_ticks > 1*TICKS_PER_ HALFCYCLE || err_ticks > 1*TICKS_PER_HALFCYCLE);389 not_good = (-err_ticks > 1*TICKS_PER_CYCLE || err_ticks > 1*TICKS_PER_CYCLE); 386 390 if(not_good) { 387 391 debugOutput(DEBUG_LEVEL_VERBOSE, … … 389 393 this, err_ticks, 1*TICKS_PER_CYCLE, ntries, expected_ticks); 390 394 // sleep half a cycle to make sure the hardware moved on 391 Util::SystemTimeSource::SleepUsecRelative(USECS_PER_CYCLE /2);395 Util::SystemTimeSource::SleepUsecRelative(USECS_PER_CYCLE); 392 396 } 393 397 … … 477 481 478 482 // decide what coefficients to use 479 double coeff_b, coeff_c;480 if (m_high_bw_updates > 0) {481 coeff_b = DLL_COEFF_B_HIGH;482 coeff_c = DLL_COEFF_C_HIGH;483 m_high_bw_updates--;484 if (m_high_bw_updates == 0) {485 debugOutput(DEBUG_LEVEL_VERBOSE,486 "Switching to low-bandwidth coefficients\n");487 }488 } else {489 coeff_b = DLL_COEFF_B;490 coeff_c = DLL_COEFF_C;491 }492 483 493 484 // it should be ok to not do this in tick space … … 500 491 501 492 double diff_ticks_corr_d = (double)diff_ticks_corr; 502 double step_ticks = ( coeff_b * diff_ticks_corr_d);493 double step_ticks = (m_dll_coeff_b * diff_ticks_corr_d); 503 494 debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, 504 495 "diff_ticks_corr=%f, step_ticks=%f\n", … … 528 519 529 520 // update the DLL state 530 m_dll_e2 += coeff_c * diff_ticks_corr_d;521 m_dll_e2 += m_dll_coeff_c * diff_ticks_corr_d; 531 522 532 523 // update the y-axis values branches/libffado-2.0/src/libieee1394/CycleTimerHelper.h
r1341 r1525 147 147 uint32_t m_cycle_timer_prev; 148 148 uint64_t m_cycle_timer_ticks_prev; 149 int m_high_bw_updates; 149 150 double m_dll_coeff_b; 151 double m_dll_coeff_c; 150 152 151 153 // cached vars used for computation branches/libffado-2.0/src/libstreaming/amdtp/AmdtpReceiveStreamProcessor.cpp
r1524 r1525 104 104 if(ok) { 105 105 m_last_timestamp = sytRecvToFullTicks2((uint32_t)CondSwapFromBus16(packet->syt), pkt_ctr); 106 106 107 //#ifdef DEBUG 107 108 #if 0 branches/libffado-2.0/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.cpp
r1419 r1525 54 54 , m_send_nodata_payload ( AMDTP_SEND_PAYLOAD_IN_NODATA_XMIT_BY_DEFAULT ) 55 55 #endif 56 , m_max_cycles_to_transmit_early ( AMDTP_MAX_CYCLES_TO_TRANSMIT_EARLY ) 57 , m_transmit_transfer_delay ( AMDTP_TRANSMIT_TRANSFER_DELAY ) 58 , m_min_cycles_before_presentation ( AMDTP_MIN_CYCLES_BEFORE_PRESENTATION ) 56 59 , m_nb_audio_ports( 0 ) 57 60 , m_nb_midi_ports( 0 ) … … 103 106 104 107 // now we calculate the time when we have to transmit the sample block 105 transmit_at_time = substractTicks( presentation_time, AMDTP_TRANSMIT_TRANSFER_DELAY);108 transmit_at_time = substractTicks( presentation_time, m_transmit_transfer_delay ); 106 109 107 110 // calculate the cycle this block should be presented in … … 135 138 // we can still postpone the queueing of the packets 136 139 // if we are far enough ahead of the presentation time 137 if ( cycles_until_presentation <= AMDTP_MIN_CYCLES_BEFORE_PRESENTATION)140 if ( cycles_until_presentation <= m_min_cycles_before_presentation ) 138 141 { 139 142 debugOutput( DEBUG_LEVEL_NORMAL, … … 206 209 // NOTE: dangerous since the device has no way of reporting that it didn't get 207 210 // this packet on time. 208 if(cycles_until_presentation >= AMDTP_MIN_CYCLES_BEFORE_PRESENTATION)211 if(cycles_until_presentation >= m_min_cycles_before_presentation) 209 212 { 210 213 // we are not that late and can still try to transmit the packet … … 218 221 } 219 222 } 220 else if(cycles_until_transmit <= AMDTP_MAX_CYCLES_TO_TRANSMIT_EARLY)223 else if(cycles_until_transmit <= m_max_cycles_to_transmit_early) 221 224 { 222 225 // it's time send the packet … … 242 245 presentation_time, (unsigned int)TICKS_TO_CYCLES(presentation_time)); 243 246 #ifdef DEBUG 244 if ( cycles_until_transmit > AMDTP_MAX_CYCLES_TO_TRANSMIT_EARLY+ 1 )247 if ( cycles_until_transmit > m_max_cycles_to_transmit_early + 1 ) 245 248 { 246 249 debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, … … 429 432 m_syt_interval = getSytInterval(); 430 433 m_fdf = getFDF(); 434 435 debugOutput ( DEBUG_LEVEL_VERBOSE, " SYT interval / FDF : %d / %d\n", m_syt_interval, m_fdf ); 436 #if AMDTP_ALLOW_PAYLOAD_IN_NODATA_XMIT 437 debugOutput ( DEBUG_LEVEL_VERBOSE, " Send payload in No-Data packets: %s \n", m_send_nodata_payload?"Yes":"No" ); 438 #endif 439 debugOutput ( DEBUG_LEVEL_VERBOSE, " Max early transmit cycles : %d\n", m_max_cycles_to_transmit_early ); 440 debugOutput ( DEBUG_LEVEL_VERBOSE, " Transfer delay : %d\n", m_transmit_transfer_delay ); 441 debugOutput ( DEBUG_LEVEL_VERBOSE, " Min cycles before presentation : %d\n", m_min_cycles_before_presentation ); 431 442 432 443 iec61883_cip_init ( branches/libffado-2.0/src/libstreaming/amdtp/AmdtpTransmitStreamProcessor.h
r1524 r1525 110 110 virtual unsigned int getNominalFramesPerPacket() 111 111 {return getSytInterval();}; 112 // transmit control parameters 113 virtual int getMaxCyclesToTransmitEarly() 114 {return m_max_cycles_to_transmit_early;}; 115 virtual void setMaxCyclesToTransmitEarly(int x) 116 {m_max_cycles_to_transmit_early = x;}; 117 virtual unsigned int getTransferDelay() 118 {return m_transmit_transfer_delay;}; 119 virtual void setTransferDelay(unsigned int x) 120 {m_transmit_transfer_delay = x;}; 121 virtual int getMinCyclesBeforePresentation() 122 {return m_min_cycles_before_presentation;}; 123 virtual void setMinCyclesBeforePresentation(int x) 124 {m_min_cycles_before_presentation = x;}; 112 125 113 126 protected: … … 141 154 bool m_send_nodata_payload; 142 155 #endif 156 int m_max_cycles_to_transmit_early; 157 unsigned int m_transmit_transfer_delay; 158 int m_min_cycles_before_presentation; 143 159 144 160 private: // local port caching for performance branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.cpp
r1463 r1525 76 76 , m_scratch_buffer_size_bytes( 0 ) 77 77 , m_ticks_per_frame( 0 ) 78 , m_dll_bandwidth_hz ( STREAMPROCESSOR_DLL_BW_HZ ) 78 79 , m_sync_delay( 0 ) 79 80 , m_in_xrun( false ) … … 136 137 137 138 int StreamProcessor::getMaxFrameLatency() { 138 if (getType() == ePT_Receive) { 139 return (int)(m_IsoHandlerManager.getPacketLatencyForStream( this ) * TICKS_PER_CYCLE); 140 } else { 141 return (int)(m_IsoHandlerManager.getPacketLatencyForStream( this ) * TICKS_PER_CYCLE); 142 } 139 return (int)(m_IsoHandlerManager.getPacketLatencyForStream( this ) * TICKS_PER_CYCLE); 143 140 } 144 141 … … 282 279 283 280 bool 281 StreamProcessor::setDllBandwidth(float bw) 282 { 283 m_dll_bandwidth_hz = bw; 284 return true; 285 } 286 287 bool 284 288 StreamProcessor::canClientTransferFrames(unsigned int nbframes) 285 289 { … … 397 401 398 402 if (result == eCRV_OK) { 403 #ifdef DEBUG 404 if (m_last_timestamp > 0 && m_last_timestamp2 > 0) { 405 int64_t tsp_diff = diffTicks(m_last_timestamp, m_last_timestamp2); 406 debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "TSP diff: %lld\n", tsp_diff); 407 double tsp_diff_d = tsp_diff; 408 double fs_syt = 1.0/tsp_diff_d; 409 fs_syt *= (double)getNominalFramesPerPacket() * (double)TICKS_PER_USEC * 1e6; 410 double fs_nom = (double)m_StreamProcessorManager.getNominalRate(); 411 double fs_diff = fs_nom - fs_syt; 412 double fs_diff_norm = fs_diff/fs_nom; 413 debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "Nom fs: %12f, Instantanous fs: %12f, diff: %12f (%12f)\n", 414 fs_nom, fs_syt, fs_diff, fs_diff_norm); 415 if (fs_diff_norm > 0.01 || fs_diff_norm < -0.01) { 416 debugWarning( "Instantanous samplerate more than 1%% off nominal. [Nom fs: %12f, Instantanous fs: %12f, diff: %12f (%12f)]\n", 417 fs_nom, fs_syt, fs_diff, fs_diff_norm); 418 } 419 } 420 #endif 421 399 422 // #ifdef DEBUG 400 423 int ticks_per_packet = (int)(getTicksPerFrame() * getNominalFramesPerPacket()); … … 702 725 } 703 726 #ifdef DEBUG 727 if (m_last_timestamp > 0 && m_last_timestamp2 > 0) { 728 int64_t tsp_diff = diffTicks(m_last_timestamp, m_last_timestamp2); 729 debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "TSP diff: %lld\n", tsp_diff); 730 double tsp_diff_d = tsp_diff; 731 double fs_syt = 1.0/tsp_diff_d; 732 fs_syt *= (double)getNominalFramesPerPacket() * (double)TICKS_PER_USEC * 1e6; 733 double fs_nom = (double)m_StreamProcessorManager.getNominalRate(); 734 double fs_diff = fs_nom - fs_syt; 735 double fs_diff_norm = fs_diff/fs_nom; 736 debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "Nom fs: %12f, Instantanous fs: %12f, diff: %12f (%12f)\n", 737 fs_nom, fs_syt, fs_diff, fs_diff_norm); 738 if (fs_diff_norm > 0.01 || fs_diff_norm < -0.01) { 739 debugWarning( "Instantanous samplerate more than 1%% off nominal. [Nom fs: %12f, Instantanous fs: %12f, diff: %12f (%12f)]\n", 740 fs_nom, fs_syt, fs_diff, fs_diff_norm); 741 } 742 } 743 704 744 int ticks_per_packet = (int)(getTicksPerFrame() * getNominalFramesPerPacket()); 705 745 int diff = diffTicks(m_last_timestamp, m_last_timestamp2); … … 1097 1137 1098 1138 debugOutput( DEBUG_LEVEL_VERBOSE, "Prepared for:\n"); 1099 debugOutput( DEBUG_LEVEL_VERBOSE, " Samplerate: %d \n",1100 m_StreamProcessorManager.getNominalRate() );1139 debugOutput( DEBUG_LEVEL_VERBOSE, " Samplerate: %d [DLL Bandwidth: %f Hz]\n", 1140 m_StreamProcessorManager.getNominalRate(), m_dll_bandwidth_hz); 1101 1141 debugOutput( DEBUG_LEVEL_VERBOSE, " PeriodSize: %d, NbBuffers: %d\n", 1102 1142 m_StreamProcessorManager.getPeriodSize(), m_StreamProcessorManager.getNbBuffers()); … … 1358 1398 m_correct_last_timestamp = false; 1359 1399 1360 debugOutput(DEBUG_LEVEL_VERBOSE, "Initializing remote ticks/frame to %f\n", ticks_per_frame);1400 debugOutput(DEBUG_LEVEL_VERBOSE, "Initializing remote ticks/frame to %f\n", ticks_per_frame); 1361 1401 1362 1402 // initialize internal buffer … … 1372 1412 result &= m_data_buffer->setNominalRate(ticks_per_frame); 1373 1413 result &= m_data_buffer->setWrapValue(128L*TICKS_PER_SECOND); 1414 result &= m_data_buffer->setBandwidth(m_dll_bandwidth_hz / (double)TICKS_PER_SECOND); 1374 1415 result &= m_data_buffer->prepare(); // FIXME: the name 1416 1417 debugOutput(DEBUG_LEVEL_VERBOSE, "DLL info: nominal tpf: %f, update period: %d, bandwidth: %e 1/ticks (%e Hz)\n", 1418 m_data_buffer->getNominalRate(), m_data_buffer->getUpdatePeriod(), m_data_buffer->getBandwidth(), m_data_buffer->getBandwidth() * TICKS_PER_SECOND); 1375 1419 1376 1420 break; branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.h
r1419 r1525 405 405 void setTicksPerFrame(float tpf); 406 406 407 bool setDllBandwidth(float bw); 408 407 409 int getBufferFill(); 408 410 … … 451 453 protected: 452 454 float m_ticks_per_frame; 455 float m_dll_bandwidth_hz; 453 456 unsigned int m_sync_delay; 454 457 private: branches/libffado-2.0/src/libutil/Configuration.cpp
r1524 r1525 270 270 } 271 271 272 bool 273 Configuration::getValueForSetting(std::string path, float &ref) 274 { 275 libconfig::Setting *s = getSetting( path ); 276 if(s) { 277 // FIXME: this can be done using the libconfig methods 278 Setting::Type t = s->getType(); 279 if(t == Setting::TypeFloat) { 280 ref = *s; 281 debugOutput(DEBUG_LEVEL_VERBOSE, "path '%s' has value %f\n", path.c_str(), ref); 282 return true; 283 } else { 284 debugOutput(DEBUG_LEVEL_VERBOSE, "path '%s' has wrong type\n", path.c_str()); 285 return false; 286 } 287 } else { 288 debugOutput(DEBUG_LEVEL_VERBOSE, "path '%s' not found\n", path.c_str()); 289 return false; 290 } 291 } 292 272 293 libconfig::Setting * 273 294 Configuration::getSetting( std::string path ) … … 308 329 bool 309 330 Configuration::getValueForDeviceSetting(unsigned int vendor_id, unsigned model_id, std::string setting, int64_t &ref) 331 { 332 libconfig::Setting *s = getDeviceSetting( vendor_id, model_id ); 333 if(s) { 334 try { 335 return s->lookupValue(setting, ref); 336 } catch (...) { 337 debugOutput(DEBUG_LEVEL_VERBOSE, "Setting %s not found\n", setting.c_str()); 338 return false; 339 } 340 } else { 341 debugOutput(DEBUG_LEVEL_VERBOSE, "device %X/%X not found\n", vendor_id, model_id); 342 return false; 343 } 344 } 345 346 bool 347 Configuration::getValueForDeviceSetting(unsigned int vendor_id, unsigned model_id, std::string setting, float &ref) 310 348 { 311 349 libconfig::Setting *s = getDeviceSetting( vendor_id, model_id ); branches/libffado-2.0/src/libutil/Configuration.h
r1524 r1525 126 126 bool getValueForSetting(std::string path, int32_t &ref); 127 127 bool getValueForSetting(std::string path, int64_t &ref); 128 bool getValueForSetting(std::string path, float &ref); 128 129 129 130 /** … … 141 142 bool getValueForDeviceSetting(unsigned int vendor_id, unsigned model_id, std::string setting, int32_t &ref); 142 143 bool getValueForDeviceSetting(unsigned int vendor_id, unsigned model_id, std::string setting, int64_t &ref); 144 bool getValueForDeviceSetting(unsigned int vendor_id, unsigned model_id, std::string setting, float &ref); 143 145 144 146 virtual void setVerboseLevel(int l) {setDebugLevel(l);}; branches/libffado-2.0/src/libutil/TimestampedBuffer.cpp
r1464 r1525 36 36 #define DLL_PI (3.141592653589793238) 37 37 #define DLL_SQRT2 (1.414213562373095049) 38 #define DLL_OMEGA (2.0*DLL_PI*TIMESTAMPEDBUFFER_DLL_BANDWIDTH) 38 #define DLL_2PI (2.0 * DLL_PI) 39 40 // these are the defaults 41 #define DLL_OMEGA (DLL_2PI * 0.01) 39 42 #define DLL_COEFF_B (DLL_SQRT2 * DLL_OMEGA) 40 43 #define DLL_COEFF_C (DLL_OMEGA * DLL_OMEGA) … … 84 87 85 88 /** 86 * \brief Set the nominal rate in frames/timeunit 87 * 88 * Sets the nominal rate in frames per time unit. This rate is used 89 * \brief Set the bandwidth of the DLL 90 * 91 * Sets the bandwith of the DLL in absolute frequency 92 * 93 * @param bw bandwidth in absolute frequency 94 * @return true if successful 95 */ 96 bool TimestampedBuffer::setBandwidth(double bw) { 97 double curr_bw = getBandwidth(); 98 debugOutput(DEBUG_LEVEL_VERBOSE," bandwidth %e => %e\n", 99 curr_bw, bw); 100 double tupdate = m_nominal_rate * (float)m_update_period; 101 double bw_rel = bw * tupdate; 102 if(bw_rel >= 0.5) { 103 debugError("Requested bandwidth out of range: %f > %f\n", bw, 0.5*tupdate); 104 return false; 105 } 106 m_dll_b = bw_rel * (DLL_SQRT2 * DLL_2PI); 107 m_dll_c = bw_rel * bw_rel * DLL_2PI * DLL_2PI; 108 return true; 109 } 110 111 /** 112 * \brief Returns the current bandwidth of the DLL 113 * 114 * Returns the current bandwith of the DLL in absolute frequency 115 * 116 * @return bandwidth in absolute frequency 117 */ 118 double TimestampedBuffer::getBandwidth() { 119 double tupdate = m_nominal_rate * (float)m_update_period; 120 double curr_bw = m_dll_b / (DLL_SQRT2 * DLL_2PI * tupdate); 121 return curr_bw; 122 } 123 124 125 /** 126 * \brief Set the nominal rate in timeunits/frame 127 * 128 * Sets the nominal rate in time units per frame. This rate is used 89 129 * to initialize the DLL that will extract the effective rate based 90 130 * upon the timestamps it gets fed. … … 94 134 */ 95 135 bool TimestampedBuffer::setNominalRate(float r) { 136 debugOutput(DEBUG_LEVEL_VERBOSE," nominal rate %e => %e\n", 137 m_nominal_rate, r); 96 138 m_nominal_rate=r; 97 debugOutput(DEBUG_LEVEL_VERBOSE," nominal rate=%e set to %e\n",98 m_nominal_rate, r);99 139 return true; 100 140 } … … 362 402 m_dll_e2=m_nominal_rate * (float)m_update_period; 363 403 364 m_dll_b=((float)(DLL_COEFF_B));365 m_dll_c=((float)(DLL_COEFF_C));366 367 404 // this will init the internal timestamps to a sensible value 368 405 setBufferTailTimestamp(m_buffer_tail_timestamp); … … 958 995 959 996 #ifdef DEBUG 997 960 998 // check whether the update is within the allowed bounds 961 999 ffado_timestamp_t max_abs_diff = 3072/2; // half a cycle is what we consider 'normal' branches/libffado-2.0/src/libutil/TimestampedBuffer.h
r1299 r1525 136 136 137 137 // dll stuff 138 bool setBandwidth(double bw); 139 double getBandwidth(); 138 140 bool setNominalRate ( float r ); 139 141 float getNominalRate() {return m_nominal_rate;}; branches/libffado-2.0/src/motu/motu_avdevice.cpp
r1521 r1525 24 24 25 25 #include "motu/motu_avdevice.h" 26 27 #include "devicemanager.h" 26 28 27 29 #include "libieee1394/configrom.h" … … 1397 1399 } 1398 1400 1401 // get the device specific and/or global SP configuration 1402 Util::Configuration &config = getDeviceManager().getConfiguration(); 1403 // base value is the config.h value 1404 float recv_sp_dll_bw = STREAMPROCESSOR_DLL_BW_HZ; 1405 float xmit_sp_dll_bw = STREAMPROCESSOR_DLL_BW_HZ; 1406 1407 // we can override that globally 1408 config.getValueForSetting("streaming.spm.recv_sp_dll_bw", recv_sp_dll_bw); 1409 config.getValueForSetting("streaming.spm.xmit_sp_dll_bw", xmit_sp_dll_bw); 1410 1411 // or override in the device section 1412 config.getValueForDeviceSetting(getConfigRom().getNodeVendorId(), getConfigRom().getModelId(), "recv_sp_dll_bw", recv_sp_dll_bw); 1413 config.getValueForDeviceSetting(getConfigRom().getNodeVendorId(), getConfigRom().getModelId(), "xmit_sp_dll_bw", xmit_sp_dll_bw); 1414 1399 1415 m_receiveProcessor=new Streaming::MotuReceiveStreamProcessor(*this, event_size_in); 1416 m_receiveProcessor->setVerboseLevel(getDebugLevel()); 1400 1417 1401 1418 // The first thing is to initialize the processor. This creates the … … 1405 1422 return false; 1406 1423 } 1407 m_receiveProcessor->setVerboseLevel(getDebugLevel()); 1424 1425 if(!m_receiveProcessor->setDllBandwidth(recv_sp_dll_bw)) { 1426 debugFatal("Could not set DLL bandwidth\n"); 1427 delete m_receiveProcessor; 1428 m_receiveProcessor = NULL; 1429 return false; 1430 } 1408 1431 1409 1432 // Now we add ports to the processor … … 1467 1490 } 1468 1491 1492 if(!m_transmitProcessor->setDllBandwidth(xmit_sp_dll_bw)) { 1493 debugFatal("Could not set DLL bandwidth\n"); 1494 delete m_transmitProcessor; 1495 m_transmitProcessor = NULL; 1496 return false; 1497 } 1498 1469 1499 // Now we add ports to the processor 1470 1500 debugOutput(DEBUG_LEVEL_VERBOSE,"Adding ports to transmit processor\n");