AMB Format Analysis

Flintlock

King
Joined
Sep 25, 2004
Messages
888
Over the past few months I've been slowly working on decoding the AMB files used by Civ 3. These files have been mysteries since the game was released, a few people have looked into them but no one has gotten very far, at least not that I know of. We want to enable C7 (the open source Civ 3 recreation) to read these files so the time has come to get them figured out once and for all. So far I have the core of the job done. I've posted my work to a GitHub repo here: https://github.com/maxpetul/Civ3AMBAnalysis.

The Python script in that repo can completely parse all AMBs in Civ 3. For example, here's the contents of TrebuchetRun.amb:
Code:
prgm    3       200     -200    127     75      'Foot 1'  'TrebRunFoot1'
prgm    3       200     -200    127     75      'Foot 2'  'TrebRunFoot2'
prgm    0       0       0       0       0       'Wheels'  'TrebRunWheels'
prgm    3       200     -200    127     75      'Vox'  'TrebRunVox'
prgm    0       0       0       0       0       'Wheels End'  'TrebRunWheelsEnd'
kmap    2       0       0       'TrebRunFoot1'  1       12      ["b'\\x7f\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00'  'TrebuchetRunFoot1.wav'"]
kmap    2       0       0       'TrebRunFoot2'  1       12      ["b'\\x7f\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00'  'TrebuchetRunFoot2.wav'"]
kmap    2       0       0       'TrebRunWheels' 1       12      ["b'\\x7f\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00'  'TrebuchetRunWheels.wav'"]
kmap    2       0       0       'TrebRunVox'    1       12      ["b'\\x7f\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00'  'TrebuchetRunVox.wav'"]
kmap    2       0       0       'TrebRunWheelsEnd'      1       12      ["b'\\x7f\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x00\\x00\\x00'  'TrebuchetRunWheelsEnd.wav'"]
glbl    12      b'$\x00\x00\x00\x00\x00\x00\x00\xcd\xcd\xcd\xcd'        b''
Midi:
        ticks per quarter note: 480
        Track:
                0.000   TrackName 'Seq-1'
                0.000   SMPTEOffset 96 0 0 0 0
                0.000   TimeSignature 4 2 24 8
                0.000   SetTempo 705882
                0.000   EndOfTrack
        Track:
                0.000   TrackName 'Foot 1'
                0.000   ControlChange 0 32 0
                0.000   ProgramChange 0 1
                0.228   NoteOn 0 60 64
                0.625   NoteOff 0 60 64
                0.625   EndOfTrack
        Track:
                0.000   TrackName 'Foot 2'
                0.000   ControlChange 1 32 0
                0.000   ProgramChange 1 2
                0.541   NoteOn 1 62 64
                0.625   NoteOff 1 62 64
                0.625   EndOfTrack
        Track:
                0.000   TrackName 'Wheels'
                0.000   ControlChange 2 32 0
                0.000   ProgramChange 2 3
                0.000   NoteOn 2 64 64
                0.625   NoteOff 2 64 64
                0.625   EndOfTrack
        Track:
                0.000   TrackName 'Vox'
                0.000   ControlChange 3 32 0
                0.000   ProgramChange 3 4
                0.134   NoteOn 3 65 64
                0.625   NoteOff 3 65 64
                0.625   EndOfTrack
        Track:
                0.000   TrackName 'Wheels End'
                0.000   ControlChange 4 32 0
                0.000   ProgramChange 4 5
                0.596   NoteOn 4 67 64
                0.625   NoteOff 4 67 64
                0.625   EndOfTrack
You can generate this yourself by following the instructions at the top of the Python script. AMB files are pretty complicated but that's only because they're way over-engineered, they can be boiled down to something very simple. Basically the way AMBs work is that they contain a bunch of component sounds with randomized effects applied. Using the example above, those "NoteOn" events in the Midi tracks indicate when the component sounds are to be triggered (the first number on those lines indicates the time of the event in seconds, computed by the script). Each component sound corresponds to a "prgm" chunk that specifies some randomized effects and a variable name. Finally the variable name is associated with a WAV file name by a "kmap" chunk.

There are still some things I haven't figured out. Specifically, I believe the 2nd and 3rd numbers in the prgm chunks specify bounds for a random pitch/tempo but I don't know what the units are, f.e. from above the pitch/tempo in the first chunk is randomized between +/- 200, but "200" of what? Also I don't know what the fourth and fifth numbers in the prgm chunks are, I suspect at least one of them specifies a randomized volume. I have managed to play an AMB file "manually" by loading the component WAV files into Audacity and arranging them at the set times. I checked that the result sounds similar to the in-game effect, so like I said, the core of the job is done.

Once the AMBs are completely decoded, it would be easy to write a tool to modify them or create new ones. That's not super valuable since you can just stitch together sound files manually, as modders have been doing for 20 years now. The only reason to use AMBs is for the randomized effects and to save a bit of disk space. In any case, if that's something people are interested in, just ask and (maybe) I'll make it happen.
 

Vuldacon

Dedicated to Excellence
Supporter
Joined
Nov 14, 2001
Messages
7,044
Location
USA
Flintlock... Glad you are looking into the AMB files if for nothing else than providing C7 the ability to read the ones that have been used.

Not sure why the Run sounds that use AMB files do not work well. Especially foot Units that run more tiles will start playing crazy fast like a machine gun.
Run sounds tend to play again after the Unit has stopped moving and especially toward the coasts.
Attack sounds also many times play again after the Unit animation stops or when the Unit dies and the Death animation plays.

While it is important to have C7 be able to use the existing AMB files, it would be far better to have all Unit sounds absolutely match the animation time so if a Run animation is 1 second, the sound play back should be 1 second then it is just a matter of math for foot steps when the left and right feet hit the ground on what ever frame of the animation.

Unit sounds have many sound bytes that are sounds the Unit makes such as a step then a whoosh sound of a sword then the sword hit, etc... all of those sounds bytes could be added in to a sound .wav file on the frames they take place on and should play back exactly.

It seems as though the sound play back uses alternate pitch and timing play back like the ambient sounds. I believe this type of sound play back was used to gain some different ambient sounds using the few existing ones... possibly to save game space.

The AMB files are "programs" specific to the Unit they are used for. If people try to use the existing AMB files that are meant for a particular Unit and alter them for another Unit, the original Unit will also be affected by the changes made.

There is some information Online about AMB files and how to make them but they require more special programs and details that most cannot use.
"Files containing the AMB extension are known as AIMMS Model Files as they refer to the models that the AIMMS (Advanced Integrated Multidimensional Modeling Software) created. The AMB file extension was developed by Paragon Decision Technology and the files with this extension are categorized as data files".
 

Flintlock

King
Joined
Sep 25, 2004
Messages
888
Not sure why the Run sounds that use AMB files do not work well. Especially foot Units that run more tiles will start playing crazy fast like a machine gun.
I'm not sure exactly what's going on there either. My guess is that the engine tries to loop the AMB sound effect when a unit is moving diagonally between tiles, because diagonal movement takes longer than normal, but then when the animation ends much sooner than the second AMB effect, the engine tries to stop the AMB quicker by compressing the timings. That would explain why the footsteps sound like a machine gun, but it doesn't match exactly what I hear. Listening in-game to a trebuchet walking around, I can hear TrebuchetRunVox.wav getting played not twice but three times when the unit moves along a diagonal. I can't imagine how/why that's happening.
While it is important to have C7 be able to use the existing AMB files, it would be far better to have all Unit sounds absolutely match the animation time so if a Run animation is 1 second, the sound play back should be 1 second then it is just a matter of math for foot steps when the left and right feet hit the ground on what ever frame of the animation.
That's how we have it programmed right now. In C7 the run animations take the same amount of time for all directions so there would be no need to loop the sound. The downside to this approach is that units moving diagonally will slide along the ground faster than their legs appear to be carrying them.
The AMB files are "programs" specific to the Unit they are used for. If people try to use the existing AMB files that are meant for a particular Unit and alter them for another Unit, the original Unit will also be affected by the changes made.
That must be because of the AMB variables. You should be able to use an existing AMB with a different unit as long as you edit it so that the variable names are different from the ones in the original.
 

