MediaPortal Audio renderer - better video playback quality (3 Viewers)

hoborg

Portal Pro
June 13, 2008
4,413
1,644
Nový Jičín
Home Country
Czech Republic Czech Republic
Please post log and ffdshow setting screen shots for 1) mixer screen 2) output screen 3) resampling screen. SAF might be having pretty bad settings for ffdshow. Currently I'm not recommending using SAF for testing at all.

Only if passthrough is enabled, default setting should be OK.

ONLY :p That will kill the audio renderer's ability to work completely (I even wonder why it was able to connect, since even that should fail for passthru formats - but I need a log to analyze that). Please have a look on the first post for more technical details.

Tourettes, durning SAF install, SAF ask user if enable audio passthrough or not.
If you click no, FFDshow setiing are fully compatible with your renderer, as i wrote, only stereo mixer is enabled. Still, ffdshow audio settings window popup durning SAF install, and you can simply disable mixer or select different audio output (5.1, 7.1, etc...).

That is all.
 

davidf

Retired Team Member
  • Premium Supporter
  • April 3, 2006
    796
    348
    Scotland
    Home Country
    Scotland Scotland
    Interesting initial analysis:

    DEV PC
    Difference between QpcCLock and HwClock: -80791
    Multiplier calculated Adjustment: 80967
    Bias Adjustment: 0
    Adj : -715555
    Total amount really adjusted: -814925

    Multiplier Min 1.000059
    Multiplier Max 1.000059

    HTPC
    Difference between QpcCLock and HwClock: 30237
    Multiplier calculated Adjustment: -83
    Bias Adjustment: 0
    Adj : -32895
    Total amount really adjusted : -45400

    Multiplier Min 0.999984075
    Multiplier Max 1.000037477

    Looks like the hardware on the HTPC is not consistent - is that the one with the XONAR?

    I'll keep poking at it and let you know. Looks like you may have to take a more complex route of tracking the drift if the variance is so high.
     

    tourettes

    Retired Team Member
  • Premium Supporter
  • January 7, 2005
    17,301
    4,800
    Total amount really adjusted: -814925

    What you were using to calculate the total and calculated adjustment? Could we have the formula for calculating those, it would help on the debugging since we could see from 5 minute sample already how much the audio is drifting (of course it would require the calculated / approximated adjustment need to be known as well).

    Dev PC
    Multiplier Min 1.000059
    Multiplier Max 1.000059

    HTPC
    Multiplier Min 0.999984075
    Multiplier Max 1.000037477

    Looks like the hardware on the HTPC is not consistent - is that the one with the XONAR?

    Usually that HTPC shows only 0.9999999 as the multiplier - also the value from
    Code:
    pClockData->driftHWvsSystem = (m_dDurationHW - m_dDurationSystem) / 10000;

    Is quite close to zero, much smaller than on dev PC. Maybe it was still in the beginning of the sampled data where the fluctuations happened? Can you see that easialy with Excel? By hand it will be impossible to tell :)

    No, I don¨t have Xonar and I wont be planning to buy such in the future either.

    I'll keep poking at it and let you know. Looks like you may have to take a more complex route of tracking the drift if the variance is so high.

    Could be.
     

    tourettes

    Retired Team Member
  • Premium Supporter
  • January 7, 2005
    17,301
    4,800
    davidf, I'm currently testing following code. This gives (at least on first 1,5 hour DVD playback) good results on the HTPC. The main difference if that the 1 ms accuracy for the current system time has been improved by using the QPC for it as well. Do you think that the precission error could have been piling up in the non-QPC based code?

    Code:
    REFERENCE_TIME CSyncClock::GetPrivateTime()
    {
      CAutoLock cObjectLock(this);
    
      UINT64 qpcNow = GetCurrentTimestamp();
    
      //DWORD dwTime = timeGetTime();
    
      UINT64 hwClock(0);
      UINT64 hwQpc(0);
    
      UINT64 hwClockEnd(0);
      UINT64 hwQpcEnd(0);
    
      HRESULT hr = m_pAudioRenderer->AudioClock(hwClock, hwQpc);
    
      if (m_dStartTimeSystem == 0)
        m_dStartTimeSystem = qpcNow; //dwTime;
    
      if (m_dwPrevSystemTime == 0)
        m_dwPrevSystemTime = qpcNow;
    
      if (hr == S_OK)
      {
        if (m_dStartQpcHW == 0)
          m_dStartQpcHW = hwQpc;
    
        if (m_dStartTimeHW == 0)
          m_dStartTimeHW = hwClock;
    
        if (m_dStartTimeCorrected == 0)
          m_dStartTimeCorrected = m_rtPrivateTime;
    
        m_dDurationHW = (hwClock - m_dStartTimeHW);
        m_dDurationSystem = (qpcNow/*dwTime*/ - m_dStartTimeSystem); 
        m_dDurationCorrected = (m_rtPrivateTime - m_dStartTimeCorrected);
    
        //if (hwQpc < m_dPrevQpcHW)
          //Log("%I64d", hwQpc - m_dPrevQpcHW);
    
        if (m_dPrevTimeHW > hwClock)
        {
          m_dStartTimeHW = m_dPrevTimeHW = hwClock;
          m_dStartQpcHW = m_dPrevQpcHW = hwQpc;
          m_dStartTimeSystem = qpcNow;//dwTime;
          m_dStartTimeCorrected = m_rtPrivateTime;
          m_llDeltaError = 0;
          overallCorrection = 0;
        }
        else
        {
          double clockDiff = hwClock - m_dStartTimeHW;
          double qpcDiff = hwQpc - m_dStartQpcHW;
    
          if (clockDiff > 0 && qpcDiff > 0)
            m_dSystemClockMultiplier = clockDiff / qpcDiff;
    
          if (m_dSystemClockMultiplier < 0.95 || m_dSystemClockMultiplier > 1.05)
            m_dSystemClockMultiplier = 1.0;
    
          m_dPrevTimeHW = hwClock;
          m_dPrevQpcHW = hwQpc;
        }
      }
      else
      {
        //Log("AudioClock() returned error (0x%08x)");
      }
    
      //REFERENCE_TIME delta = REFERENCE_TIME(dwTime) - REFERENCE_TIME(m_dwPrevSystemTime);
      //REFERENCE_TIME deltaOrig = delta;
      
      INT64 delta = qpcNow - m_dwPrevSystemTime;
      INT64 deltaOrig = delta;
    
    //  if (dwTime < m_dwPrevSystemTime)
      {
        //delta += REFERENCE_TIME(UINT_MAX) + 1;
      }
    
      m_dwPrevSystemTime = qpcNow;// dwTime;
      delta = (REFERENCE_TIME)(delta * (UNITS / MILLISECONDS));
      double dAdjustment;
      if (m_bHWBasedRefClock)
      {
        dAdjustment = m_dAdjustment * m_dBias / m_dSystemClockMultiplier;
      }
      else
      {
        dAdjustment = m_dAdjustment * m_dBias;
      }
      double ddelta= ((double) delta) * dAdjustment;
      delta = (REFERENCE_TIME) ddelta;
      m_ddeltaError += ddelta - delta;
      if (m_ddeltaError > 1.0)
      {
        delta += 10000;
        m_ddeltaError -= 1.0;
        overallCorrection += 1.0;
      }
      else if (m_ddeltaError < -1.0)
      {
        delta -= 10000;
        m_ddeltaError += 1.0;
        overallCorrection -= 1.0;
      }
      
      //if (hwQpc - m_dStartQpcHW > 600000000)
      {
        //Log("mul: %.10f de: %8I64d de.orig: %8I64d de.err: %.10f bias: %.10f adj: %.10f hwQpc: %I64d hwClock: %I64d", 
          //m_dSystemClockMultiplier, delta / 10000, deltaOrig, m_ddeltaError, m_dBias, m_dAdjustment, hwQpc, hwClock);
      }
    
      m_rtPrivateTime = m_rtPrivateTime + delta / 10000;
    
      //m_ddeltaError += (delta - (double)((INT64)delta / 10000) * 10000);
    
      return m_rtPrivateTime;
    }


    here's a sample of the logged data:

    Code:
    02-10-2010 17:14:32.920 [  c50] mul: 1.0000591714 de:    50067 de.orig:    50064 de.err: 0.5450161928 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931319657 hwClock: 121402083
    02-10-2010 17:14:32.925 [  c50] mul: 1.0000587848 de:    49917 de.orig:    49914 de.err: 0.4135349030 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931369493 hwClock: 121451875
    02-10-2010 17:14:32.927 [  c50] mul: 1.0000594914 de:    20122 de.orig:    20120 de.err: 0.0784983570 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931389614 hwClock: 121472083
    02-10-2010 17:14:32.929 [  c50] mul: 1.0000588067 de:    19884 de.orig:    19883 de.err: 0.6050553257 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931409488 hwClock: 121491875
    02-10-2010 17:14:32.931 [  c50] mul: 1.0000583278 de:    20050 de.orig:    20049 de.err: 0.7496228749 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931429545 hwClock: 121511875
    02-10-2010 17:14:32.933 [  c50] mul: 1.0000584828 de:    19985 de.orig:    19983 de.err: 0.3691143924 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931449525 hwClock: 121531875
    02-10-2010 17:14:32.936 [  c50] mul: 1.0000599162 de:    30189 de.orig:    30187 de.err: 0.2678700024 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931479765 hwClock: 121562291
    02-10-2010 17:14:32.938 [  c50] mul: 1.0000595445 de:    19862 de.orig:    19861 de.err: 0.3983151847 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931499601 hwClock: 121582083
    02-10-2010 17:14:32.938 [  c50] mul: 1.0000596672 de:     1469 de.orig:     1468 de.err: 0.3122369414 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931501044 hwClock: 121583541
    02-10-2010 17:14:32.938 [  c50] mul: 1.0000588440 de:     1357 de.orig:     1356 de.err: 0.2364152828 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931502394 hwClock: 121584791
    02-10-2010 17:14:32.938 [  c50] mul: 1.0000599866 de:     1321 de.orig:     1320 de.err: 0.0599926887 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931503714 hwClock: 121586250
    02-10-2010 17:14:32.938 [  c50] mul: 1.0000593526 de:     1329 de.orig:     1329 de.err: 0.8566284487 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931505041 hwClock: 121587500
    02-10-2010 17:14:32.938 [  c50] mul: 1.0000587680 de:     1323 de.orig:     1322 de.err: 0.7698523877 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931506362 hwClock: 121588750
    02-10-2010 17:14:32.938 [  c50] mul: 1.0000599436 de:     1315 de.orig:     1314 de.err: 0.4281588281 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931507677 hwClock: 121590208
    02-10-2010 17:14:32.939 [  c50] mul: 1.0000599839 de:     1663 de.orig:     1662 de.err: 0.3599017607 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931509339 hwClock: 121591875
    02-10-2010 17:14:32.945 [  72c] mul: 1.0000599191 de:    64305 de.orig:    64302 de.err: 0.5587509619 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931573926 hwClock: 121656458
    02-10-2010 17:14:32.945 [  c50] mul: 1.0000596389 de:     1768 de.orig:     1768 de.err: 0.9745344454 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931575418 hwClock: 121657916
    02-10-2010 17:14:32.945 [  64c] mul: 1.0000596630 de:     1249 de.orig:     1248 de.err: 0.5681672310 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931576665 hwClock: 121659166
    02-10-2010 17:14:32.951 [  64c] mul: 1.0000583305 de:    52811 de.orig:    52808 de.err: 0.7247242546 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931629741 hwClock: 121712083
    02-10-2010 17:14:32.951 [  448] mul: 1.0000596528 de:     1352 de.orig:     1351 de.err: 0.6344760293 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931630830 hwClock: 121713333
    02-10-2010 17:14:32.951 [  64c] mul: 1.0000597917 de:     1639 de.orig:     1638 de.err: 0.0225823438 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931632480 hwClock: 121715000
    02-10-2010 17:14:32.951 [  448] mul: 1.0000589122 de:      761 de.orig:      761 de.err: 0.3442753851 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931633212 hwClock: 121715625
    02-10-2010 17:14:32.951 [  c50] mul: 1.0000587720 de:     1045 de.orig:     1045 de.err: 0.5115637202 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931634270 hwClock: 121716666
    02-10-2010 17:14:32.953 [  64c] mul: 1.0000597909 de:    16301 de.orig:    16300 de.err: 0.4305750448 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931650812 hwClock: 121733333
    02-10-2010 17:14:32.956 [  c50] mul: 1.0000597604 de:    28991 de.orig:    28990 de.err: 0.9612073023 bias: 1.0000000000 adj: 1.0000000000 hwQpc: 15412931679564 hwClock: 121762083


    btw. should it be

    Code:
     if (m_bHWBasedRefClock)
      {
        dAdjustment = m_dAdjustment * m_dBias * m_dSystemClockMultiplier;
      }

    OR

    Code:
     if (m_bHWBasedRefClock)
      {
        dAdjustment = m_dAdjustment * m_dBias / m_dSystemClockMultiplier;
      }
     

    tourettes

    Retired Team Member
  • Premium Supporter
  • January 7, 2005
    17,301
    4,800
    Also one thing I noticed is that a seek after startup makes wonders for the m_dSystemClockMultiplier accuracy. It wont climb anymore to the correct position. I think this is related to the fact that audio buffer wont advance directly after startup. This could be cured by using 1.0 as m_dSystemClockMultiplier for brief moment and then start calculating it when we have steady outflow of the audio samples from audio device.
     

    davidf

    Retired Team Member
  • Premium Supporter
  • April 3, 2006
    796
    348
    Scotland
    Home Country
    Scotland Scotland
    btw. should it be

    Code:
     if (m_bHWBasedRefClock)
      {
        dAdjustment = m_dAdjustment * m_dBias * m_dSystemClockMultiplier;
      }

    OR

    Code:
     if (m_bHWBasedRefClock)
      {
        dAdjustment = m_dAdjustment * m_dBias / m_dSystemClockMultiplier;
      }

    Maths lesson :D

    you want hw = qpc so :

    hw*qpc/hw = qpc

    m_dSystemClockMultiplier = hw/qpc
    so either use / m_dSystemClockMultiplier
    or make m_dSystemClockMultiplier = qpc/hw
     

    tourettes

    Retired Team Member
  • Premium Supporter
  • January 7, 2005
    17,301
    4,800
    btw. should it be

    Code:
     if (m_bHWBasedRefClock)
      {
        dAdjustment = m_dAdjustment * m_dBias * m_dSystemClockMultiplier;
      }

    OR

    Code:
     if (m_bHWBasedRefClock)
      {
        dAdjustment = m_dAdjustment * m_dBias / m_dSystemClockMultiplier;
      }

    Maths lesson :D

    you want hw = qpc so :

    hw*qpc/hw = qpc

    m_dSystemClockMultiplier = hw/qpc
    so either use / m_dSystemClockMultiplier
    or make m_dSystemClockMultiplier = qpc/hw

    Well, my math isn't that bad :D The reason why I was wondering that is that we don't want to have QPC - why would we since we can get that also directly by GetCurrentTimestamp(). Of course I could have misunderstood something.

    But the really weird part is that "*" works for dev PC and HTPC ( "/" works of course for the HTPC as well since it has 0.99999999 as the multiplier so the actual drifting is so minimal that it wont be noticeable. I think HTPC was only having the issue with the lost precission on delta calculation and it is now fixed). But using "*" causes approx one dropped frame on the dev PC per minute (need to reboot to make sure it is not something wierd).

    As you can see it is quite possible to write broken reference clock code that will behave just good enough on some systems.
     

    davidf

    Retired Team Member
  • Premium Supporter
  • April 3, 2006
    796
    348
    Scotland
    Home Country
    Scotland Scotland
    Use "*" then, I've already changed my mind about it once :). Never let a mathematical proof stand in the way of empirical evidence... You can prove a bee can't possibly fly after all.

    And you've just reminded me that it's trying to move by the same amount to the other side so it is *. i.e. we want to speed the clock up by that about to stop the drift.

    If you do another detailed log (with the accurate clock and multiplier) I'll push the numbers through see what happens. Do you have Excel - and what version?
     

    tourettes

    Retired Team Member
  • Premium Supporter
  • January 7, 2005
    17,301
    4,800
    Use "*" then, I've already changed my mind about it once :). Never let a mathematical proof stand in the way of empirical evidence... You can prove a bee can't possibly fly after all.

    Empirical Strikes Back this time with the nasty dropped frames when the multiplier is > 1.0 and we use *. Sync seems to be good, but I haven't figured out the reason for the dropped frames (maybe the clock gets pushed too far in the future - but 1.00006x shouldn't be doing such). :mad:

    Maybe Owlsroosts reads this thread and tells us right away what goes nuts inside the EVR presenter :D

    And you've just reminded me that it's trying to move by the same amount to the other side so it is *. i.e. we want to speed the clock up by that about to stop the drift.

    I haven't ever had this hard decission to be made with one char :)
     

    Users who are viewing this thread

    Top Bottom