tylernguyen / x1c6-hackintosh

READMEs, OpenCore configurations, patches, and notes for the Thinkpad X1 Carbon 6th Gen 2018 Hackintosh
https://tylernguyen.github.io/x1c6-hackintosh/
The Unlicense
636 stars 109 forks source link

Bad distortion through headphones with AppleALC and alc_fix #75

Closed erdemoney closed 4 years ago

erdemoney commented 4 years ago

Describe the bug After sleep audio through the headphone jack its muted and distorted. I'm using AppleALC.kext and alc_fix from the patches directory. I just ran the install.sh. I'm assuming that's all you have to do for it to work. I've tried using alcid 11, 21, and 31 with no change. I checked the pin config in Hackintool and it matches yours so I don't think there should be an issue there.

alc_fix seems to be working

2020-09-24 21:15:16.462 ALCPlugFix[620:11035] ALCPlugFix v1.6
2020-09-24 21:15:16.493 ALCPlugFix[620:11035] Found had-verb in work dir
2020-09-24 21:15:16.493 ALCPlugFix[620:11035] Headphones daemon running!
2020-09-24 21:15:16.508 ALCPlugFix[620:11035] Correctly added Audio Listener!
2020-09-24 21:15:16.508 ALCPlugFix[620:11035] Fixing...
2020-09-24 21:15:16.532 ALCPlugFix[620:11035] Performing periodical work
2020-09-24 21:16:08.234 ALCPlugFix[620:11035] receiveSleepNote: com.apple.screenIsUnlocked
2020-09-24 21:16:08.234 ALCPlugFix[620:11035] Wake detected
2020-09-24 21:16:08.234 ALCPlugFix[620:11035] Fixing...
2020-09-24 21:16:10.504 ALCPlugFix[620:11035] receiveSleepNote: NSWorkspaceDidWakeNotification
2020-09-24 21:16:10.504 ALCPlugFix[620:11035] Wake detected
2020-09-24 21:16:10.504 ALCPlugFix[620:11035] Fixing...
2020-09-24 21:24:23.190 ALCPlugFix[620:11035] receiveSleepNote: NSWorkspaceDidWakeNotification
2020-09-24 21:24:23.190 ALCPlugFix[620:11035] Wake detected
2020-09-24 21:24:23.190 ALCPlugFix[620:11035] Fixing...
2020-09-24 21:24:34.434 ALCPlugFix[620:11035] receiveSleepNote: com.apple.screenIsUnlocked
2020-09-24 21:24:34.434 ALCPlugFix[620:11035] Wake detected
2020-09-24 21:24:34.434 ALCPlugFix[620:11035] Fixing...

To Reproduce Steps to reproduce the behavior:

  1. Use EFI Folder from this repo with unmodded bios additions to config.plist
  2. Install alc_fix by running install.sh
  3. Sleep laptop
  4. Wake and play audio through headphones
  5. Audio is very distorted and much quieter than normal. Gets extremely crunchy at higher volumes. Reboot is necessary to fix. Note: Consistently repeatable. Audio gets messed up every time after first sleep following boot.

Expected behavior Undistored audio through headphones

notthebee commented 4 years ago

I have a similar problem. The audio randomly cuts at times and the only thing that solves it is going to System Preferences > Sound > Input and switching from Line In to Built-In Microphone. Then, after a few seconds, it cuts again. Happens with both loudspeakers and headphones, but I can't find the exact steps to reproduce it.

erdemoney commented 4 years ago

Yeah, I just found out yesterday that I can fix my issue by selecting β€œline in” in the same settings panel so our issues are probably related. Mine seems to stay working after changing the setting but I haven’t done any real testing.

Porco-Rosso commented 4 years ago

I have experienced the same problem as @notthebee several times, after sleep. It doesn't happen every-time however. I have also experienced entire system crashes, which seem tied to the audio (only has happened while playing music. The entire system freezes, and I can hear a small clip repeating until I force-shutdown the laptop. This might be unrelated, possibly from overheating or something.

savvamitrofanov commented 4 years ago

Same problem on T490 platform. Seems like problem with interrupts

zombillano commented 4 years ago

I have both headphone interference and audio cuts on a T480. It seems to happen only after waking up from sleep but not immediately, it takes like 1 hour or so to stop working. The built in mic also stops working. Restarting solves the problem.

The audio randomly cuts at times and the only thing that solves it is going to System Preferences > Sound > Input and switching from Line In to Built-In.

Keep System Preferences open at the Input submenu. That'll make the output keep working as far as you keep System Preferences open. Still not a great solution but can help you in case you can't restart immediately.

Offtopic: I love your videos. I decided to get a T480 just because of your advices, best laptop I've ever had, so far πŸ‘.

benbender commented 4 years ago

It may be the same problems like those which are solved here: https://github.com/acidanthera/AppleALC/pull/571#issue-434129924

I've asked for some help/advise :)

benbender commented 4 years ago

Got much help from @fewtarius and have a test-build with a maybe fixed layout 21 for you. He, the magician of ALC-codecs, throwed some voodoo on it and it may be fixed and could work natively now.

I would love to get some testing and feedback from you before posting a merge request to http://github.com/acidanthera/AppleALC.

So: If you are brave enough, simply take the build attached to this post, remove every alc_fix, CodecCommander or similar, set your LayoutId to 21 and do some testing!

If it succeeds or fails, please report back!

AppleALC-1.5.4-RELEASE-X1C6-ALC285-LayoutID-21-Fix.zip

the-ethernal commented 4 years ago

I'll test it later today. I've already replaced AppleALC.kext and layout-id on config.plist but I can't restart right now. I'm I missing anything? I have a T480 and I'm using EETagent's EFI.

benbender commented 4 years ago

@TheQuetz if you don't have any additional tools in place to fix audio, thats it. If you are on Catalina a "sudo kextcache -i /" to rebuild the kextcache won't hurt, but may be unnecessary.

erdemoney commented 4 years ago

@benbender Just swapped out my AppleALC with the fixed one this morning. No issues so far! Seems to be working!

tylernguyen commented 4 years ago

@benbender Removed ALCPlugFix and tested your AppleALC, no problems so far after 3-4 sleep cycles. I think after a few more days, it'll be safe to say that the changes can be made into a PR upstream. Meanwhile I'll push your kext into the repo and advise to remove existing ALCPlugFix.

Thank you @fewtarius for helping out!

tylernguyen commented 4 years ago

@benbender @fewtarius

It switches output automatically too once headphones are plugged, that's awesome! Do you guys still have the instructions/steps? If possible, I'd like for that to be posted here in case someone else stumbles onto this issue with a different audio layout.

benbender commented 4 years ago

I have saved the conversation. If it's fine for @fewtarius, I'll give it to you. But it surely will need some serious edit to be helpful.

ghost commented 4 years ago

@benbender Removed ALCPlugFix and tested your AppleALC, no problems so far after 3-4 sleep cycles. I think after a few more days, it'll be safe to say that the changes can be made into a PR upstream. Meanwhile I'll push your kext into the repo and advise to remove existing ALCPlugFix.

Thank you @fewtarius for helping out!

If you're curious, as to how we resolved this, here's what we did.

We started by downloading the AppleALC source code and making sure we could do a test build. Next we looked at your codec dump, specifically your headphone jack input and output and your internal speaker out. We wanted to verify that the output supported EAPD, and the input supported JackSense. We confirmed both. The outputs supported EAPD (EAPD Detect), and the jack mic supported JackSense (In Detect).

