How sound.xml Files Work

User avatar
FL2070
Posts: 245
Joined: Tue Sep 22, 2015 4:48 pm
Location: Earth

How sound.xml Files Work

Postby FL2070 » Thu Nov 26, 2015 1:30 am

You'll see I have posted multiple sound packs for different aircraft on the old forum and on this one. Modesty aside, I have a bit of experience, and I thought I'd share it with y'all people. Here goes nothing...

DISCLAIMER: This tutorial assumes you are proficient in the syntax of XML and have some basic understanding of how it works, and how the FlightGear property system works. If you are not proficient with these things, this tutorial will be of little to no use to you.

PART ONE: DEFINING A SOUND.XML FILE

Under FlightGear/data/Aircraft/(aircraft name), you will see a file called (aircraft name)-main.xml, which will look something like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>

<PropertyList>
   <sim>
      <author>Mr. Generic (model), Mr. Example (FDM), FL2070 (sound)</author>
      <status>aircraft development status</status>
      <flight-model>fdm type</flight-model>

      <model>
      etc.


The sound.xml path is defined here, and will look like this:

Code: Select all

<PropertyList>
   <sim>
      <sound>
         <path>Aircraft/717/Sounds/717-sound.xml</path> <!-- this is what you want. -->
      </sound>
   </sim>
</PropertyList>


Now as you can see, the 717 already has a sound.xml defined under Aircraft/717/Sounds/717-sound.xml. For your aircraft, you can call it what ever you like (e.g. donkey.xml), but you should probably stick to something intuitive like sound.xml or <insert aircraft name here>-sounds.xml. Remember: your <sound> open and close tags should be under <PropertyList> -> <sim>

Now that you have your sound.xml file set, it's time to move on to actually programming it.

PART TWO: ADDING YOUR FIRST SOUND

Here's where it gets really fun. You're about to dive into the complex, incredibly frustrating world of making sounds for aircraft. First of all, make your sound.xml, e.g. under Aircraft/ExampleAircraftFolder/sounds/sounds.xml or whatever you called it in part one - then add the bare minimum requirements for a sound.xml file, which is where you start:

Code: Select all

<PropertyList>
   <fx>
   </fx>
</PropertyList>


Note: Not <sim>, but <fx>. The <fx> tag means anything in here will be interpreted as the declaration of a new sound.

Okay, now that you have that done, it's time to make whatever plane actually sound like something. You'll need to define a new sound by adding this under <fx>:

Code: Select all

<anything alphanumeric can be put here no spaces>
   <path>Aircraft/example/sounds/example_wav_file.wav</path>
   <mode>looped</mode>
   <property>engines/engine[0]/n1</property>
</anything alphanumeric can be put here but no spaces>


The <path> tag is what sound file you're using. That means that our example sound.xml will look for a sound called example_wav_file.wav under the directory Aircraft/example/sounds. Second of all, the <mode> tag is how your sound is played. There are three <mode>s in FlightGear 3.4, which is the version I'm using. The three <mode<s are:

once: once means the sound will be played once and only once, every time your <property> exceeds 0.
looped: looped means this sound will loop forever, but only when your <property> exceeds 0.
in-transit: in-transit means the sound will loop forever, but only when your <property> is changing.

