Changing sounds and music - technical issues
Sorry for my English, it's not excellent.
One of the best programmer here I mean Helix666 made fantastic tool to change any sound in TW2 game. This tool is called:
TW2SoundUtil and it was presented first time on 8 January 2011 in the following thread
Two Worlds 2 Sound store editor, link:
http://www.insidetwoworlds.com/showthread.php?t=32697. This is a very useful program because using it we can change practically every game sound file - music, sound effects, and even voices of game characters. And all of it with an easy manner.
We can insert any number of new sound files or extract existing ones to OGG format because exactly files of this format are stored in sound archives in ...Two Worlds 2\SoundData sub-folder. In the mentioned thread there is also short concise conversation on how to use Helix's application. In this post I want to raise an issue of changing sound files in TW2 and problems related to it.
A some sort of small introduction
Because I'm a musician when some game appears and I like it, and the game is modding-prone, after some time I always seek answer the question: How to change the music in this game? In this case the same situation took place. When I noticed Helixe's tool I started to dig and did many tests to understand how the TW2 game manipulates its sounds and especially music. During that digging I found some answers and also some new questions and problems arose related to changing sounds in TW2. In this post I'd like to share those issues with you. Maybe they will be helpful, I hope.
What I noticed while digging
I will come to the point. Let's go back to the first few lines of this text and continue. You can notice that physically sounds are stored in the folder ...Two Worlds 2/SoundData in files with extensions: .idx, .asncdat, .database. The .lipsync extension files as we can easily guess concern synchronization of game characters lips and recorded dialogs. To use Helix's tool we need to deliver one of the .idx files (Helix called it: sound store index files) to his TW2SoundUtil. After loading an .idx file we can see some kind of folders tree, where every folder has a name which in certain cases (especially in sfx*.idx files) corresponds with the type of sounds it stores. Helix named those folders cues. Every cue can contain more than one sound file. In case of sfx*.idx files I noticed the different files in the same cue are similar to each other. This is because the game choose them randomly while playing (probably in order to create an effect of greater diversity of sounds). You can notice it yourself e.g. while gaming open inventory tab and several times take off and put on our hero's armor. Try to remember the sounds. Then exit the game and open sfx.idx file with the TW2SoundUtil, next find cue named ACTION_METAL and play every one of the three sound files placed there. They are similar to each other, but not the same. The same situation takes place while the game system plays any sound file containing music (from music related files). But in this case, I mean when one of the cues contains more than one music piece, those pieces of music are usually different. While playing the game when we enter a new location the cue or cues corresponding to this location are set (so to speak) and if one of the location related cues contains the suffix: _INT at the end of its name (I suppose it is from INTRO) one of the randomly chosen files is played from there. Than (if we haven't changed entered location yet and nothing important has happened or there was no fight) game system goes to the cue ended by _GAP string and started to play randomly chosen files one after another from this cue. Being still in the same area when somebody or something attacks us, this time the game system jumps to _BE cue and plays randomly its contents until the fight is finished. Described process would repeat constantly if we didn't go to another location. There are certain exceptions to this rule, especially while fighting, it means while the _BE cue is used. When we look closer at the contents of some _BE cues we can see some filenames end with _BOSS suffix while others with _BE suffix. As everybody can guess _BOSS files concern fighting with bosses. And one more thing: cues where we can notice _BOSS suffix files, those cues contain only two files: one with _BOSS suffix and one with _BE suffix. This means despite the game generally plays randomly chosen files from that particular cue in this situation we have an exception because here game system differentiates these two files and uses their names to find the difference (!). This can be important if we want to change the music while fighting with bosses. I don't know if the only _BOSS suffix is sufficient or exactly the same original whole filename is needed if we want to make sure the appropriate music will be played while fighting with some boss. Probably the best and the safest method would be to use exactly the same filename as stored in the original music.idx file. Of course all of this is only an introduction. Probably there are many other specific situations where specific cues and also files with specific filenames are used to play proper sound file in particular moment in the game. I don't know all of such situations.
So..what? Everything seems to be ok... but...
As I mentioned before sound files stored in ...\SoundData folder are OGG format. I did many tests changing OGG files to add some variety to the game, and constantly had one problem. Suppose we want to change music played while in New Ashos. Originally the game system will work in such way (more or less):
1) Entering New Ashos location --> playing introductory music from 1_ASIAN_TOWN_INT cue (originally there is only one music piece in this cue: (INTRO)ASIAN-TOWN.OGG)
2) We are still in New Ashos area --> playing randomly chosen music piece from 1_ASIAN_TOWN_GAP cue. The process is repeating until something unusual happens or we exit the New Ashos area. (In original game in this _GAP cue there are only two files: GAP_ASIAN_01.GAP and GAP_ASIAN_02.OGG. They will be played randomly until:
3a) We are attacked by somebody or something (but not a boss) --> in this particular situation only one file can be played over and over again until battle is finished: BE_ASIAN_PLACES_01_BE.OGG, because originally the only one file is available in the 1_ASIAN_TOWN_BE cue.
3b) We are attacked by a boss --> the file: BE_ASIAN_PLACES_O1_BOSS.OGG and it will be played repeatedly until the fight is over.
4) We are still in New Ashos location --> the same situation as in 2nd pt. takes place.
Now suppose we have our own interesting OGGs and we want to change music in New Ashos location (using TW2SoundUtil) in the following manner:
1) Entering New Ashos (_INT): We are changing original OGG files to e.g.: NA_Int1.ogg, NA_Int2.ogg, NA_Int3.ogg (we want every time we enter New Ashos territory to hear more diversified music than in the original version of the game (always the same music is played while entering New Ashos)).
2) We are still in Ashos (_GAP): We want to change two original files to different ones and add some more. So we remove original files and add e.g.: NA_Gap1.ogg, NA_Gap2.ogg, NA_Gap3.ogg and so on..let's say up to 10 different OGG files.
3) At the moment we decided not to change files in _BE cue.
And after saving our modified set of music pieces (using TW2SoundUtil), running the game and entering New Ashos town what we get?: In fact we hear one of our NA_Int OGGs but after first melody and as usual after some pause ...nothing happens with the music. It simply stops playing. We can wait and wait. If we leave New Ashos area and go back we can hear again one of our NA_Int OGGs but after one piece of music the music stops again.
Where is the error?
Like I said I did many, many tests and at last I found the answer. Maybe somebody knows about it and hasn't said anything so far? Well, the problem is connected with OGG headers. Without going into details every typical OGG header contains some customizable header fields (like in MP3 files) (in format:
name: value) which can be used to describe some info on a given sound file: title, version, album, tracknumber, artist and so on. But by means of some sound editing program (like e.g.: Audacity 1.3.12 beta (Unicode)) we can add more our own fields and we are not limited to only standard named fields. Moreover we can name it as we wish. For example we can even add totally new field and name it: Does my sister like it? and assign the value: Yes (or No :-) or whatever we want. Yet we can add as many such fields as we want. TW2 creators did a similar thing and created a new field named:
size and the value of this field must equal:
size_of_the_ogg_file_in_miliseconds - 1. Why? I don't know. Only TW2 creators can give us exact answer. Probably such information helps game engine to play sound files correctly. But only one important think I know: after I checked how big in milliseconds my OGGs files are (I used pretty useful program called: MediaTab), when I created
size fields in my OGGs headers (with Audacity 1.3.12-beta Unicode) and filled them with mentioned calculated value, saved those OGGs with changed headers, than put them in TW2 archives (with Helix's TW2SoundUtil) and put modified archives in the .../SoundData sub-folder... when I ran the game and started to walk New Ashos streets, TW2 began to play my music files correctly !!! The music was played constantly !! (of course with short pauses between music pieces), music was chosen randomly and everything started to work right. I didn't check it but the same situation may happen with sfx sound archives. If you want to change sfx sound files you need to change their headers as described above. Otherwise you may have problems not only with one particular cue but also with other cues and to sum up, you can't even hear whole parts of sounds in the game because of such "trifle".
I think, that's all I wanted to share with you. I also wrote this post because I wanted to encourage you to test TW2 behavior connected with sounds, music and the like and share your knowledge with people in this forum.
And I hope somebody can make a program to facilitate changing our OGG files headers faster then I described above (before we put them in a given TW2 sound archive).
lestat426