Game assets like sounds are usually best managed if preloaded in advance. You don't want the user to experience a delay in the sound effects every time a sound has to be loaded.
You should implement a ResourceCache
helper that manages game resources for you. Then things like sounds could be preloaded at each level start and unloaded when the level ends. This is a very good approach if your game is not huge.
// This class will probably be a singleton, so I made the methods 'static'.
class ResourceCache {
// Call when level loads
public static void PreloadResource(string resourceName);
// Call when level ends
public static void UnloadAllResources();
// Find a previously loaded resource
public static Resource FindResourceByName(string resourceName);
}
Then in the level load section:
void LoadLevel()
{
ResourceCache.PreloadResource("foo.mp3");
ResourceCache.PreloadResource("bar.mp3");
...
}
Now anywhere in the game, you can:
// No loading is done, just a cache/map lookup.
// "bar.mp3" was loaded at level start by PreloadResource().
Resource barSound = ResourceCache.FindResourceByName("bar.mp3");
And when a level ends, you can clear the resource cache:
ResourceCache.UnloadAllResources();
The cache should eventually use some management policy like LRU to handle scenarios when you want to load more data than what can fit into memory. Then the cache can evict old resources to make room for new ones. If you have the cache interface in place, adding a "real" caching scheme becomes very easy.