360 21.DataDrivenSoundPackLoadingandOrganization
Sound Event Instance
Count
Overlapped Events Occurrences of
Overlap
Bird_Chirp 5 Crickets,
Bird_Chirp
4, 2
Crickets 10 Bird_Chirp, Crick-
ets, Frogs
7, 6, 1
Frogs 5 Crickets, Frogs 5, 5
Table 21.3. Remaining sound events that need to be placed into sound packs.
ConstructingSoundPacks
Now that we have removed the streamed sound events from our original event
table, we can begin analyzing which audio files should be combined into sound
packs. Table 21.3 shows the remaining entries that we are going to analyze from
our original event table.
We must consider the following simple rules when determining which audio
files should be placed into a sound pack:
Sound events that overlap approximately two-thirds of the time are potential
candidates for having their audio files placed into the same sound pack. The
overlap count should be a high percentage both ways so that sound event A
overlaps with sound event B a high number of times, and vice versa. Other-
wise, we may end up with redundant audio data being loaded frequently for
one of the sound events.
All audio files used by a sound event should be placed into the same sound
pack.
The file size of a sound pack should not exceed the amount of available
sound RAM.
The ratio between the size of a sound event’s audio data and the file size of
the sound pack should closely match the percentage of event overlaps. For
instance, if we have a sound event whose audio data occupies 80 percent of a
sound pack’s file size, but is only used 10 percent of the time, then it should
be placed in its own sound pack.
Table 21.3 illustrates an interesting example. In this fictional sound map, we
have a cluster of frogs next to a single cricket. Therefore, we have all five frogs
21.4ConstructingandUsingSoundLoadingTriggers 361
next to each other (five occurrences of an overlap) and next to a single cricket
(five occurrences of an overlap with
Crickets) in our table. For the Crickets
entry, we have only a single cricket that was next to the frogs, so there is only
one instance of an overlap.
There were no instances of the
Bird_Chirp event overlapping with the
Frogs event, so we should put Bird_Chirp and Crickets into a single sound
pack and put
Frogs into a separate sound pack.
21.4ConstructingandUsingSoundLoadingTriggers
Now that the sound packs are created, we can take a further look at the sound
emitter data set and generate our sound pack loading triggers from it. For each
sound emitter, we create a sound loading trigger. Each sound loader has a refer-
ence to the sound pack that it is responsible for loading and a loading area. The
loading area is initially set to be the same size as the sound emitter’s audible dis-
tance. When the listener is within the loading area, the sound pack that it refer-
ences is loaded into memory, if it has not already been loaded.
We have to increase the size of the loading area depending on the bandwidth
of the storage media, the file size of the sound pack, the number of other
streamed resources taking place, and the maximum distance the listener can
move in a game tick. When generating these numbers for your media, you should
take into account the worst possible performance cases.
For example, if you have a minimum bandwidth of 1 MB/s (due to other sys-
tems accessing the media at the same time), a sound pack that is 2.5 MB in size,
and a listener having a maximum travel speed of 3 m/s, then you need to add a
minimum of 7.5 meters to the loading area size because it takes 2.5 seconds for
the data to load and the listener could travel 7.5 meters in that time.
We unload a sound pack when we find the listener is not within the area of a
sound loader referencing that sound pack.
OptimizingSoundLoaders
Not all sound emitters require a separate sound loader to be constructed for them.
Most sound emitters do not move, and so there are optimizations that can be
made by merging similar sound loaders that overlap.
If two or more sound loaders reference the same sound pack, don’t move,
and are overlapping, then they should be merged into a single sound loader. This
new sound loader must contain both of the original sound loading areas.
362 21.DataDrivenSoundPackLoadingandOrganization
OutofMemoryDetection
Now that we have our sound loading triggers created, we can check for sound
loaders that overlap. For an overlapping set of sound loaders, we can tally up the
memory used by the sound packs. If the memory used by several sound packs
exceeds the amount of available sound memory, then a warning can be generated
to direct the audio designer to investigate the section of the world that has been
flagged. He can then make changes to the sound events, such as removing the
number of audio files used by a sound event or reducing the quality of the audio
files in order to have that section of the game fit into memory.
LoadingSoundPacksWhileRunningtheGame
When the game is running, it needs to check the listener position each frame and
determine whether the listener has entered a sound loading area. Listing 21.1
shows pseudocode that handles the loading of sound packs.
mark_all_sound_packs_for_removal(m_loaded_sound_pack_list);
get_list_of_packs_needed(required_pack_list, m_listener_position);
/*
Iterate through all the loaded sound packs and retain
those which are in the required list.
*/
for (each required_pack in required_pack_list)
{
for (each loaded_pack in m_loaded_sound_pack_list)
{
if (loaded_pack == required_pack)
{
retain_sound_pack(loaded_pack);
remove_pack_from_required_list(required_pack);
break;
}
}
}
unload_sound_packs_not_retained(m_loaded_sound_pack_list);
21.5Conclusion 363
/*
Now all the sound packs remaining in the required_sound_packs
list are those which are not yet loaded.
*/
for (each required_pack in required_sound_pack_list)
{
load_sound_pack_and_add_to_loaded_list(required_pack);
}
Listing 21.1. Pseudocode for loading sound packs.
21.5Conclusion
While not all sound events can have their data packaged up by the process de-
scribed in this chapter, it still helps simplify the task of constructing and manag-
ing sound packs used by a game’s environment. Sound events that typically can’t
take advantage of this process are global sounds, such as the player being hit or a
projectile being fired, because they can occur at any time during a level.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.4.191