Note: You can find different properties by opening the property browser in-game with the forward slash key. Use the property browser to navigate to engines, then engine[0] (It's a zero-based index. engine[0] is engine 1 in human-speak, engine[1] is engine 2, etc), and find the n1 property. If your engine isn't started, your n1 will be 0, unless your plane uses rpm instead of n1.

Another Note: FlightGear will only accept sounds in wav format to the extent of my knowledge.

If you've been following the tutorial, you've just created a sound that will play if the engine 1's N1 is greater than 0, because of the <property>, it will loop forever, because of the <mode>, and can be found here: data/Aircraft/example/sounds/example_wav_file.wav because of the <path>, if you made a sound by that name.

PART THREE: <volume>

So let's say you have done all the stuff from part two, now you can make your sounds change according to different properties with the knowledge contained in part three. Let's go to what we have so far and add a <volume> tag to it, and add some new stuff.

Code: Select all

<example>
   <path>Aircraft/example/sounds/example_wav_file.wav</path>
   <mode>looped</mode>
   <property>engines/engine[0]/n1</property>
   <volume>
      <property>engines/engine[0]/n1</property>
      <factor>0.01</factor>
      <offset>0</offset>
      <min>0</min>
      <max>1</max>
   </volume>
</example>


I just introduced a second usage of <property>, and also <factor>, <offset>, and <min>/<max>. Their functions are as follows:

property: This property will be the input for the sound, eg engines/engine[0]/n1, the sound will play at a volume equal to the property, with the property equal to 1 being the sound playing at its base volume.
factor: The factor is how much you multiply the property by to get the final value. 100 * 0.01 is 1, and thus the sound will play at 1x volume at 100% N1.
offset: It is, as you might guess, an offset (aka addition). The offset is processed after the value, so if the N1 is 100%, the factor is 0.01, and the offset is 1, 100 * 0.01 = 1, 1 + 1 = 2, so the sound will play at 2x volume.
min/max: The absolute minimum and maximum levels. IMPORTANT: min and max are processed before the offset. This is a very important factor in a lot of my older sound packs, as you can do this:

Code: Select all

<property>example_property_ranging_from_0_to_2</property>
<factor>1</factor>
<offset>-1</offset>
<min>1</min>
<max>2</max>


and since the offset is added after min and max are processed, say the property is 2: 2 * 1 = 2, within min and max, 2 - 1 = 1, so it will play at 1x volume. If the property is 0: 0 * 1 = 0, min is 1, so 1, and 1 - 1 = 0. If the property is 1, 1 * 1 = 1, min 1, so 1, and 1 - 1 is 0. This is very important. If the property slowly increases to 2, you won't hear the sound at all until the property is more than 1. And thus, the sound fades, but only if the property is more than one!

PART THREE: <pitch>

Pitch works much the same as volume, but it cannon exceed 2. Here's how pitch works: A sound is a wave that can go up and down.

Image

The closer together the ups and downs are, the higher the pitch is. This is what pitch does in FG. If the pitch is one, the sound will play at its normal speed (1.0 pitch), and the wave's ups and downs will be the same distance apart, resulting in the same pitch. If the sound is played at pitch 2.0, it plays twice as fast, and the ups and downs in the wave will be half as far apart. If it is played at pitch 0.5, the ups and downs will be twice as far apart, resulting in a much lower pitch.

Here is an example of pitch code:

Code: Select all

<pitch>
   <property>engines/engine[0]/n1</property>
   <factor>0.01</factor>
   <offset>0</offset>
<pitch>


Now, there's a few very important things here. First, the property. It's engine 0's N1. Next, the factor. All jet engines max out at around 100% N1, and hence the factor 0.01. When 100 is multiplied by 0.01, you get one, and therefore the sound will play at pitch 1.0 when the engine is at full. Third, <pitch> uses an offset of 1.0 if you don't put your own offset in - so if you have this code:

Code: Select all

<pitch>
   <property>engines/engine[0]/n1</property>
   <factor>0.01</factor>
<pitch>


The calculation goes as such: 100% N1 * 0.01 = 1.0 pitch. Then the default offset (1) is added, and 1 + 1 = 2, which means your sound will play at a much higher pitch when the offset is not set, compared to when it's set at 0. This is very important to remember as I have often forgot to set a pitch offset of 0 when I needed to.

PART FOUR: <condition>

Conditions are very useful, but not absolutely needed all the time. They block the sound from playing if any of the properties in the condition clause are false, or not more than 0. Here is an example of condition:

Code: Select all

<condition>
   <property>engines/engine[0]/cranking</property>
   <not>
      <property>engines/engine[0]/out-of-fuel</property>
   </not>
   <or>
      <greater-than>
         <property>sim/example[0]/prop</property>
         <value>6</value>
      </greater-than>
      <less-than>
         <property>sim/example[1]/prop</property>
         <value>9</value>
      </less-than>
      <and>
         <equals>
            <property>sim/example[2]/prop</property>
            <value>123</value>
         </equals>
         <equals>
            <property>sim/example[3]prop</property>
            <value>123</value>
         </equals>
      </and>
   </or>
</condition>


There are lots of things in here, so let's go over all of them! First of all, not. <not> is fairly obvious, it takes whether the property or clause inside the <not> is true or false, and returns the opposite of that. Second, <or>, which is also fairly obvious. It returns true if any of the properties inside it return true. There's <greater-than> and <less-than>, which are just as obvious as the other ones. <greater-than> returns true if the <property> is greater than the <value>, and <less-than> returns true if the <property> is less than the <value>. <and> returns true only if everything inside it is true. Equals returns true if the <property> is equal to the <value>.

Overview: the condition will be true if the engine is cranking, and if it's not out of fuel, and if example[0]/prop is more than 6, example[1]/prop is less than 9, or if example[2]/prop and example[3]/prop are both equal to 123. Hopefully when you make your own conditions, they'll be simpler.

That's pretty much everything I know about <condition>.

PART FIVE: Property Rules

To be written.
Last edited by FL2070 on Sun Feb 05, 2017 2:59 am, edited 9 times in total.
Soundpack requests are currently: ON HOLD
Current WIP: B737NG (cfm56-7b)
See and download all my work: HERE

User avatar
jwocky
Site Admin
Posts: 1807
Joined: Sat Sep 12, 2015 12:04 pm
Contact:

Re: Editing Sounds! (how to do it)

Postby jwocky » Thu Nov 26, 2015 11:00 am

Nice! And a good idea to document knowledge for others.
Free speech can never be achieved by dictatorial measures!

User avatar
IAHM-COL
Posts: 5632
Joined: Sat Sep 12, 2015 3:43 pm
Location: Homey, NV (KXTA) - U.S.A
Contact:

Re: Editing Sounds! (how to do it)

Postby IAHM-COL » Sat Apr 23, 2016 1:12 am

Continue here : viewtopic.php?f=15&t=416
R.M.S.
If we gave everybody in the World free software today, but we failed to teach them about the four freedoms, five years from now, would they still have it? Probably not, because if they don’t recognise their freedoms, they’ll let their freedoms fall

User avatar
FL2070
Posts: 245
Joined: Tue Sep 22, 2015 4:48 pm
Location: Earth

Re: Editing Sounds! (how to do it)

Postby FL2070 » Wed May 11, 2016 1:49 am

Updated documentation on <pitch> and <condition>.
Soundpack requests are currently: ON HOLD
Current WIP: B737NG (cfm56-7b)
See and download all my work: HERE


Return to “Sound”

Who is online

Users browsing this forum: No registered users and 1 guest