Using AudioSystem for the first time

Hello everybody:



    I am using AudioSystem for the first time, and the only way I have been able to make it work is by calling the update method in the AudioSystem when the application is being updated. The actual way I did it was the following.


                AudioTrack track = sys.createAudioTrack( file, false );
                sys.getEnvironmentalPool().addTrack( track );
                GameTaskQueueManager.getManager().getQueue( GameTaskQueue.UPDATE ).enqueue( new Callable<Object>()
                {
                    public Object call() throws Exception
                    {
                        AudioSystem.getSystem().update();
                        GameTaskQueueManager.getManager().getQueue( GameTaskQueue.UPDATE ).enqueue( this );
                        //System.out.println( "


> Updating the audio system" );
                        return null;
                    }
                } );
                track.play();



I am aware that I could get rid of this overhead by simply incorporating the update call inside my main game loop, but this way is neat because I can do it from outside any example without messing with its internals...  :wink:

Anyway, my question is if this is actually the right way to do it (updating every frame) or there is a better/preferred way around I am not aware of. An also, as a minor question, is this queuing scheme OK from the technical point of view, and only the performance might be a problem?

Thanks,

Yes, the sound system needs to be updated as the application runs.  I've done it two ways…  One is by including the update in my game update loop and  the other is having a separate update thread that fires off as needed (200ms or so seems to work well.)



Your method would work as well, but will have a certain amount of overhead for the queue.

Thanks Renanse, I will look deeper into AudioSystem and let you know my findings :slight_smile: