Adding Sounds

Pazyryk

Deity
Joined
Jun 13, 2008
Messages
3,584
I noticed that Hypereon appears to be doing this in the Finnish Civilization mod.

This is just my running notes as I attempt to deduce what was done.

From looking inside the mod, what he appears to have done is replace these three files.

RamkhamhaengAmbience.mp3
RamkhamhaengPeace.mp3
RamkhamhaengWar.mp3

I played these and they make nice new sounds. I haven't actually played the mod yet but Hypereon indicates in the thread that they do play in game. Hypereon notes that he had to "replace" the Ramkhamhaeng leader with his Finnish leader.

These three sound files are referenced (without the .mp3 extension) in Sounds/XML/AudioDefines.xml and the structure looks line this:

Code:
<AudioDefinesFile>
  <SoundDatas>
    <SoundData>
      <SoundID>SND_AMBIENCE_RAMKHAMHAENG_AMBIENCE</SoundID>
      <Filename>RamkhamhaengAmbience</Filename>
      <bDontCache/>
      <bOnlyLoadOneVariationEachTime/>
      <LoadType>DYNAMIC_RES</LoadType>
    </SoundData>
...

This xml links the sound file to a SoundID. As far as I know, we can't add SoundDatas. But I haven't really tried yet so I'm not sure.

Inside RamkhamhaengAudio2DScripts.xml you find this:

Code:
<Script2DFile>
  <Script2DSounds>
    <Script2DSound>
      <ScriptID>AS2D_AMBIENCE_LEADER_RAMKHAMHAENG_AMBIENCE</ScriptID>
      <SoundID>SND_AMBIENCE_RAMKHAMHAENG_AMBIENCE</SoundID>
      <SoundType>GAME_SFX</SoundType>
      <bLooping>True</bLooping>
      <iMaxVolume>35</iMaxVolume>
      <iMinVolume>35</iMinVolume>
    </Script2DSound>
...
  </Script2DSounds>
</Script2DFile>

This xml links SoundID to ScriptID. I don't really know why Hypereon included this file -- I can't tell what was changed in it.

OK, looking in his CIV5Leader_Mannerheim.xml I see that he hasn't technically replaced Ramkhamhaeng, but rather has changed the description text, art and some other stuff:
Spoiler :
Code:
		<Leaders>
			<Update>
				<Where Type="LEADER_RAMKHAMHAENG"/>
				<Set>
					<Description>TXT_KEY_LEADER_MANNERHEIM</Description>
					<Civilopedia>TXT_KEY_LEADER_MANNERHEIM_PEDIA</Civilopedia>
					<CivilopediaTag>TXT_KEY_CIVILOPEDIA_LEADERS_MANNERHEIM</CivilopediaTag>
					<ArtDefineTag>Mannerheim_Scene.xml</ArtDefineTag>
					<VictoryCompetitiveness>7</VictoryCompetitiveness>
					<WonderCompetitiveness>7</WonderCompetitiveness>
					<MinorCivCompetitiveness>8</MinorCivCompetitiveness>
					<Boldness>7</Boldness>
					<DiploBalance>3</DiploBalance>
					<WarmongerHate>6</WarmongerHate>
					<WorkAgainstWillingness>4</WorkAgainstWillingness>
					<WorkWithWillingness>8</WorkWithWillingness>
					<PortraitIndex>1</PortraitIndex>
					<IconAtlas>CIV_COLOR_ATLAS_FINLAND</IconAtlas>
				</Set>
			</Update>
		</Leaders>

So LEADER_RAMKHAMHAENG is still there, technically speaking (he has been doppelgangered by Mannerheim!). I believe that this is where we hit a bit of a dead end. You can play the mp3 sounds easy enough. Just try this in the Fire Tuner:
Code:
Events.AudioPlay2DSound("AS2D_AMBIENCE_LEADER_RAMKHAMHAENG_AMBIENCE")
However, you won't find AS2D_AMBIENCE_LEADER_RAMKHAMHAENG_AMBIENCE referenced anywhere that links it to LEADER_RAMKHAMHAENG. The AS2D sounds seem to be hardcoded to particular leaders in the dll.

What I'm actually more interested in is adding my own music tracks. I have a feeling that I might be able to do a brute-force replacement as Hypereon did here. That is, just add mp3 music files that have the same name as existing ones (I don't actually know where the base game mp3 files are, but they are referenced in AudioDefines.xml). I'll keep posting here if I figure anything out...
 
Yes, that what I used in the WWII scenario for DoM speech, just mp3 with same name as the one from the original civ and VFS to true.
 
Well that's annoying. Music files appear to be streamed directly out of the instalation folders:

C:\Program Files\Steam\steamapps\common\sid meier's civilization v\assets\Sounds\Streamed\Music\

In there you find Europe\Peace\, Europe\War\, etc.

The music files are all .ogg, which you can find a converter for easily enough. Unfortunately, you can't change any of the xml info that links Civ to particular tracks (see spoilers below). Even worse, you can't even replace an existing music file in the normal override manner (using same file name with VFS=true).

You can replace the files in the installation folder. Just create ogg files and use the names that are already there. This does work. Not a great way to mod, but at least it is an option if your mod needs its own soundtrack (but then you need to replace them all...and there are a lot).

If you want to see what soundtracks are played for each civ, you need to look in (for example) RomeAudio2DScripts.xml, where you see this:
Spoiler :
Code:
    <Script2DSound>
      <ScriptID>SONG_ROME_PEACE_3</ScriptID>
      <SoundID>SND_EUROPE_PEACE_3</SoundID>
      <SoundType>GAME_MUSIC</SoundType>
      <iMinVolume>40</iMinVolume>
      <iMaxVolume>40</iMaxVolume>
      <bIsMusic>True</bIsMusic>
      <iPriority>1</iPriority>
    </Script2DSound>
    <Script2DSound>
      <ScriptID>SONG_ROME_PEACE_4</ScriptID>
      <SoundID>SND_EUROPE_PEACE_4</SoundID>
      <SoundType>GAME_MUSIC</SoundType>
      <iMinVolume>40</iMinVolume>
      <iMaxVolume>40</iMaxVolume>
      <bIsMusic>True</bIsMusic>
      <iPriority>1</iPriority>
    </Script2DSound>
    <Script2DSound>
      <ScriptID>SONG_ROME_PEACE_5</ScriptID>
      <SoundID>SND_EUROPE_PEACE_5</SoundID>
      <SoundType>GAME_MUSIC</SoundType>
      <iMinVolume>40</iMinVolume>
      <iMaxVolume>40</iMaxVolume>
      <bIsMusic>True</bIsMusic>
      <iPriority>1</iPriority>
    </Script2DSound>
    <Script2DSound>
      <ScriptID>SONG_ROME_PEACE_6</ScriptID>
      <SoundID>SND_EUROPE_PEACE_6</SoundID>
      <SoundType>GAME_MUSIC</SoundType>
      <iMinVolume>40</iMinVolume>
      <iMaxVolume>40</iMaxVolume>
      <bIsMusic>True</bIsMusic>
      <iPriority>1</iPriority>
    </Script2DSound>
I believe that the ScriptIDs are hard-coded to each civ type (e.g., CIVILIZATION_ROME). Then look in EuropeAudioDefines.xml where you will see this:
Spoiler :
Code:
<SoundData>
			<SoundID>SND_EUROPE_PEACE_3</SoundID>
			<Filename>Chanson</Filename>
			<LoadType>STREAMED</LoadType>
		</SoundData>
		<SoundData>
			<SoundID>SND_EUROPE_PEACE_4</SoundID>
			<Filename>Dusk0123</Filename>
			<LoadType>STREAMED</LoadType>
		</SoundData>
		<SoundData>
			<SoundID>SND_EUROPE_PEACE_5</SoundID>
			<Filename>Fantasias_A_3_No.6</Filename>
			<LoadType>STREAMED</LoadType>
		</SoundData>
		<SoundData>
			<SoundID>SND_EUROPE_PEACE_6</SoundID>
			<Filename>Fete-DieuASeville</Filename>
			<LoadType>STREAMED</LoadType>
		</SoundData>
This links the SoundIDs to the actual file names (which you find in the above mentioned directory with .ogg extentions).
 
So, would it work if we were to replace those filenames in the AudioDefines.xml with new filenames from the mod, or does it automatically look for them only in the aforementioned folders of the game?
 
I'm still a bit puzzled. The expansion scenarios seem to be adding music just fine. They just link file name to SoundID to ScriptID (in xml files) and then drop the .ogg file in the DLC directory.

I can't tell if my xml changes work here because this isn't affecting any DB that I can look at. So I don't know whether my xml is failing or if my .ogg file is failing (though I know the .ogg file works if I drop it in the installation folder replacing an existing one).

