Adding Sounds to Tracks

In order to do this you're going to need a hex editor. I use FRHED as it's simple enough for me to understand, it does what I want it to do and it's free! You can get it HERE When using a hex editor I prefer to have it show 16 bytes per line as this seems to make more sense (as we're dealing with hexadecimal, i.e base 16). You don't have to do this of course, I just thought I'd mention it :-) You'll also probably want Paul Hoad's GPL Track Editor (sometimes known as just GPL Editor) although you can add sounds without it; I don't know where you can get this from but a search at Race Sim Central will probably point you in the right direction.

Hex, bytes, nodes, offsets....???

Hex - I won't attempt to explain hexadecimal; the FRHED help file does this pretty well anyway. Hex numbers are usually written with a preceding 0x, e.g 0x10 = decimal 16. Note that the 0x is not part of the number, it's just there to show that what follows is hexadecimal(i.e 10). In this tutorial I haven't always stuck to this convention as we're dealing with hex most of the time so it's easier to state when a number isn't hex than when it is :-)

Bytes - Again, the FRHED help file is worth looking at for more about bytes. If you can't be bothered to read that then bear these things in mind when dealing with bytes and a hex editor:
            - one byte is shown as two 'digits' - e.g 4f is one byte, not two.
            - numbers (hexadecimal numbers, that is) are shown least significant byte first - in other words, the bytes are shown 'backwards'. This is                     where it's important to remember that one byte is two 'digits' : 1a2b3c4d will be shown in a hex editor as 4d 3c 2b 1a (not d4 c3 b2 a1)
            - if you use Windows calculator note that it doesn't display preceding zeros. It's probably best to consider all numbers as being 4-byte                         (32-bit) numbers as this is what you're be dealing with most of the time. So if  the calculator shows 1ab, look at it as 4 bytes with all preceding              zeros: 000001ab; in a hex editor this be seen as ab 01 00 00

Nodes - Don't worry about nodes, and don't worry about the fact that they're called "nodes" - for the purposes of adding sounds to tracks the main thing to know is what the relevant nodes look like in a hex editor, and which parts you need to edit to make something happen. This is explained later on.

Offsets - A 3do consists of different sections; within any of those sections a particluar byte can be said to be a certain 'distance' from the start of that section, with the distance measured in bytes. E.g if this was a section: 00 00 00 00 FF 00 00 00,  the 'FF' has an offset of 3 (bytes) from the start of the section. If we wanted to reference 'FF' from somewhere else we could do it by giving its offset, i.e 3.

Okay not the greatest explanations.... for more (and better) info on 3dos, nodes and offsets visit Guru's GPL File Formats


Three things are needed for a track to have to sounds: the track 3do must have an ssourcelist section (which references other 3dos on the track to be used as sound sources); the referenced objects must also have an ssourcelist section (different to the track one - this tells GPL to actually 'play' the sounds); the track folder must have files called crowd.wav and/or announce.wav. If both these files are in the track folder then both sounds will be heard at the sound sources. I haven't been able to find a way of 'splitting' them and I doubt it's possible as all the Papy tracks which use both sounds play them together, so I presume if it were possible to play only one then Papy would have done this.


Restoring sounds to Papy tracks

Some of the orignal tracks have been updated in a way which means the track 3dos have lost the ssourcelist section. Putting the sound back is slightly easier than adding sounds to a track that never had any as to start with the 3dos which are the sound sources already have the ssourcelist section (or most of them do; some have been edited and the ssourcelist section lost). Also much of the data can be copied from the orignal (unedited) tracks so there's not as much to do. If you want to add sounds to non-Papy tracks you should read this section first as much of the info is still relevant.


Adding string "ssourcelist"

This process is the same for both track 3dos and non-track 3dos.
Strings are the names of files and other bits an pieces that the 3do uses. All the names of the mips, srbs, sub-3dos, etc are strings and they're stored in the STRN section. Note they're not stored with the file extension, e.g asphalt.mip will be just asphalt in the STRN section.

1. Open 3do in a hex editor and find the end of the STRN section. The easiest way to do this is to use the "find" tool and search for MIRP; the end of the STRN section will then be a few bytes before this and will be FF in hex and shown as a y with two dots above it in the text window.

End of STRN section:



2. Position the cursor at this byte (i.e click on it)  and switch to INSERT mode (press the insert key to switch between overwrite and insert modes); then type 73 73 6f 75 72 63 65 6c 69 73 74 00. (You can also type "ssourcelist" (without quotes) directly in the text window but remember to then add 00 to the end in the hex window afterwards.)

