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");

But there is no such function like:


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;

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

  • \$\begingroup\$ What's wrong with storing one variable holding the volume? \$\endgroup\$ – The Communist Duck Jun 5 '11 at 16:53
  • 1
    \$\begingroup\$ @Duck the problem is the inital value. What value will that be? Crappy API IMHO \$\endgroup\$ – Maik Semder Jun 5 '11 at 16:56
  • \$\begingroup\$ @Maik Semder I assume it would be 0. \$\endgroup\$ – The Communist Duck Jun 5 '11 at 17:19
  • \$\begingroup\$ @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. \$\endgroup\$ – Maik Semder Jun 5 '11 at 17:26
  • \$\begingroup\$ 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. \$\endgroup\$ – michael.bartnett Jun 6 '11 at 5:30

I think you can get volume from category, beacouse various sound in this category can have various volumes. When you set volume for category, you set the same for all.


I suspect what you are trying to implement is a slider control in your game that allows the user to select the SFX volume and the Music volume independently.

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).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.