I’m getting into sound effects in my 3079 game – I read over the “Hello Audio” document, and I was concerned about performance. I have lots of “actors” running around that could be playing lots of different sounds, and I didn’t want every creation of an “actor” object to re-read audio data from the hard drive when rebuilding all of the possible AudioNodes. So, I created a function that loaded a bunch of AudioData objects from getAssetManager().loadAudio() calls (to be run once during initialization). However, in creation of an AudioNode, I need an “AudioKey”… I couldn’t find anything in the audio documentation about AudioKeys other than “The audio key that was used to load the AudioData” – but getAssetManager().loadAudio() doesn’t return any “key” data…
Am I just going about this the wrong way?
Yeah, you do The assetManager never reloads assets unnecessarily. You can assetManager.loadModel(“myModel.j3o”) all day and the model will only be loaded once, same for audio. Only exception is when you explicitly set the audio to streaming mode. And what you wanted to do is basically [java]AudioData = assetManager.loadAsset(new AudioKey(‘audio/myfile.ogg’)); [/java]
[java]AudioData = (AudioData)assetManager.loadAsset(‘audio/myfile.ogg’);[/java]
works just as well.
Using the SDK you can actually save the AudioNodes as j3o too, or directly attach sound effects to models and save them along with the model…
Hrm… if I want to move all audio loading to my game’s initialization, is this what I need to do?
loadedSoundsKey = new AudioKey(“Sounds/assaultrifle.ogg”);
loadedSoundsData = Main.myApp.getAssetManager().loadAudio(loadedSoundsKey);
… then later, when I create my Actor:
AudioNode newANode = new AudioNode(loadedSoundsKey, loadedSoundsData);
You could do that but as I just said, the assetManager buffers the data, so you only need to load it once, not even save a reference. Then later just load the AudioData from the assetManager by name.
Ahh, thanks for the reply. If you guys already do caching, then I don’t really need to do all this