XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Audio memory and CPU usage problems

Last post 04-23-2008 11:54 PM by Joel Martinez. 1 replies.
  • 04-23-2008 8:11 PM

    Audio memory and CPU usage problems

    I am having problem with my in game audio.  I have an audio class which has the capabilities to search for an audio file and add it, play it, pause it, unpause it, and stop it.  The problem I am having is that every time I try to play the sound in my game is that each time a sound file is played it takes up more memory and CPU usage.  I am only able to get this memory back by ending the application.  After playing my game for a few minutes the game it usually slows to a halt and often times crashes because the sound is consuming so many resources.

    Here is my audio class, if anyone has any ideas on changes I can make I would be grateful:

    http://xna.multigan.com/pastebin/?page=view&id=1208996292
  • 04-23-2008 11:54 PM In reply to

    Re: Audio memory and CPU usage problems

    I'll start by saying that your usage of Cues is very inneficient.  Generally speaking, you want to be careful with keeping instances of Cues.  If you need to be able to play/pause, that's fine, but if you just need to play the sound, use the PlayCue method.  Otherwise, you will need to manually dispose of the Cue once you are done with it every time.

    In your code, when you add a sound, you use the GetCue method to get an instance of the Cue, then you store it in a list.  Then, to play the sound, you loop through to find the instance using the "name" ... and then once found, you use the Cue instance's name to call PlayCue. 

    A better approach would be to simply call PlayCue when you need to play a sound.  If you really really need to pause/unpause (and I would really analyse your situation to see if you really do need that functionality), then add specific functionality.  Like, if it's for background music ... add a StartMusic method that gets the cue and stores it in a class level variable.  Then, you can say pause/stop music ... and when it's done, you can dispose of the Cue instance.

    hope that helps :-)

    Joel Martinez
    Blog: http://codecube.net
    Play Videos on an XNA Texture: Scurvy Media
Page 1 of 1 (2 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG