Tips for using custom sounds and music in
Operation Flashpoint

by toadlife



Introduction
So you've read all the tutorials and hacked it out yourself in notepad, or you've found a great program that put custom sounds, music and, radio messages in your OFP missions. You must be done then right? No way! Simply knowing how to put sounds in you mission is only half the battle. This tutorial addresess some of the common mistakes that are made when using sound in OFP, and gives some tips on using them more effectively.

This tutorial will often cite my mission Operation LoJack as an example. I would recommend downloading it and extract it using the tool "PBO Decryptor".





Common Mistakes made regarding sound in OFP


Improper Sample Rates/Bitrates


    Though many people today have fast net connections, there are still millions of people who don't (like ME). For those of us who have modems, donwloading a large mission is not desirable - especially when the mission is BETA and/or has not been reviewed. There is nothing more frustrating than downloading a 10MB mission, only to find out that the mission sucks and the download was a waste of time. Even missions that have rave reviews that are large are a pain to download. To increase the chances that people will download your mission, it important to "effeciently" encode your sounds and music. What I mean by "efficiently" is to make sure you use the lowest possible bitrate, while still maintaining an acceptable level of sound quality. The biggest mistake people make when incorporating sound into their OFP mission is larger bitrate than is neccessary.

My mission Operation Lojack contains thirty eight sounds, and one music track, yet the mission only weighs in at 4.8MB. The 38 sounds total only 1.8MB and the 3:52 music track is only 3MB.

What does "Bitrate" mean?
    Bitrate is the term used most when describing the quality of compressed audio (like mp3 and ogg). When encoding an uncompressed peice of audio into a compressed format the bitrate is how much data per second is alotted to represent the sample rate of the source file. With uncompressed audio, the sample rate directly coorolates with the bitrate, while with compressed audio different combinations of bitrate and sample rate can be used.  When encoding an audio file, the encoder will try and squeeze all of the frequencies stored into the audio file using the specified bitrate. An example of bitrate/sample rate comparison would be a typical music track taken from a CD, which has a sample rate of 44100hz (44.1khz). When encoding a file of this type, a bit rate of at least 64kbps per channel (In some cases higher is needed) would be needed to make a compressed file accurately represent the source file's sample rate (sound exactly like the original). If you try to encode a typical 44khz stereo wave file containing music at a low bitrate such as 64kbps (32kbps per channel), it will proably not sound very good.


What does "sample rate" mean?
     The sample rate of a peice of audio relates to how much of the frequency spectrum is contained per sample in the audio file. The higer the sample rate, the wider the range of frequencies will be stored in the audio file. With uncompressed audio (such as wave files), the sample rate directly corolates with the bit rate - The higher the sample rate is, the higher the bitrate will be. Consequently, an uncompressed audio file with a higher sample rate will sound more lifelike and be larger than one with a lower sample rate. The sample rate of a peice of audio should allways be set before encoding a peice of audio into a compressed format such as ogg, or mp3.

Below is a table showing various sample rates that are compatible with the .ogg format, along with their ideal bitrates, and examples of real world uses. These are numbers taken from my experience with compressed audio (I've been working with digital audio and digital audio compression for over 7 years). These are only guidelines, and not rules.

Sample rate (khz)
Ideal bitrates for encoding (Per Channel - Double these numbers for stereo files)*
Ideal for:
Real life comparisons
Notes
48000khz
96-160+
Music/Archival of raw recordings. (Good for recording from Vinyl records)
Vinyl Records/DAT recordings(Studio Master Tapes)
Usually only used for master studio recordings or in other professional settings
44100khz
64-128+
Music
Compact Discs
This is the format of the sound the comes on audio CD's you buy at the store
32000khz
56-64+
Music/Sound Effects
FM Radio
Usually Best in OFP
24000khz
48-56+
Music/Voices and Effects/Radio Transmissions
Just below FM Radio
Usually Best in OFP
16000khz
32+**
Voices and Effects
AM Radio
Usually Best in OFP
12000khz
32+**
Voice/Radio transmissions
Standard Telephones Very Low Quality
8000khz
32+** Voice/Radio transmissions Cell Phones/IP Voice Communication (Roger Wilco, Internet Phones)
Very Low Quality

* In many cases, lower bitrates can be used than recommended in the table above.
** Lower bitrates than 32kbps are supported in the some formats, but as of now the lowest bitrate the ogg format supports is 32kbps (16kbps per channel).



Improper sound levels


    The loudness, or softness of your sound is not just controlled when the sound is recorded. It is also controlled by the settings in your description.ext file. Sounds that are either too loud or too soft usually kill the atmosphere in a mission. This is a problem which can be easily remedied by making a few changes in your description.ext file.  The following snippet shows a portion of a description.ext file with the section which controlls the sound level colored red.
        class goodtoseeyou
            {
                                name = "goodtoseeyou";
                                sound[] = {"\sounds\blair\goodtoseeyou.ogg", db-60, 1};
                                titles[] = {0, $STRM_goodtoseeyou};
            };
"db" stands for decibel, which is a way of measuring level or volume of a sound. In order to make the sound louder you would just increase the number. In the above snippet the decibel level is set to -60 (negative sixty). The snippet below is the same sound with a higher decibel level.

        class goodtoseeyou
            {
                                name = "goodtoseeyou";
                                sound[] = {"\sounds\blair\goodtoseeyou.ogg", db-30, 1};
                                titles[] = {0, $STRM_goodtoseeyou};
            };

IMPORTANT: When testing your sound levels in the game make sure your sound, music, and radio levels are all set to the same level, regardless of what your personal preferences are.


Improper Implimentation/Usage of sounds


    When I say "improper usage", I don't mean that mission editors shouldn't use some sounds. I mean then sometimes don't utilize all of  OFP's abilities when it comes to sound usage. Here is a table of scripting commands that pertain to sounds in OFP, along with their official description and some notes by myself.

Scripting Command
Official Description
Notes
time fadeMusic volume
Operand types:
    time: Number
    volume: Number
Type of returned value:Nothing
Description:
    Smooth change in music volume. Change duration is given by time, target volume by volume. Default music volume is 0.5.

Example:
    5 fadeMusic 0
If the volume of the recording is very high, sometimes this will appear to not work very well.
time fadeSound volume
Operand types:
    time: Number
    volume: Number
Type of returned value:Nothing
Description:
Smooth change in all sounds volume. Change duration is given by time, target volume by volume. Default sounds volume is 1.0.

Example:
    5 fadeSound 0.1
If the volume of the recording is very high, sometimes this will appear to not work very well.
musicVolume
Type of returned value:Number
Description:
Check current music volume (set by setmusicvolume)
n/a
onBriefingGear sound
Operand types:
sound: String
Compatibility:Version 1.75 required.
Type of returned value:Nothing
Description:
Define sound (voice) played first time when section Gear in briefing is selected.

Example:
onBriefingGear "GearVoiceOver"
New Resistance Command.
onBriefingGroup sound
Operand types:
sound: String
Compatibility:Version 1.75 required.
Type of returned value:Nothing
Description:
Define sound (voice) played first time when section Group in briefing is selected.

Example:
onBriefingGroup "GroupVoiceOver"
New Resistance Command.
onBriefingNotes sound
Operand types:
sound: String
Compatibility:
Version 1.75 required.
Type of returned value:
Nothing
Description:
Define sound (voice) played first time when section Notes in briefing is selected.

Example:
onBriefingNotes "NotesVoiceOver"
New Resistance Command.
onBriefingPlan sound
Operand types:
   sound: String
Compatibility:Version 1.75 required.
Type of returned value:Nothing
Description:
Define sound (voice) played first time when section Plan in briefing is selected.

Example:
onBriefingPlan "PlanVoiceOver"
New Resistance Command.
playMusic name
Operand types:
name: String
Type of returned value:Nothing
Description:
Play music defined in description.ext.

Example:
playMusic "musicname"
Music will not appear to come from anywhere. It just plays on your speakers.
playMusic nameAndPos
Operand types:
nameAndPos: Array
Type of returned value:Nothing
Description:
Play music defined in description.ext. Format of nameAndPos is [name,position], position is in seconds.

Example:
playMusic ["Track13", 30]
For playing only certain parts of songs. Can give a mission a movie like feeling if used properly. Think of movies where a certain song is played througout the movie.
playSound name
Operand types:
name: String
Type of returned value:Nothing
Description:
Play sound defined in description.ext.

Example:
playSound "soundname"
Sound will not appear to come from anywhere. It just plays on your speakers.
unit say speechName
Operand types:
unit: Object
speechName: Array
Compatibility: Version 1.75 required.
Type of returned value:Nothing
Description:
Format of speechName is [sound, maxTitlesDistance]. Unit will play given sound. When unit is person, it will also pefrorm corresponding lipsync effect. If camera is not withing given range, title is not shown. Sound is defined in description.ext.
New Resistance Command.

Any object can say something. Even inanimate objects like rocks, and vehicles. Sound will stop immediately if the object saying it is destroyed.
unit say speechName Operand types:
unit: Object
speechName: String
Type of returned value:Nothing
Description:
Unit will play given sound. When unit is person, it will also pefrorm corresponding lipsync effect. Sound is defined in description.ext.

Example:
soldierOne say "speechId"
Any object can say something - even inanimate objects like rocks, and vehicles. Sound will stop immediately if the object saying it is destroyed.
setmusicvolume none - Syntax is probably:  setmusicvolume level

I would guess that the valid levels are from 0-1
Mentioned in the command ref but not listed.
setsoundvolume none - Syntax is probably: setsoundvolume level

I would guess that the valid levels are from 0-1
Mentioned in the command ref but not listed.
soundVolume
Type of returned value:Number
Description:
Check current sound volume (set by setsoundvolume)






Example sound usage scenarios in OFP mission editing


Using the "say" command on inanimate objects
    The say command can be used on more that people. Any object can say something. You can use the say command to simulate vehicles with stereos (car1 say "music"), and you make those little radios available in the mission editor appear to play music (Example: radio say "music"). By doing this the sound will appear to being coming from the object that says it, which makes the scenario more realistic.
    In my mission Operation LoJack, the group leader uses a tracking device that beeps. To simulate the beeping sound coming from the leader, I simply had the leader "say" the beeping sound. The effect of the sound coming from the leader was especially important in coop version, when other human players would hear the beep too. I of course, used no lip file for the beep, so the leader's lips did not move when the tracking device was on. Other examples from Operation LoJack where the say command is used on inanimate objects, are the alarm sound that goes off when the helicopet gets hit, and the litle radios by the campfires that play music in the intro and beggining of the mission.

Using the fadesound and fademusic commands
    The fadesound and fademusic commands should be used with regularity. They are great for the begginings and ends of missions/cuscenes. I use both of these commands at the beggining and end of my missions. Here are some sample scripts for beggining and endings.

;fade sound and screen in at beggining of mission/cutscene (best if put at the beggining of the init.sqs file)
0 fadesound 0
0 fademusic 0
titlecut["","black in", 10000000000]
10 fadesound 1
10 fademusic 1
titlecut["","black in", 10]


;fade sound and screen out at end of mission/cutscene (these three lines can be put into a trigger)
titlecut["","black out", 10]
10 fadesound 0
10 fademusic 0


    Fading music out can give a nice effect in cutscense, and during the mission.

More to come...