audio sounds volume doesn't decrease

Hi, when my function boumTest is active, it’s the sound of the function scoreSound that i hear. Why ?

normaly i have to ear the bumSound but it’s seems that the scoreSound is more important than the other… 

function scoreSound() piece = audio.loadSound( "piece.wav" ) audio.setVolume(0.01, { channel=piece}) piece = audio.play( piece ) end

function bumSound() bum = audio.loadSound("boum.mp3") audio.setVolume( 0.99, {channel=5}) bum = audio.play( bum ) end function boum() bumSound() local function boumtest (event) &nbsp; &nbsp; print (flagCircleonTransitionOnLife) &nbsp; &nbsp; if flagCircleonTransitionOnLife == true then&nbsp; print("CircleonTransition.x",CircleonTransition.x) &nbsp; &nbsp; if CircleonTransition.x \<= 80 then &nbsp; &nbsp; &nbsp; &nbsp; boum() &nbsp; &nbsp; end &nbsp; &nbsp; if CircleonTransition.x \>= 395 then &nbsp; &nbsp; &nbsp; &nbsp; boum() &nbsp; &nbsp; end end end Runtime:addEventListener("enterFrame", boumtest)

HI @espace3d,

FIRST NOTE: I highly recommend that you pre-load all sounds that you need for particular scene, especially if these sounds are longer than 1-2 seconds.

Now for the main issue:

  1. The problem is that you’re trying to set the volume on an audio handle before the audio plays. “audio.loadSound()” returns an audio handle, not a channel number, so you can’t set the volume on that (it’s not a channel number).

  2. I don’t think you should be using “piece” as a reference to both the audio handle and the playing audio (same for “bum”). Use distinct variables for each.

So basically, you need to follow this process:

  1. Load the sound… this returns an audio handle.

  2. Play that sound using the audio handle… this returns a channel number (or you can specify the channel yourself).

  3. Use the channel number to set the volume.

[lua]

– Pre-load your sounds before the scene starts, if possible

local pieceSound = audio.loadSound( “piece.wav” )

function scoreSound() --Note: you should avoid global functions and variables

   local piece = audio.play( pieceSound )

   audio.setVolume( 0.01, { channel=piece } )

end

[/lua]

Take care,

Brent

hi Brent,

Thanks for your advice this works . Have a nice day :)  

HI @espace3d,

FIRST NOTE: I highly recommend that you pre-load all sounds that you need for particular scene, especially if these sounds are longer than 1-2 seconds.

Now for the main issue:

  1. The problem is that you’re trying to set the volume on an audio handle before the audio plays. “audio.loadSound()” returns an audio handle, not a channel number, so you can’t set the volume on that (it’s not a channel number).

  2. I don’t think you should be using “piece” as a reference to both the audio handle and the playing audio (same for “bum”). Use distinct variables for each.

So basically, you need to follow this process:

  1. Load the sound… this returns an audio handle.

  2. Play that sound using the audio handle… this returns a channel number (or you can specify the channel yourself).

  3. Use the channel number to set the volume.

[lua]

– Pre-load your sounds before the scene starts, if possible

local pieceSound = audio.loadSound( “piece.wav” )

function scoreSound() --Note: you should avoid global functions and variables

   local piece = audio.play( pieceSound )

   audio.setVolume( 0.01, { channel=piece } )

end

[/lua]

Take care,

Brent

hi Brent,

Thanks for your advice this works . Have a nice day :)