"ssourcelist" string:


3. Now you need to update the STRN section header so that it has the correct data for the length of the section, which has now increased by 12 bytes (length of section means the number of bytes in the section, not including the header). So scroll up to the top of the STRN section (or just search for NRTS) to find the header. Add 0xC to the number shown as the section length to get the new section length and type this in; make sure that you're in OVERWRITE mode.

STRN header:


And that's it for the string. It's a good idea to save the file now, partly as a back-up if it all goes wrong later but mainly so that the track can be opened in GPLeditor as a reference for the string offsets which you'll need later. Before saving you need to update the 3do header so that it has the correct data for the section length (i.e the file size). This is very easy to work out as it's just the total file size (in bytes) minus 12. The file size is shown in the bottom-right corner in FRHED (in decimal). The 3do header is the first 12 bytes of the file and the section length is bytes 8 - 11 (counting starts at 0) so just subtract 12 from the file size, convert to hex and type the number in (make sure you're OVERWRITE mode). Then save .

3do header:




Adding ssourcelist and HAND sections to track 3do

Some of this can be done by copying the data from the original Papy tracks and then pasting it back into the new track; however you will still need to edit some offsets. It's not difficult, you just need to keep your wits about you! To make it a bit easier I've made some files which contain only the data needed from the Papy tracks. i.e the ssourcelist section and the HAND section - download the zip HERE Note these file won't actually do anything - it just seemed the easiest way of getting the data into a copyable form :-) In case you're interested (and in case I've made a mistake) the ssourcelist sections of the Papy tracks are all at the start of the PRIM section (well, 4 bytes after the start - the first 4 bytes are the offset for the start of the section (which is somewhere near the end of the file...the whole things is upside down)). T-E and T-13 nodes total 48 bytes, thus 48* the number of  sound sources + 8 ( T-4, number of offsets)  + (4*number of sound sources) = the number of bytes in the ssourcelist section. (In case you're still interested, the reason I'm putting the ssourcelist at the end of the file is because if it's put back where it came from all the other offsets in the PRIM section would have to be changed, and I'm not interested in doing that :-))

1. Open <trackname>_ssourcelist file in hex editor and select all the data. Copy this to the clipboard.

2. Open the track in the hex editor. Scroll right down to the end of the file and position the cursor after the last byte. Paste the data here. (You'll need to choose 'insert' in the paste dialog box)

End of file:


3. Now you need to edit the offsets, so first you need to know what a T-E node and a T-13 node looks like in a hex editor.

T-E node
This node is used to define a sub-3do in another 3do, in this case a sound source within the track 3do. It consists of 12 bytes - the first 4 bytes are 0e 00 00 00; the next 4 bytes are the string offset; the last 4 bytes are always 00 00 00 00



The string offset references the string in the STRN section for the object which is used as a sound source. This needs to be edited so that it points to the correct string - the string name willl be the same, but it's position in the STRN section  may be different to what it was originally. The easiest way to find out the string offset is to open the track in GPL Editor and look at the STRN section. You can expand the STRN section by clicking on +

STRN section in GPL Editor:


The numbers in brackets are the string offsets. (These are shown in decimal in GPL Editor so you need to convert to hexadecimal.) Find the string in the list and enter the offset into bytes 4-7 of the T-E node in the hex editor. (See the table further down the page for a list of all the strings which are referenced for sound sources by each of the tracks.)

T-13 node
This node is used to define the position (co-ordinates, rotation and scale) of  the sub-3do in the T-E node. It consists of  36 bytes - the first 4 bytes are 13 00 00 00;  the next 28 bytes define the object's position and scale (4 bytes each for x, y, z, x-rotation, y-rotation, z-rotation, scale) - these don't need to be changed. The last 4 bytes are the offset in the PRIM section for the T-E node which immediately precedes the T-13 node in the file.



The offset for the T-E node can be found by subtracting the offset in the whole file of the start of the PRIM section by the offset (in the whole file) of the start of the T-E node. So now you need to find the start of the PRIM section - use the "find" tool and search for MIRP (may need to search 'up'). The PRIM section has a header of 12 bytes, and the section starts with the first byte after this.

Start of PRIM section:


If you position the cursor at the first byte of the PRIM section the offset for this in the whole file will be shown in the bottom-left corner (both in decimal and hex)



Make a note of this as you'll need it several times! Now go back down to the T-E and T-13 nodes and position the cursor at the first byte (0e) of the T-E node. T-E offset minus start of PRIM offset equals offset in PRIM section of the T-E node. This is the value you need to enter in the last 4 bytes of the T-13 node.
Do the same for all the other T-E and T-13 nodes! The number of T-E/T-13 pairs will vary depending on how many sound sources the track has.
NOTE: when used in the ssourcelist the T-13 and T-E nodes don't actually place an object; they just specify the co-ordinates of the sound source. Usually you'll want your sound to come from the relevant object but this doesn't have to be the case. This means that you could actually just use the same string offset for all the T-E nodes (as long as the object it references has the ssourcelist section) - the co-ords in the T-13 will define where the sounds comes from.

4. After the T-E and T-13 nodes there'll be one T-4 node. This node references all the T-13 nodes so obviously its length will depend on how many T-13 nodes there are in the ssourcelist but the first 4 bytes will always be 04 00 00 00; the next 4 bytes will be the number of T-E/T13 pairs in the ssourcelist (i.e the number of offsets in the T-4 node); then there'll be the offsets for the T-13 nodes, which are 4 bytes each. These are what you'll need to edit.

T-4 node:


The offsets for the T-13 nodes can be calculated in the same way as the T-E offsets, i.e T-13 offset minus start of PRIM section. The order is from top to bottom, so bytes 8-11 of the T-4 node will be the offset for the first T-13 in the file, bytes 12- 15 for the next T-13, etc. The whole structure of the ssourcelist might make more sense when seen in GPL Editor (note GPL Editor uses decimal for node types, so T-E = 14 and T-13 = 9)

ssourcelist in GPL Editor:


5. Now you need to edit the HAND section. There's two things to change here, the string offset and the offset which points to the start of the ssourcelist.

HAND section:


The string offset is the offset in the STRN section of the "ssourcelist" string. This can be found by looking at the list of strings in the STRN section in GPL Editor.
The offset to the start of the ssourcelist points at the T-4 node, so start of T-4 node minus start of PRIM section gives the value that need to be entered here.

6. Next you need to update the PRIM header so that the data for the section length is correct. The length of the PRIM section is start of HAND section minus start of PRIM section. This is then entered in bytes 8 - 11 of the PRIM header.

PRIM header:


The last thing to be done is to update the 3do header so the data for the size of the file is correct. This was described earlier.

Then save, and that's it. :-)

EDIT - d'oh!!! Although the above method will work it's not actually necessary to add all the new T-E and T-13 nodes as these already exist in the track 3do. As mentioned the ssourcelist consists of a T-4 node which contains offsets that point to all the objects which are sound-sources; so all that needs to be done is to find the offsets in the track 3do for these objects and add these to the T-4 node. Finding these offsets is not difficult but it take a while as it basically means searching the 3do for the required objects, but this might be preferable to hex-editing a load of new T-E and T-13 nodes :-) So the process would now be: 1) add "ssourcelist" string;  2) add T-4 node at end of  file and add the offsets for sound-source objects (note no need to add T-E and T-13 nodes);  3) add HAND section