Vuldacon

Dedicated to Excellence
Supporter
Joined
Nov 14, 2001
Messages
7,044
Location
USA
That's how we have it programmed right now. In C7 the run animations take the same amount of time for all directions so there would be no need to loop the sound. The downside to this approach is that units moving diagonally will slide along the ground faster than their legs appear to be carrying them.

Yes, that will be a problem graphically.

It does seem to be the game is trying to play back sounds that cannot fit the length long and shot distances regardless of the AMB files.
...there may not be a good way to solve this sound problem with units.

I wonder how this is affecting Attacks playing again at the Unit Death or after the Attack stops?

It is not the Unit Run animation but rather the game moving the Unit across the map with the different lengths and trying to play the same sound... it would probably be an extreme difficulty to set the Unit sounds to play the diagonal moves differently than the shorter vertical and horizontal moves... I assume that was the main reason the .amb files were used.

This has been a "Headache" for years and caused a great deal of time to try to make sounds and have the Game play the sounds correctly.

Flintlock... You know, it is not meant to be "funny" but there is a Plethora of details that are desirable to correct/change... it fact there are so many requests You can be assured that you have what I call "Job Security", meaning many years to accomplish the tasks if at all :crazyeye:

Suffice to say that all you have done is Great and each correction- adjustment-addition-change has allowed a tremendous Leap in Modding here :hatsoff::clap:
 

Ozymandias

Archivist of C3C Game Info and Assets
Supporter
Joined
Nov 5, 2001
Messages
10,223
Location
The lone and level sands
@Flintlock - I just wound up Googling .amb files, and I'm wondering if there's a mismatch between, oh, 1998 and now:

"Files containing the AMB extension are known as AIMMS Model Files as they refer to the models that the AIMMS (Advanced Integrated Multidimensional Modeling Software) created." -AND- (of course, perversely) - " AMB files are saved in the .MDB (Microsoft Access) format."

There's a lot more tech info than that, but that's the gist of the insanity of it.
 

WildWeazel

Carthago Creanda Est
Joined
Jul 14, 2003
Messages
7,234
Location
%CIV3%\Conquests\Scenarios\
Though we'd like to pretend otherwise, there's a difference between file format (the standard by which the data is interpreted) and file extension (the part of the filename after the dot). The latter is supposed to indicate the former, but there's nothing stopping anyone from making different formats with the same extension or vice versa. We already see this in Civ3 with its own variation of the "FLC" format. Point being that third party references may or may not hold true for the files in question, or may be entirely unrelated.
 

Flintlock

King
Joined
Sep 25, 2004
Messages
888
@Flintlock - I just wound up Googling .amb files, and I'm wondering if there's a mismatch between, oh, 1998 and now:
"Files containing the AMB extension are known as AIMMS Model Files as they refer to the models that the AIMMS (Advanced Integrated Multidimensional Modeling Software) created." -AND- (of course, perversely) - " AMB files are saved in the .MDB (Microsoft Access) format."
Yeah I found that too searching for info about the AMB format. I read up a bit on AIMMS wondering if that could possibly be what Civ 3 was using, that would make AMB files insane overkill since fundamentally all they do is combine some WAV sounds. Of course Civ 3's AMBs are an unrelated format, though they are still overkill. For example they contain variables which AFAIK are only used as aliases for WAV file names. They each contain an entire MIDI file of which the only important parts are the time stamps on each NoteOn event. The code to parse them in contains references to some kind of audio channel chunks, except no AMBs in Civ 3 have those chunks. I wonder what all of this was supposed to be used for.
 
Top Bottom