Wav files can be used for sound effects in FRB. Wav files, which are uncompressed, are used because compression can introduce latency (delay before the sound plays).
The FRB Editor can use .wav files to create two types of objects:
SoundEffect
SoundEffectInstance
By default .wav files are loaded as a SoundEffect, which is the simplest object to work with. The SoundEffect object allows fire-and-forget sound effects. Once a .wav file is added to FRB, the SoundEffect it creates can be used with a Play call as shown in the following code:
Once a SoundEffect Play call is made, the sound cannot be modified. It will play to completion and then stop. By contrast, SoundEffectInstances are single-instance sounds which can be played, and manipulated after playing. For example, the following code plays a sound, but then adjusts its volume after 0.5 seconds:
To change whether a .wav file is loaded as a SoundEffect or SoundEffectInstance, change its RuntimeType as shown in the following image:
To add a .wav file to FRB:
Right-click on a Screen or Entity's Files item
Select Add File->Existing File
Navigate to the location of the .wav that you would like to use and click OK
You should see the .wav file in your project:
Alternatively you can drop WAV files into your project from Windows Explorer:
Open your project in the FRB Editor
Locate the WAV file you would like to use on disk
Drag+drop the file from Windows Explorer into your project in the desired Files folder. Note that if the file is not already a child of your Content folder, the file will be copied to the desired folder and the original file will be left on disk in its original location.
Once a .wav file has been added to your FRB project, your Screen, Entity, or GlobalContent includes an instance of a SoundEffect in generated code.
The following example assumes a file named GunShotSound.wav, so the code instance is named GunShotSound. The following code can be added to CustomActivity to play the sound when the space bar is pressed:
For the full SoundEffect documentation, see the MonoGame SoundEffect page.
For more information on SoundEffect in FlatRedBall, see the SoundEffect page.
FlatRedBall MonoGame requires WAV files to be built and loaded from XNB files. XNB files are built by the MonoGame content pipeline. This happens automatically when a WAV file is added to your FlatRedBall project, and will also happen if the WAV file ever changes.
WAV files are added as XNB files to your Visual Studio project. For example, the following SoundEffectFile.wav is part of GameScreen:
This file is automatically added to your Visual Studio project by FlatRedBall, as shown in the following screenshot:
WAV files can be explicitly rebuilt in the FRB Editor by right-clicking on the file and selecting Rebuild Content Pipeline File (.xnb).
When the file is built, the output window displays information about the build so you can diagnose problems.