# Sounds categories volume level in xna

I am preparing sounds system to my game in xna. I am using XACT Tools, and i got problem.

There is class SoundCategory. I can change sound level for all sounds in that category easily.

SoundCategory category = engine.GetCategory("music");
category.SetVolume(float_value);


But there is no such function like:

category.AddVolume(float_value);


Which would increase or deacrease that value. There is also no function that get current volume so i can do thing like:

float vol = category.Add(float_value);
vol += 0.1;
category.SetVolume(vol);


Is there some clever way to achive what i want without creating some additional variables which keep current volume for all sounds categories ?

• What's wrong with storing one variable holding the volume? – The Communist Duck Jun 5 '11 at 16:53
• @Duck the problem is the inital value. What value will that be? Crappy API IMHO – Maik Semder Jun 5 '11 at 16:56
• @Maik Semder I assume it would be 0. – The Communist Duck Jun 5 '11 at 17:19
• @Duck that means the sound-designer can't set that value in its sound-project, or if s/he does anyway, the values are out of sync. – Maik Semder Jun 5 '11 at 17:26
• It IS a crappy API. This might be out of scope for what Skotnik wants. But what I would do is make sure that I've got a hold of the .XAP and parse that for initial settings of everything that isn't available in the api. You could make a pre-build step that parses the XAP and pulls out relevant information into an XML file then add that to the Content project so you can deserialize it into an AudioCategoryInfo object or something. – michael.bartnett Jun 6 '11 at 5:30

Assuming that's the case, whatever volume the user picks IS the value you set in .SetVolume(float); For example, every time the Music Volume slider changes, it changes a float variable from 0.0 to 1.0 and at that time, you call .SetVolume(sliderValue); If you are trying to implement an Up/Down volume control which moves in increments, you don't need to add .05f to the current sound, you need to always know what it was before (storing the volume value outside the SoundCategory).