Node 0x14 [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Speaker Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x00010014: OUT EAPD Detect
  EAPD 0x2: EAPD
  Pin Default 0x90170110: [Fixed] Speaker at Int N/A
    Conn = Analog, Color = Unknown
    DefAssociation = 0x1, Sequence = 0x0
    Misc = NO_PRESENCE
  Pin-ctls: 0x40: OUT
  Unsolicited: tag=00, enabled=0
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0
  Connection: 1
     0x02

Node 0x21 [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Headphone Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x80 0x80]
  Pincap 0x0001001c: OUT HP EAPD Detect
  EAPD 0x2: EAPD
  Pin Default 0x04211020: [Jack] HP Out at Ext Right
    Conn = 1/8, Color = Black
    DefAssociation = 0x2, Sequence = 0x0
  Pin-ctls: 0xc0: OUT HP
  Unsolicited: tag=01, enabled=1
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0
  Connection: 2
     0x02* 0x03

Node 0x19 [Pin Complex] wcaps 0x40048b: Stereo Amp-In
  Control: name="Mic Boost Volume", index=0, device=0
    ControlAmp: chs=3, dir=In, idx=0, ofs=0
  Amp-In caps: ofs=0x00, nsteps=0x03, stepsize=0x27, mute=0
  Amp-In vals:  [0x00 0x00]
  Pincap 0x00003724: IN Detect
    Vref caps: HIZ 50 GRD 80 100
  Pin Default 0x04a11040: [Jack] Mic at Ext Right
    Conn = 1/8, Color = Black
    DefAssociation = 0x4, Sequence = 0x0
  Pin-ctls: 0x24: IN VREF_80
  Unsolicited: tag=02, enabled=1
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0

Once we had this data, we inspected the pin config data in AppleALC for ALC285 layout 21 (AppleALC/Resources/PinConfigs.kext/Contents/Info.plist) with ProperTree and learned that the EAPD signal was only being sent to the internal speakers, and no pin widget control signal was being sent to the jack mic. This means the jack was not being put into the proper state after a wake event. To remedy this we needed to update the ConfigData and the WakeConfigData to send the proper signals.

Screen Shot 2020-10-08 at 7 49 44 PM

Original ConfigData:

01271C10 01271D01 01271EA6 01271F90 01471C30 01471D01 01471E17 01471F90 01971C00 01971D10 01971E8B 01971F04 02171C20 02171D10 02171E2B 02171F04 01470C02

Original WakeConfigData:

01470C02

Each of the bytes above represent a pin complex, you can break the pin complex down like this:

  0  19 707  25
  β”‚ β””β”¬β”˜ β””β”¬β”˜ β””β”¬β”˜
  β”‚  β”‚   β”‚   β”‚
  β”‚  β”‚   β”‚   β”‚
  β”‚  β”‚   β”‚   β”‚
  β”‚  β”‚   β”‚   └───── Instruction
  β”‚  β”‚   └────── Verb
  β”‚  └─────── Node Location
  └──────── Codec # (Usually 0)

Each of the verbs that can be sent to the codec are documented in the Intel HDA specification manual, but we know that the EAPD verb is 70C and the Pin Widget Control verb is 707.

Looking at the data above we can quickly see that we're missing both the pin widget control verb and EAPD on the headphone switch. To correct this we simply add the verbs to the configuration data, and recompile AppleALC.

To correct EAPD, we add 02170C02 which sends the EAPD enable signal to node 21. To correct the jack mic, we add 01970725 which sends the Pin Widget Control signal to node 19. We add the EAPD verb to both the ConfigData, and the WakeConfigData and the Pin Widget Control signal to the WakeConfigData. ConfigData is used by AppleALC on initialization, and WakeConfigData is used on each wake event. We used ProperTree to update the data.

Corrected ConfigData:

01271C10 01271D01 01271EA6 01271F90 01471C30 01471D01 01471E17 01471F90 01971C00 01971D10 01971E8B 01971F04 02171C20 02171D10 02171E2B 02171F04 01470C02 02170C02

Corrected WakeConfigData:

01470C02 02170C02 01970725

Screen Shot 2020-10-08 at 7 59 58 PM

After we've updated the pin config for this codec and layout, we simply compile and test to ensure everything works on wake. We also want to make sure that we remove VerbStub, CodecCommander, ALCWakeFix, and any other helper that may be installed as those helpers can clobber the fix.

ghost commented 4 years ago

I have saved the conversation. If it's fine for @fewtarius, I'll can give it to you. But it surely will need some serious edit to be helpful.

I was already typing it up. :)

benbender commented 4 years ago

Additional links for in depth documentation/learning:

tylernguyen commented 4 years ago

@benbender

If you want to make that PR now, I'll go ahead and endorse it on the ticket.

ghost commented 4 years ago

@benbender

If you want to make that PR now, I'll go ahead and endorse it on the ticket.

Glad to hear the patch is working out for you all. πŸ‘

benbender commented 4 years ago

I'll do as soon as I finished my other small Hackintosh project. Thanks again everyone - especially @fewtarius. It was a pleasure!

benbender commented 4 years ago

PR on the way: https://github.com/acidanthera/AppleALC/pull/612

benbender commented 4 years ago

The eagle has landed: https://github.com/acidanthera/AppleALC/commit/41106026cf9bb093d88090bc3c207b9ffde0ef6b πŸ‘

Mifaxav commented 2 years ago

I haven't tried any patches yet but just asking, is there a similar fix for a T480? ALC 257?