Monkey.D.Luffy

Technical Hackintosh
Staff member
12/5/15
527
244
63
36
140619020937263817.png


. CHAPTER 1: GETTING CODEC INFORMATION.


Intro: This guide is for those who want to use AppleHDA and / or trying to learn how it works. It is divided in to several steps and we will address each of them throughout the guide.

. STEP ONE: Getting Information from the codec. There are other ways but in this guide we will explain how to get to Linux. Using Ubuntu or another distro. (Note: Use the latest version of Linux and Alsa drivers)

in terminal type:
Mã:
cat /proc/asound/card0/codec#1 > ~/Desktop/codec_dump.txt

or
Mã:
cat /proc/asound/card0/codec#0 > ~/Desktop/codec_dump.txt
or if you prefer use zhell script:
Mã:
cd ~/Desktop && mkdir CodecDump && for c in /proc/asound/card*/codec#*; do f="${c/\/*card/card}"; cat "$c" > CodecDump/${f//\//-}.txt; done && zip -r CodecDump.zip CodecDump
Save it in a safe place.

In OS X, we use the codec_dump for a graphical interface, convert it to decimal (I'll explain why later), get him codec verbs and correct them for OS X.
Download and install: Graphviz
Download CodecGraph: codecgraph , unzip it to desktop, copy the generated codec_dump.txt linux folder to CodeGraph then type in termainal:
Mã:
cd ~/Desktop/codecgraph
and then:
Mã:
./codecgraph codec_dump.txt
. STEP TWO: Converting CodecGraph CodecDump and hexadecimal to decimal:

Download:convert_hex_to_dec Credits Munky . Unzip it in the same folder used previously (codecgraph) - In the terminal:
Mã:
cd ~/Desktop/codecgraph

chmod +x ./convert_hex_to_dec.rb

./convert_hex_to_dec.rb codec_dump.txt.svg >~/Desktop/codecgraph/codec_dump_dec.txt.svg
* Replace "codec_dump.txt" with your user name and codec file (if you gave a specific name)
Mã:
./convert_hex_to_dec.rb codec_dump.txt > ~/Desktop/codecgraph/codec_dump_dec.txt
* Replace "codec_dump.txt" with your user name and codec file (if you gave a specific name)

. STEP THREE: For our standard onboard sound card be recognized by OS X must add the device to our HDEF DSDT.aml. For this we use the following patches: HDEF or AZAL to HDEF in both DTGP method has to be present in our DSDT.aml. We use the DSDT Editor to apply the patches correctly http://olarila.com/f...c.php?f=7&t=646The Patchs you find here http://olarila.com/forum/patches.php This is a Audio Injection standard and should work for all codecs:
Mã:
Device(HDEF){Name(_ADR,0x001B0000)Method(_DSM,4,NotSerialized){Store(Package(0x04){"layout-id",Buffer(0x04){0x0C,0x00,0x00,0x00},

"PinConfigurations",Buffer(Zero){}

},Local0)
DTGP (Arg0,Arg1,Arg2,Arg3,RefOf(Local0))Return(Local0)}}
Mã:
Method(DTGP,5,NotSerialized){If(LEqual(Arg0,Buffer(0x10){/* 0000 */0xC6,0xB7,0xB5,0xA0,0x18,0x13,0x1C,0x44,/* 0008 */0xB0,0xC9,0xFE,0x69,0x5E,0xAF,0x94,0x9B})){If(LEqual(Arg1,One)){If(LEqual(Arg2,Zero)){Store(Buffer(One){0x03},Arg4)Return(One)}

If(LEqual(Arg2,One)){Return(One)}}}

Store(Buffer(One){0x00},Arg4)Return(Zero)}
 
Last edited:
. CHAPTER 2: CORRECTION APPLEHDA.KEXT


For the AppleHDA Work correctly for our codec we make some modifications in the same plists.

So what are these changes?

If you look at it (click the right mouse button / Show Package Contents), you will find in the Content folder of the main Info.plist (not touching it) and a folder plugins. There are plugins that we have to fix, but not all just Info.plist from this one:

1-AppleHDAHardwareConfigDriver.kext

2-platform.xml and layout12.xml or Layout1.xml (in Folder Resources)
3-BinPatch

1-AppleHDAHardwareConfigDriver.kext

To edit this kext need to get configdata / CodecVerbs.
You can fix them in two ways, either manually or automatically using the script called Signal64 Verbit that performs the entire process automatically
requiring a few adjustments you can download it here: verbit.zip
Unzip it in the same folder codecgraph used previously. then Run this command in Terminal:
Mã:
cd /Users/your_user_name/Desktop/codecgraph
and then:
Mã:
./Verbit codec_dump.txt> verbs.txt
. NOTE: You must delete the line codec_dump.txt: AFG Function Id: 0x1 (unsol 0)
Having done this codecgraph open the folder and you will see two files and another one called verbs.txtverbitdebug.txt.
verbit.texto is in our interest. For in him we find our configdata / CodecVerbs original and corrected tops underneath.
verbs.txt:
Mã:
--------------------------------------------------------------------------------------------------------
ATAPI Unknown SPDIF Out at Int ATAPI 170x110x9943014001171c4001171d0001171e4301171f90
1/8 Green LineOut at ExtRear 200x140x0101401001471c1001471d4001471e0101471f01
1/8 Black LineOut at ExtRear 210x150x0101101201571c7001571d1001571e0101571f01
1/8 Orange LineOut at ExtRear 220x160x0101601101671c8001671d6001671e0101671f01
1/8 Grey LineOut at ExtRear 230x170x0101201401771c9001771d2001771e0101771f01
Mic at ExtRear 240x182736750401871c5001871d9001871ea101871f01
Mic at ExtFront 250x194414576001971c6001971d9001971ea101971f01
1/8 Blue LineIn at ExtRear 260x1a0x0181305f01a71ca001a71d3001a71e8101a71f01
HP Out at ExtFront270x1b3573660801b71c2001b71d4001b71e2101b71f01
Optical WhiteLineOut at Ext N/A 290x1d0x4005e60101d71cb001d71de001d71e0501d71f40
Optical Orange SPDIF Out at ExtRear 300x1e0x0145613001e71c3001e71d6001e71e4501e71f01

verbitdebug.txt:
Mã:
Checkingif2 already exists in:4178956 a 13no duplicate found
Checkingif1 already exists in:4178956 a 23
duplicate found -Isthis the first time we've seen this association?
no - replacing association with: b
Checking if 3 already exists in: 4 1 7 8 9 5 6 a 2 b
no duplicate found

New 71c Associations
Before After
--------------------------------------------------
01171c40 01171c40 01171d01 01171e43 01171f99
01471c10 01471c10 01471d40 01471e01 01471f01
01571c12 01571c70 01571d10 01571e01 01571f01
01671c11 01671c80 01671d60 01671e01 01671f01
01771c14 01771c90 01771d20 01771e01 01771f01
01871c50 01871c50 01871d98 01871ea1 01871f01
01971c60 01971c60 01971d9c 01971ea1 01971f02
01a71c5f 01a71ca0 01a71d30 01a71e81 01a71f01
01b71c20 01b71c20 01b71d4c 01b71e21 01b71f02
01d71c01 01d71cb0 01d71de6 01d71e05 01d71f40
01e71c30 01e71c30 01e71d61 01e71e45 01e71f01

Reset 71d Misc to 0
New 71d Associations
Before After
--------------------------------------------------
01171d01 01171c40 01171d00 01171e43 01171f99
01471d40 01471c10 01471d40 01471e01 01471f01
01571d10 01571c70 01571d10 01571e01 01571f01
01671d60 01671c80 01671d60 01671e01 01671f01
01771d20 01771c90 01771d20 01771e01 01771f01
01871d98 01871c50 01871d90 01871ea1 01871f01
01971d9c 01971c60 01971d90 01971ea1 01971f02
01a71d30 01a71ca0 01a71d30 01a71e81 01a71f01
01b71d4c 01b71c20 01b71d40 01b71e21 01b71f02
01d71de6 01d71cb0 01d71de0 01d71e05 01d71f40
01e71d61 01e71c30 01e71d60 01e71e45 01e71f01

Correct 71f 02 FP to 01
New 71f Associations
Before After
--------------------------------------------------
01171d01 01171c40 01171d00 01171e43 01171f90
01471d40 01471c10 01471d40 01471e01 01471f01
01571d10 01571c70 01571d10 01571e01 01571f01
01671d60 01671c80 01671d60 01671e01 01671f01
01771d20 01771c90 01771d20 01771e01 01771f01
01871d98 01871c50 01871d90 01871ea1 01871f01
01971d9c 01971c60 01971d90 01971ea1 01971f01
01a71d30 01a71ca0 01a71d30 01a71e81 01a71f01
01b71d4c 01b71c20 01b71d40 01b71e21 01b71f01
01d71de6 01d71cb0 01d71de0 01d71e05 01d71f40
01e71d61 01e71c30 01e71d60 01e71e45 01e71f01
The codec used in the above example as you can see is a ALC887-VD was necessary to change only one of the external microphones.
To understand how these changes are made we need to go deeper.
So what is a codec verb?
For each input/output there is a sequence of 4 verbs.
Lets take an example from codec used before:



ts about NodeID(NID) 0x14 in hex, 20 in decimal:

The default verbs for it: 21471c10 21471d44 21471e01 21471f01
01471c10:
01471c10 = CAd (Codec Adress)
01471c10 = NID (NodeID)
01471c10 = Verb Commands like 71"c" then "d", "e" ,"f"
01471c10 = Verb Data
And the same for the rest.

I think Cad, NID and Verb Commands are pretty simple to figure out: first 2 you get them from linux dump, and commands are standard 71c, 71d, 71e, 71f.
Lets see about verb data:

- 71cXY X=Default Association Y=Sequence

. DEFAULT ASSOCIATION AND SEQUENCE: are used together by software to group Pin Complexes (and therefore jacks) together into functional blocks to support multichannel operation. Software may assume that all jacks with the same association number are intended to be grouped together, for instance to provide six channel analog output. The Default Association can also be used by software to prioritize resource allocation in constrained situations. Lower Default Association values would be higher in priority for resources such as processing nodes or Input and Output Converters. Note that this is the default association only, and software can override this value if required, in particular if the user provides additional information about the particular system configuration. A value of 0000b is reserved and should not be used. Software may interpret this value to indicate that the Pin Configuration data has not been properly initialized. A value of 1111b is a special value indicating that the Association has the lowest priority. Multiple different Pin Complexes may share this value, and each is intended to be exposed as independent devices.

. SEQUENCE: indicates the order of the jacks in the association group. The lowest numbered jack in the association group should be assigned the lowest numbered channels in the stream, etc. The numbers need not be sequential within the group, only the order matters. Sequence numbers within a set of Default Associations must be unique.

*My notes for this, if you look on the vanilla codec verb(no matter what codec) you will see that Sequence is always 0.
Why that, and why for us on our codec verbs is different? Simple b/c Apple dosen't have multichannel analog out! so you must change it to 0.

*About Default Association, Keep the default one, in order, and on those that are the same replace them with new one that dosen't exist already in the dump... the values you can use are: 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d and f.(see what does verbit if you still don't understand)

- 71dXY X=Color Y=Misc

. COLOR: indicates the color of the physical jack for use by software.
Mã:
Unknown 0
Black 1
Grey 2
Blue 3
Green 4
Red 5
Orange 6
Yellow 7
Purple 8
Pink 9
Reserved A-D
White E
Other F
. MISC: is a bit field used to indicate other information about the jack. Currently, only bit 0 is defined. If bit 0 is set, it indicates that the jack has no presence detect capability, so even if a Pin Complex indicates that the codec hardware supports the presence detect functionality on the jack, the external circuitry is not capable of supporting the functionality.
Reserved 3
Reserved 2
Reserved 1
Jack Detect Override 0

*Use 0 for Jack Detect - External Device(e.g. Headphones Mic etc)
Use 1 for Jack Detect Disabled - Internal Device(e.g. Internal speakers, Internal mic)

71eXY X=Default Device Y=Connection Type

. DEFAULT DEVICE: INDICATES: the intended use of the jack or device. This can indicate either the label on the jack or the device that is hardwired to the port, as with integrated speakers and the like.
Mã:
LineOut 0
Speaker 1
HP Out 2
CD 3
SPDIF Out 4
Digital Other Out 5
Modem Line Side 6
Modem Handset Side 7
LineIn 8
AUX 9
MicIn A
Telephony B
SPDIF In C
Digital Other In D
Reserved E
Other F
 

Attachments

  • verbit.zip
    3.1 KB · Xem: 120
Last edited:
  • Like
Reactions: Tiến La Văn
. CONNECTION TYPE: indicates the type of physical connection, such as a 1/8-inch stereo jack or an optical digital connector, etc. Software can use this information to provide helpful user interface descriptions to the user or to modify reported codec capabilities based on the capabilities of the physical transport external to the codec.

Mã:
Unknown 0
1/8" stereo/mono 1
1/4" stereo/mono 2
ATAPI internal 3
RCA 4
Optical 5
OtherDigital 6
OtherAnalog 7
MultichannelAnalog(DIN) 8
XLR/Professional 9
RJ-11(Modem) A
Combination B Other F
71fXY X=Port Connectivity Y=Location

. PORT CONNECTIVITY: indicates the external connectivity of the Pin Complex. Software can use this value to know what Pin Complexes are connected to jacks, internal devices, or not connected at all.
00b - The Port Complex is connected to a jack (1/8", ATAPI, etc.).
01b - No physical connection for Port.
10b - A fixed function device (integrated speaker, integrated mic, etc.) is attached.
11b - Both a jack and an internal device are attached. The Information provided in all other fields refers to the integrated device. The PD pin will reflect the status of the jack; the user will need to be queried to figure out what it is.

. LOCATION: INDICATES the physical location of the jack or device to which the pin complex is connected. This allows software to indicate, for instance, that the device is the “Front Panel Headphone Jack” as opposed to rear panel connections.

*Details:
Convert the 2 digit hex number to binary.
Pad the front with zero's to make it 8 dgits.

EXAMPLE:

0x02= binary 10=000000108 digit binary

Reading the bits from left to right:

PortConnectivity bits 7:6-----------------------------------------------------------00-Portis connected to a Jack01-NoExternalPort-or-No physical connection forPort10-FixedFunction/BuiltInDevice(integrated speaker, mic, etc)11-JackandInternal device are attached

LocationPart1- bits 5:4
Mã:
-----------------------------------------------------------00-External on primary chassis
01-Internal10-Separate chassis11-Other

LocationPart2- bits 3:0-----------------------------------------------------------The meaning depends on LocationPart1

000000 N/A000001Rear000010Front000011Left000100Right000101Top000110Bottom000111Special(Rear panel)001000Special(Drive bay)

010000 N/A010111Special(Riser)011000 HDMI011001 ATAPI

100000 N/A100001Rear100010Front100011Left100100Right100101Top100110Bottom

110000 N/A110110?110111InsideMobileLid(example: mic)111000OutsideMobileLid

BitsHex76543210-------------------71cf01=00000001-Port has a jack -ItisExternal-RearLocation71cf02=00000010-Port has a jack -ItisExternal-FrontPanelLocation71cf59=01011001-NoExternalPort- ATAPI 71cf18=00011000-Port has a jack -External- HDMI71cf90=10010000-BuiltInDevice-Internal- N/A |||||||||---------Location part 2||------------Location part 1|---------------PortConnectivity
A good APP for you to test in practice
is this: PinConfigurator
Credits: sax-mmS

Thanks again to Signal64 for his VerbCheatSheet
*All info came from High Definition Audio Specification Read it for more details!
 
Last edited:
  • Like
Reactions: Tiến La Văn
. CONCLUSION:

The script does a great job, still not perfect as it does not know what are our options ... perhaps a GUI application may be added in the future.
So that those options may be?
- you may want to setup mic as internal to get ambient noise reduction for it.
- some codecs have only line outs same trick can apply and you can set first output as speaker and get as an option software dsp for it.
- for front panel support you may need to transform back mic in line in.
And so on ...
Now that we got all necessary information about configdata / CodecVerbs we edit the info.plist of AppleHDAHardwareConfigDriver.kext.

Editing AppleHDAHardwareConfigDriver.kext (Info.plist)
(Click with the right mouse button / Show Package Contents) Open Plist with a Plist editor.
Navigate to the key IOKitPersonalities / HDA Hardware Config ResourceHDAConfigDefault.

1-CodecID: Put the ID of your codec in Numbers 0x10ec0887 Decimal (Hexadecimal) -> 283 904 135 (Decimal)
2-configdata: Here we put our configdata / Verbs codec that previously corrected.
3-FuncGroup: Must always be 1.
4-LayoutID: By default is 12 but can be any other number provided that you also change the number of layout on your DSDT.aml
* NOTE: In the Mountain/Mavericks Lion kexts so we can use a layout that already has in itself no kext and others like layout887.xml as was used in the Lion kexts.
 
Last edited:
o1dw.png


2- Editing and platform.xml layout12.xml or Layout1.xml (Folder Resources)
This is the trickiest part.
Within the Resources folder you will find several layouts.xml and a Platforms.xml.
You'll edit both according to the previous corrections ie in AppleHDAHardwareConfigDriver.kext use the layout12 so let's make the necessary edits on this.

1-CodecID: Put the ID of your codec in Numbers 0x10ec0887 Decimal (Hexadecimal) -> 283 904 135 (Decimal)
2-PathMapID: Change to 1
* Note: Exclude MuteGPIO, SignalProcessing of all keys.

uip7.png


What we had to fix in Layout12.xml is already completed.
Now we edit the Platforms.xml is here that lies the pathmaps. Within Key Pathmaps there are other keys
which are numbered and each corresponds to a specific layout.xml eg use within the same layout12.xml has a key with pathmap Id = 1.
In the example we are using a codec ALC887-VD have 4 outputs and 2 audio inputs. Totaling 6 devices.
For output devices, the PathMap follows this pattern:
Pin Complex (NodeID) -> Audio Mixer-> Audio Output
So we have to find a node Pin Complex (NodeID), a node Audio Mixer and finally an audio output node.
For input devices, the PathMap follow this pattern:
Pin-Complex (NodeID)> Selector/Mixer- Audio Input> Audio
Here, we have to find a node Pin Complex (NodeID), an audio mixer / selector node and finally a node of audio input.
Open the file in the folder generated codec_dump_dec.txt.svg codegraph you will see something like this:

nxur.png



note 20 (Pin Complex) -> 12 (node Audio Mixer) -> 2 (Audio output node)
from there we have already formed our pathmap lineout to (in the case node20 is an internal speaker).
We will do the same for the rest of our pathmaps.
Note: Note that in the screenshot attached above you can see that the lines are continuous connections of nodes.

1jis.png


An example of Pathmaps to Mic (External):
note 24 (Pin Complex) -> 35 (node Audio Mixer) -> 9 (Audio output node)
Note: Usually starts unlike 9 -> 34 -> 24



zsuy.png




The pathmaps codec for example were used as well:

9-34-24 = External Mic
9-34-25 = External Mic Front
8-35-26 = Line In
2-12-20 = Internal Speakers
27-38-37 = Headphone
23-15-5 = Line Out
22-14-4 = Line Out
23-13-3 = Line Out
30-6 = Digital Output



3-BinPatch:

Starting with version 10.6.3 of Snow Leopard was also necessary to correct the binary file of Applehda.kext it is within the MacOs folder that sits inside the Kext to make this correction we will use the script done by bcc9.

patch-hda.zip



Copy the folder to your desktop and already with Applehda.kext edits and installed in S / L / E type the following commands in Terminal:

cd ~/desktop/patch-hda
./patch-hda.pl 10ec0887
. NOTE: Open the folder hda-patch-hda-codecs.pl file inside it is all supported codecs for the script for more information: Script to patch AppleHDA binary for osx10.7/10.8/10.9

A tip if your codec is not supported by the script you can try to fix manually using a binary editor like HexFiend and replace one of the codecs used, by correction for you.
In the example above was corrected binary for ALC887-VD codec if you are correct for your codec is necessary to replace the 10ec0887 by the id of your codec.
In binary they are written from right to left ie 10ec0887 = 8708ec10.

. IMPORTANT:

The Mountain Lion kext / Mavericks have a new structure and the files are compressed in. Zlib to unpack and edit these files will use zlib.
This application is based on RevoGirl script, it makes the process of files. Zlib from AppleHDA.kext to decompress / compress easier. Just drag the file zlib. The application and it will unzip or drag the xml file. And it will compress to. Zlib.
So if you own an old kext from Lion can compress files using this APP.Download Zlib.



Folder with all the necessary tools for editing and some kexts Applehda.kext several original versions of OS X: tools AppleHDA



. CREDITS: The King, bcc9, RevoGirl (RIP), EMlyDinEsH, Munky, TimeWalker and others.
 
Last edited:
mình k thấy link down nhỉ
 
Em có thắc mắc chút xíu phần Binary Patching. Tại sao ban đầu ghi là khuyên dùng Vendor ID của 885 mà về sau lại sử dụng Vendor của 884 vậy? Mới cả lúc chọn Vendor để patch thì mình phải thử từng cái một hay có cách nào khác không?
Em cảm ơn! :D
 
Em có thắc mắc chút xíu phần Binary Patching. Tại sao ban đầu ghi là khuyên dùng Vendor ID của 885 mà về sau lại sử dụng Vendor của 884 vậy? Mới cả lúc chọn Vendor để patch thì mình phải thử từng cái một hay có cách nào khác không?
Em cảm ơn! :D
Muxuxiủa e .. nó nằm ở chỗ đoạn nào ?
 

Attachments

  • Screen Shot 2015-05-23 at 2.06.59 PM.png
    Screen Shot 2015-05-23 at 2.06.59 PM.png
    81.3 KB · Xem: 126
  • Like
Reactions: njcotjn
Mất hết ảnh rồi. Do lấy source từ nhà cũ. giờ không xem được ảnh rồi. Đề nghị bác chủ sửa lại gấp
 
Chao ban, minh da cai Mac 10.10.3 thanh cong nhung chua co am thanh ban giup minh duoc khong Realtek ALC887-VD
 
Chao ban, minh da cai Mac 10.10.3 thanh cong nhung chua co am thanh ban giup minh duoc khong Realtek ALC887-VD
JackySr bạn . mình chỉ post patch chứ k patches giùm thank
 
vậy làm đầy đủ như hướng dẫn trên của bạn là được à? Xài không có âm thanh thốn lắm >.<
JackyĐến đây là bạn có thể tự mầy mò được rồi. Forum geek nên khuyến khích người dùng tự làm, chứ không khuyến khích ăn sẵn. Ăn sẵn đã có thứ khác rồi
 
Đến đây là bạn có thể tự mầy mò được rồi. Forum geek nên khuyến khích người dùng tự làm, chứ không khuyến khích ăn sẵn. Ăn sẵn đã có thứ khác rồi
vusun123mình kêu bạn ý làm hộ đâu.
 
Bác @Monkey.D.Luffy cho e hỏi là sử dụng kext AppleHDA ALC của Hackintosh Vietnam tool có cần làm những bước này không hay thực hiện ntn khác ạ :D