Sound level change during game

Hello everyone.
I am new to all this.

I made a puzzle. Everything is working ok but i discover some flauds and i am trying to fix them.

The audio i have on my app are:
1.Background music that plays (on loop) as long as the app is working
2.Success sound for each correct piece placement
3.Another sound that discribes the image of the puzzle after its completion.

The No3 audio is too low. Is there a way to boost the sound of these files or do i have to re-record them or edit them with (e.g) audacity?

Another thing that would be great is when the puzzle is completed, the background music to lower its volume (not pause) so that sound No3 would sound clearer and louder. After the sound No3 is done i want the background music to volume up back to its previous volume. Is there a command that does that on Lua?

I have not set any of the above to a specific channel or something similar. [import]uid: 180974 topic_id: 35643 reply_id: 335643[/import]

Hi @alexander1756,
You can adjust the volume of any sound channel using the “audio.setVolume” command. To make your music and #2 sounds more quiet (in comparison to #3), you could take them down in volume while keeping #3 at a higher level. If that isn’t practical, then you might need to re-record and boost the core volume of #3.
http://docs.coronalabs.com/api/library/audio/setVolume.html

For the music fade, that is easily done using the “audio.fade” command. This lets you fade a channel from one volume to another volume.
http://docs.coronalabs.com/api/library/audio/fade.html

If you have other audio questions, check out the audio library APIs here:
http://docs.coronalabs.com/api/library/audio/index.html

Hope this helps,
Brent [import]uid: 200026 topic_id: 35643 reply_id: 141711[/import]

Thank you very much Brent. It sure did help me a lot.

I managed to fade the background music at the time the puzzle is completed.
My problem now is the one mentioned in the fade “Gotchas”. Now that my music is faded i can’t turn it back to the original volume.

I use the audio.setVolume command but it doesn’t do the trick.

Perhaps it doesn’t “understand” which sound i want it to volume up.
In the brackets of audio.setVolume can i declare the sound i want it to volume up?
I tried it but no luck. My syntax was :

audio.setVolume( music, 1)

Where “music” is the name of the background music i am using.
Am i using it with the wrong syntax?

If you want i can post my functions code to see where i might be wrong.
One more thing. In the audio.setVolume documentary it says:
“volume (required)
Number. The new volume level you want to apply. Valid numbers range from 0.0 to 1.0, where 1.0 is the maximum value.”

As i was messing around on corona sdk simulator, i set it to numbers above 1.0 and instead of “crushing” it showed to be working and it actually boosted the sound very much. Is it possible to have the same result when istalled on a smartphone? [import]uid: 180974 topic_id: 35643 reply_id: 141724[/import]

Hi @alexander1756,

Always happy to help. Just like the “audio.fade” command, “audio.setVolume” either sets the “master” volume, or the volume on a specific CHANNEL. If you look in the documentation: “Omitting this parameter entirely sets the master volume which is different than the channel volume. All channel volumes are scaled by the master volume.”

It’s a bit confusing at first, but the audio APIs work on either a specific channel OR a “handle”. This is by design. Sometimes you will want to set the volume on specific channel(s) where different sound file(s) play upon, so you want to change the volume for that entire channel, versus setting it for every sound that might play on the channel.

So, in your code, it looks like you were attempting to set (reset) the volume on a specific *handle* (music), but you need to reset the volume on the channel it’s playing on.

Brent [import]uid: 200026 topic_id: 35643 reply_id: 141814[/import]

i have tried a few stuff but i didn’t manage to make it work so i will copy my code here in case you notice something i am missing.
local function Animation()
audio.fade({ channel=0, time=1000, volume=0.1 } )
audio.play(win,{onComplete = function() audio.play(speech) end})
system.vibrate()

local t = 800
local function scaleZero()
transition.to(word,{time = t, xScale = 1, yScale = 1})
end
transition.to(word,{time = t, xScale = 1.2, yScale = 1.2,onComplete = scaleZero})

end

winTimer = timer.performWithDelay(1000, Animation)
print(“Nikisame!!!”)
counter = 0
solved[thisPuzzleImage] = true --??? ??? ??? ?? ??? ???
audio.setVolume( 1.0, { channel=0 } )
end
The ones in bold are the changes i am trying to make.
Since i have not set my background music to any channel, i also tried the same two commands without the “{ channel=0 }” but still got the same result. The music is succesfully fading but it isn’t getting back to normal again after my animations finish. [import]uid: 180974 topic_id: 35643 reply_id: 141974[/import]

Hi @alexander1756,
To save confusion later, I would suggest doing the following:

  1. “reserve” a few channels from the start, maybe 4 channels.
  2. assuming you have just one channel for music, assign that to channel 1, and always play it there.
  3. fade and set volume specifically on the music channel, not on “all channels” or the master volume.
  4. allow sounds to play automatically on any of the un-reserved channels; and to adjust the volume on those (as in, the user has a volume control from the menu of the game or something), loop through those un-reserved channels to explicitly set the volume on them.

What this basically does is give you a dedicated music channel, a few “spare” channels, in case you want to play another sound or song over-top that’s independent of the user-set volume, and then around 28 free channels to play your sounds on.

Give this a try and let me know if it works,
Brent [import]uid: 200026 topic_id: 35643 reply_id: 141978[/import]

Hi @alexander1756,
You can adjust the volume of any sound channel using the “audio.setVolume” command. To make your music and #2 sounds more quiet (in comparison to #3), you could take them down in volume while keeping #3 at a higher level. If that isn’t practical, then you might need to re-record and boost the core volume of #3.
http://docs.coronalabs.com/api/library/audio/setVolume.html

For the music fade, that is easily done using the “audio.fade” command. This lets you fade a channel from one volume to another volume.
http://docs.coronalabs.com/api/library/audio/fade.html

If you have other audio questions, check out the audio library APIs here:
http://docs.coronalabs.com/api/library/audio/index.html

Hope this helps,
Brent [import]uid: 200026 topic_id: 35643 reply_id: 141711[/import]

Thank you very much Brent. It sure did help me a lot.

I managed to fade the background music at the time the puzzle is completed.
My problem now is the one mentioned in the fade “Gotchas”. Now that my music is faded i can’t turn it back to the original volume.

I use the audio.setVolume command but it doesn’t do the trick.

Perhaps it doesn’t “understand” which sound i want it to volume up.
In the brackets of audio.setVolume can i declare the sound i want it to volume up?
I tried it but no luck. My syntax was :

audio.setVolume( music, 1)

Where “music” is the name of the background music i am using.
Am i using it with the wrong syntax?

If you want i can post my functions code to see where i might be wrong.
One more thing. In the audio.setVolume documentary it says:
“volume (required)
Number. The new volume level you want to apply. Valid numbers range from 0.0 to 1.0, where 1.0 is the maximum value.”

As i was messing around on corona sdk simulator, i set it to numbers above 1.0 and instead of “crushing” it showed to be working and it actually boosted the sound very much. Is it possible to have the same result when istalled on a smartphone? [import]uid: 180974 topic_id: 35643 reply_id: 141724[/import]

Hi @alexander1756,

Always happy to help. Just like the “audio.fade” command, “audio.setVolume” either sets the “master” volume, or the volume on a specific CHANNEL. If you look in the documentation: “Omitting this parameter entirely sets the master volume which is different than the channel volume. All channel volumes are scaled by the master volume.”

It’s a bit confusing at first, but the audio APIs work on either a specific channel OR a “handle”. This is by design. Sometimes you will want to set the volume on specific channel(s) where different sound file(s) play upon, so you want to change the volume for that entire channel, versus setting it for every sound that might play on the channel.

So, in your code, it looks like you were attempting to set (reset) the volume on a specific *handle* (music), but you need to reset the volume on the channel it’s playing on.

Brent [import]uid: 200026 topic_id: 35643 reply_id: 141814[/import]

i have tried a few stuff but i didn’t manage to make it work so i will copy my code here in case you notice something i am missing.
local function Animation()
audio.fade({ channel=0, time=1000, volume=0.1 } )
audio.play(win,{onComplete = function() audio.play(speech) end})
system.vibrate()

local t = 800
local function scaleZero()
transition.to(word,{time = t, xScale = 1, yScale = 1})
end
transition.to(word,{time = t, xScale = 1.2, yScale = 1.2,onComplete = scaleZero})

end

winTimer = timer.performWithDelay(1000, Animation)
print(“Nikisame!!!”)
counter = 0
solved[thisPuzzleImage] = true --??? ??? ??? ?? ??? ???
audio.setVolume( 1.0, { channel=0 } )
end
The ones in bold are the changes i am trying to make.
Since i have not set my background music to any channel, i also tried the same two commands without the “{ channel=0 }” but still got the same result. The music is succesfully fading but it isn’t getting back to normal again after my animations finish. [import]uid: 180974 topic_id: 35643 reply_id: 141974[/import]

Hi @alexander1756,
To save confusion later, I would suggest doing the following:

  1. “reserve” a few channels from the start, maybe 4 channels.
  2. assuming you have just one channel for music, assign that to channel 1, and always play it there.
  3. fade and set volume specifically on the music channel, not on “all channels” or the master volume.
  4. allow sounds to play automatically on any of the un-reserved channels; and to adjust the volume on those (as in, the user has a volume control from the menu of the game or something), loop through those un-reserved channels to explicitly set the volume on them.

What this basically does is give you a dedicated music channel, a few “spare” channels, in case you want to play another sound or song over-top that’s independent of the user-set volume, and then around 28 free channels to play your sounds on.

Give this a try and let me know if it works,
Brent [import]uid: 200026 topic_id: 35643 reply_id: 141978[/import]