21.4ConstructingandUsingSoundLoadingTriggers 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.4ConstructingandUsingSoundLoadingTriggers
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.