One interesting thing. You can play any existing music track using a valid ScriptID like this:

Events.AudioPlay2DSound("SONG_ROME_PEACE_1")

If you do, then the next music track won't start until that one ends. But then it does restart after your tune stops. Makes me think we could build our own "Jukebox player" in Lua (just need to disable the existing player, if that's possible).
 
I'm still working on this off and on. My goal is to be able to add both sound effects and new music tracks to my total conversion mod. Here is where I'm at:

  1. I CANNOT modify the relevant database entries that link sound files to SoundIDs to ScriptIDs in a mod. These are encoded in various files in the assets/Sounds/XML directory and can only be changed (as far as I can tell so far) by editing the installation files.
  2. I CAN relpace existing .mp3 sound files by adding "replacement files" in my mod (i.e., same-named files with VFS=true).
  3. I CANNOT do the same for existing .ogg sound files, which is the way that the non-leader music tracks are encoded (these are in assets\Sounds\Streamed\Music\). I did try replacing these in the installation folder. This works, which proves that I CAN make a valid .ogg file. Edit: according to Harald B, you CAN replace the .ogg sound file with an mp3 sound file of the same name (except extension).
  4. I CAN play any sound including long music tracks (whether .mp3 or .ogg) using Events.AudioPlay2DSound(<ScriptID>).

Edit: So both sounds and soundtracks can be modded, but only by replacement of existing files.
 
Im having trouble...Looking in log cause the file didn't play, It says the leader i "updated" doesn't exist. I set it to update Washington but its says "LEADER_WASHINGTON Does not exist in Leaders."
 
Im having trouble...Looking in log cause the file didn't play, It says the leader i "updated" doesn't exist. I set it to update Washington but its says "LEADER_WASHINGTON Does not exist in Leaders."

Then that means that washington doesn't exist. How'd you manage that?

Cereal.gif
 
I check in the Leaders file "Civ5Leader_Washington" and it said LEADER_WASHINGTON.
Then after that, I decided to make it the file name and that error went away but now it says that my modded civ leader "LEADER_KANYE Does not exist in leaders." The mod without the soundtrack worked, but then when this happens the CIV does not showup. I checked the logs for anything else but nothing else relating to my problem.
 
When XML (or SQL) fails due to some error, there is no Runtime Error. The only evidence you have is that it didn't work. In other words, your change didn't happen. You can use SQLite Manager to inspect the DB directly (I find it easier to look at the DB rather that puzzling out what's wrong from logs). In this case it will probably tell you what you already know, which is that LEADER_KANYE does not exist. If you post code, often someone will spot the error and tell you.
 
I set Kanye to replace Washington. Can you look at the code which is causing the civ to dissapear?

<GameData>
<Update>
<Delete Type="LEADER_WASHINGTON"/>
<Set>
<Type>LEADER_KANYE</Type>
<Description>TXT_KEY_LEADER_KANYE</Description>
<Civilopedia>TXT_KEY_LEADER_KANYE_PEDIA</Civilopedia>
<CivilopediaTag>TXT_KEY_CIVILOPEDIA_LEADERS_KANYE</CivilopediaTag>
<ArtDefineTag>KanyeScene.xml</ArtDefineTag>
<VictoryCompetitiveness>8</VictoryCompetitiveness>
<WonderCompetitiveness>7</WonderCompetitiveness>
<MinorCivCompetitiveness>3</MinorCivCompetitiveness>
<Boldness>8</Boldness>
<DiploBalance>3</DiploBalance>
<WarmongerHate>2</WarmongerHate>
<WorkAgainstWillingness>7</WorkAgainstWillingness>
<WorkWithWillingness>4</WorkWithWillingness>
<PortraitIndex>0</PortraitIndex>
<IconAtlas>KANYE_LEADER_ATLAS</IconAtlas>
</Set>
</Update>
 
Heres the error in the logs-

[236956.408] Database::XMLSerializer (XML/Leaders/CIV5Leader_Kanye.xml): 'Row' or 'Delete' expected, got 'Where'.
[236956.689] constraint failed
 
You're not telling it which table to update, and if that's the entire file you're missing the closing </GameData> tag as well

And this is no longer about adding sounds, but bugs in your mod, so can you start a new thread in the main forum. And if you're still having problems, attach the zipped built mod and not just post snippets of files
 
Back
Top Bottom