Sound sources for Papy tracks

Here are the names of the objects that each track uses as sound sources. Some objects are used more than once - the purpose of the list is to show the strings in the order they appear in the ssourcelist section of the track 3do. For some reason the Nurburgring doesn't have an ssourcelist; for some other, slightly more curious reason the Spa track 3do has ssourcelist but the object it references doesn't.....
Kyalami Mexico Monaco Monza   Mosport
1. gstand1
2. gstand2
3. gstand4
4. gstand2
5. gstand2
1. garage
2. stand
1. flagbox
2. stand1
3. sfstand
4. grandsf1
1. paddock
2. trees25
3. trees45
4. front01
5. front02
6. front03
7. front04
8. front05
9. front06
1. grndst1
 2. grndst2
3. grndst3
4. grndst4
 Rouen Silverstone Spa Watkin's Glen Zandvoort
1. garage
2. gstand3
3. gstand2
4. gstand2c
5. gstand3c
1. grand
2. grand
3. grand
4. grandb
5. grandb
6. cheaps
7. cheaps2
8. cheaps3
9. skybox
10. grandb
11. grand2
1. leafrow
2. leafrow

Not used -
leafrow.3do
 does not
have
 ssourcelist
1. office
2. bld2
3. bld3
4. grand
5. grandl
6. grand
7. bld4
8. newpit
1. gstand

                                                              
                                                                                           
Adding ssourcelist and HAND sections to non-track 3dos

This is a lot less complicated than with the track 3dos as the ssourcelist section is always the same and there's only three offsets to edit.

1. First you need to add the string "ssourcelist" to the STRN section. This can be done in a hex editor in the same way as for a track 3do; however it's much easier to use GPL Editor - just click the 'add new string' button and type in "ssourcelist" (Note this can't be done for track 3dos as GPL Editor cannot save a track 3do) This is the only part of adding sounds that can be done in GPL Editor - everything else requires a hex editor :-(

New string in GPL Editor:


2. The ssourcelist section for a 3do consists of one T-4 node and one T-10 node; the T-10 node is the one which makes sounds happen. This can go at the end of the PRIM section, which will probably be at the end of the file BUT if the object has a collision volume there'll be a HAND section at the end - in this case the ssourcelist (T-4 and T-10 nodes) must come before the HAND section  (but still at the end of the PRIM section). Either way, the data you have to add will be the same, which is as follows:

10 00 00 00   02 00 00 00   00 00 00 00    00 00 00 00 - this is the T-10 node. Immediately after comes the T-4 node: 04 00 00 00   01 00 00 00   ....and then 4 bytes for the offset to the T-10 node. (start of T-10 node minus start of PRIM section equals offset)

3do ssourcelist:
                                                                                                         
3. Then comes the HAND section. If the 3do doesn't already have a HAND section you'll need to add one. It will be 20 bytes as follows:

44 4e 41 48   00 00 00 00   08 00 00 00   string offset (4 bytes)   offset to start of ssourcelist, i.e T-4 node (4 bytes)

3do HAND section:                                                                                                         

                                                            
If the 3do does already have a HAND section then you'll need to edit it so it also references the ssourcelist. All that needs to be done is to add the string offset and offset for the ssourcelist, and then update the HAND header so the section-length data is correct, i.e add 8.

3do HAND section - collision and ssourcelist:                                                                                       
                                                       

4. Finally update the PRIM header and 3do header for the correct section lengths, and save :-)                                 
                                                                                           
                                                                                          
 Adding sounds to other tracks

This is a bit more complicated than adding sounds to Papy tracks but the basic principal is the same - add "ssourcelist" string, add ssourcelist section, add HAND section. However all the nodes will have to be made from scratch, although this isn't really too difficult once you get used to how a node looks in a hex editor.

The procedure is the same for Papy tracks, so first you add the "ssourcelist" string. Then you add the ssourcelist itself, but instead of pasting data at the end of the PRIM section you need to make it yourself  - T-E node first, then the T-13 which references this T-E. Add as many pairs of T-E and T-13 nodes as you want sound sources, then add the T-4 node which will reference the T-13s. Finally add the HAND section and update the PRIM and 3do headers. Now all that in more detail....

T-E node
Always 12 bytes. The only part you need to edit is bytes 4-7, which is the string offset....


T-13 node
Always 36 bytes....


The co-ordinates are all absolute co-ordinates, i.e they are offset from the x=0 y=0 z=0 point of the track (exactly where this is will vary from track to track). Dave Noonan's 3doEd utility has an option "list inserts" which will produce a text file listing the absolute co-ords of all the objects in the track.

The rotation values are all in radians.... but the list of inserts shows rotation in degrees, so you'll need to convert into radians - THIS SITE can help with that.

The scale is always 1 (0x3f800000)

The co-ords, rotation and scale are all 'floats' (numbers with decimal points). Windows calculator won't convert floats to hex, but THIS SITE will :-)

The offset points to the T-E which precedes the T-13 node (although it doesn't have to; it's just probably best to stick to this structure)

T-4 node
This will vary in length depending on how many offsets it has, i.e how many T-13/T-E pairs (sound sources) there are....


I guess the main thing to be sure of here is that the number given as the number of offsets does actually match the number of offsets! And as always, make sure the offsets do point to where they're supposed to.

HAND section
This is always 20 bytes when used in the track 3do....


The section length will always be 8 for the HAND section in a track 3do; the string offset points to the "ssourcelist" string in the STRN section.


..and that's it. I hope this all makes sense, if not straight away then maybe eventually! There's no doubt some things I've forgotten to mention or haven't explained very well - any questions/complaints then post on THIS THREAD at Race Sim Central. :-)


last updated 20/5/06