Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveAE: compensate error for TrueHD passthrough #25229

Merged
merged 1 commit into from
May 18, 2024

Conversation

thexai
Copy link
Member

@thexai thexai commented May 18, 2024

Description

ActiveAE: compensate error for TrueHD passthrough

Motivation and context

Apply what has been found in: https://forum.kodi.tv/showthread.php?tid=377117&pid=3198021#pid3198021

Basically due nature of TrueHD compressed audio, data is not received at regular intervals then the delay is not constant while handling TrueHD frames but it is once decoded to PCM. Since AE is handling compressed data, even it's not aware of this, is need a corrective factor in the error.

This is a very basic form of correction but effective since the variability is well limited.

thd

We can try to find the correction value theoretically:

There is usually a maximum of 5 MAT frames queued, that is 5 * 20 ms = 100 ms plus another 100 ms due maxpassthroughoffsyncduration. In total is 200 ms.

This is the worst case and should be inside AE threshold of 100 ms. Then is need scale 200 ms to 100 ms

error = error * 0.50

0.45 is used to have some margin.

Another way to justify this value is empirically:

FreeGuy-62

Normal error oscillation (noise) should be less than frame time (~42 ms at 23.976) to avoid accidental a/v sync corrections.

0.45 factor seems meets the two conditions in various videos tested. It may not be perfect but it is a great improvement over the current situation.

In a follow up PR should be revised self-learning algo to not exceed 2* frame time as this broke a/v sync correction.

Ideally error noise < frame time
self-learning or maxpassthroughoffsyncduration > error noise but less 2 * frame time.

Probably we can use constant value of 1.8 * frame time and remove "self-learning"....

How has this been tested?

Runtime Shield.

What is the effect on users?

  • No more TrueHD dropouts even in very problematic sources as Cars (2006) when is used adequate maxpassthroughoffsyncduration value only.
  • Seeks improved considerably: audio returns much faster after seek because there is less error and no additional corrections are necessary.

Tested Blu-Ray folder and also tested MKV created with MakeMKV v1.17.7
and
Blu-Ray to .m2ts with tsMuxer and .m2ts to MKV with mkvmerge v82.0

Screenshots (if appropriate):

No dropouts in 20 minutes of playback:
Cars-62

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • Student submission (PR was done for educational purposes and will be treated as such)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@thexai thexai added Type: Fix non-breaking change which fixes an issue Type: Improvement non-breaking change which improves existing functionality Component: Audio v22 "P" labels May 18, 2024
@thexai thexai added this to the "P" 22.0 Alpha 1 milestone May 18, 2024
Copy link
Member

@fritsch fritsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - I followed the thread. All fine within the margin ... if we ever get the delay per packed packet exactly (changing value per packet), we can change this.

@thexai thexai merged commit 4f49dcf into xbmc:master May 18, 2024
2 checks passed
@thexai thexai deleted the TrueHD-error branch May 19, 2024 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport: Done Component: Audio Type: Fix non-breaking change which fixes an issue Type: Improvement non-breaking change which improves existing functionality v22 "P"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants