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

Can I change the volume of individual sounds?

Last post 1/21/2009 1:30 PM by JasonD. 8 replies.
  • 7/24/2008 8:14 PM

    Can I change the volume of individual sounds?

    In the tutorial for changing the volume using XACT the volume is changed for an entire category, is this the only way of chaging the volume? Suppose I have a 2 second sound file which I want to play once at full volume and then again at half volume a second later, so that the sounds overlap and the first sound is not diminished when the second one enters. Is this possible without creating duplicate files?

    Another question; is it possible to adjust the pan of the sound playing directly and on the fly? Do I need to (ab)use the apply3d method to do this or is there a more direct way?

  • 7/24/2008 8:30 PM In reply to

    Re: Can I change the volume of individual sounds?

    You can use RPC presets to change the volume of individual sounds.  Also, if you have two sounds, one on the left channel, and one on the right, you can simulate panning by simply lowering the left and raising the right to pan right, etc.
    Joel Martinez - XNA MVP
    Blog: http://codecube.net
    XNA Unit Testing: Scurvy Test
  • 7/24/2008 8:56 PM In reply to

    Re: Can I change the volume of individual sounds?

    In XACT, create a new Variable.

    Call this Variable "Volume" and make it per-cue-instance. Set the range from -96 to +6.

    In XACT, create a new RPC.

    Call this RPC "VolumeVariation."

    Open this RPC, and select Volume as a variable, and make it drive the Sound Volume.

    Change the curve to be at -96 dB when Volume is -96, and +6 when Volume is +6.

    Now, right-click on your Sound, and select "Attach RPC" and select the VolumeVariation RPC.

     

    When using this sound at runtime, you can call SetVariable() on the Cue to change the Volume according to your curve -- -96 dB up to +6 dB.

     


    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 7/25/2008 3:34 PM In reply to

    Re: Can I change the volume of individual sounds?

    Excellent, thank you both for the help, I have pitch and volume working nicely now. I'm going to try this 3d malarky next.
  • 8/1/2008 6:59 PM In reply to

    Re: Can I change the volume of individual sounds?

    Great! But is there a way to make the same thing with pan? Thanks in advance.
  • 8/1/2008 10:15 PM In reply to

    Re: Can I change the volume of individual sounds?

    The only way to pan sounds in XACT is via the 3D audio functionality. Check out the "How To: Apply Basic 3D Positional Effects to a Cue" topic in the docs, and the 3D Audio sample on this site, for details.

    Once 3.0 is released, you could alternatively use the new SoundEffect API.


    XNA Framework Developer - blog - homepage
  • 1/20/2009 5:08 PM In reply to

    Re: Can I change the volume of individual sounds?

    jwatte, thanks for the information.

    Is there any way to play the same sound effect (i.e. same cue) multiple times simultaneously, while controlling the volume for the cue being used?  (Picture the firing sound of a space shooter where the sounds don't end before they are played yet again, because the firing is so rapid.)  It appears making a RPC variable for per-cue-instance forces the usage of myCue.Play() which doesn't like to be called multiple times even if the Limit Instances is turned off (or set to a very high number).  It returns InvalidOperationException.  I don't want to call Stop() then Play() each time, since it abruptly ends the sound effect.  Making multiple cues that all play the same sound effect seems like a hack...

    It looks like the only way is to continually create new Cue objects each time, so the old ones continue to play.
  • 1/21/2009 12:39 PM In reply to

    Re: Can I change the volume of individual sounds?

    It's not a hack. It's the way it works.

    The full name for an XACT Cue in the documentation is a "cue instance", and that's a clue as to how it's intended to be used: a cue in your code is an instance of the cue in the XACT project. I guess a parallel would be that each spaceship object in your game is an instance of the spaceship class: creating a new spaceship object isn't a waste, or a hack - it's how classes work. Likewise with cue instances.

    If your spaceship fires three laser blasts, you'll want three cues (cue instances) to play. Consider that each one could be played from a different point in space, with different volumes, parameters, etc... there's no way you can control three different things if you only have one thing available.
    Pandemonium, an occasionally updated blog about my game, XNA, games development, and the games industry; XapParse, a parser for XAP (XACT) files
  • 1/21/2009 1:30 PM In reply to

    Re: Can I change the volume of individual sounds?

    Andy, of course you're absolutely right.  If I used the same cue, then I'd be changing the pitch & volume of the older instances still playing if it allowed me to restart it over as a new sound effect and left the old ones continuing to play.  I just wasn't thinking straight.  I was used to PlayCue() which does not return a cue, but it is called for each sound effect in my game that doesn't require run-time parameter changes... but it likely, behind the scenes, create a new Cue on each call anyway, I just don't see it.

    I was just worried that my I would have a messy array of Cue objects and have to deal with them all, and this sounded awfully like I was implementing sound effect instancing myself, when I thought that was XACT's job to do -- so it sounded like a hack.  However, I just reuse the same Cue variable (i.e. pointer) so I don't have a messy array.  Internally, I am creating a new Cue object each time, which is being assigned to the same variable (I don't have to deal with the old Cue objects, so it's ok to 'lose' them).  And I believe that XACT is still at work in the background limiting instances (I should test this just to be absolutely sure).

    Thanks.

Page 1 of 1 (9 items) Previous Next