SoundVol vs ChannelVol

Blitz3D Forums/Blitz3D Beginners Area/SoundVol vs ChannelVol

Drekinn(Posted 2005) [#1]
The battle continues...
I still haven't fully figured out the bewildering intricacies of SoundVolume and ChannelVolume. I would be grateful for any help with the following:

1) After pausing a sound with PauseChannel and then setting a new volume with ChannelVolume the sound continues playing at this new volume when resumed with ResumeChannel. However, the next time the sound plays the volume has reverted back to its previous volume setting. (Looped sounds work fine, as they do not stop.)
I assume the specified channel volume is supposed to remain in effect until the program ends?? Why are my channel volumes reverting?? Do I need to set the channel volume every time a sound is played??

2) I tried the same thing using SoundVolume but the new volume setting only takes effect AFTER the sound has finished playing. Am I right in thinking that ChannelVolume is only to be used WHILE a sound is playing?

3) In order to set the volume for all my sounds to a similar level I've used SoundVolume to set the base volume for each sound when my program first begins. When it comes time to change the overall volume level for my program though (by means of a slider bar), setting the new volume level is quite tricky as each sound has a different maximum volume. Is the best way to approach this problem just to use a sound editing program to set each sound's volume to a similar level in the first place? Doing this via code was my ambition.
I was told once that the value set with SoundVolume represented the maximum ChannelVolume for that sound (eg. SoundVolume = .3 -> ChannelVolume = 1 (.3 in actuality)). Tests seem to reveal that this is not true. This would have made things a lot easier.

4) When a program starts I assume the default sound/channel volume value for any sound is 1?

5) Is it possible to display a system alert dialog box like with RuntimeError but without it terminating the program? I just want a message to be displayed and then to return to the program upon clicking 'Ok'.

6) I've seen code examples with EndGraphics being executed before End. Is this necessary?

7) How do I go about setting and creating my own system file icons?


Phew! That's a lot off my mind. Any assistance with the above would be greatly appreciated.


doctorskully(Posted 2005) [#2]
Here's what I know:

SoundVolume sets the volume for the ENTIRE program, not just one channel. For example, setting the SoundVolume to .5 will mean that each channel's volume, when set at 1, will be .5. (When set at .5, it will be .25). ChannelVolume must be set for EACH NEW CHANNEL. This confuses a lot of people. When you do this:

channel=Playsound(mysound)
If Not ChannelPlaying(channel)
channel=Playsound(mysound)
EndIf

When the channel isn't playing, it's completed its job and doesn't exist anymore. However, the really strange memory access number still exists, and ChannelPlaying checks to see if the channel with that number is still hanging around. When you use Playsound again, you're creating a NEW channel. Remember, "channel" isn't a channel; it's just a variable (just as image=Loadimage("whatever.bmp") doesn't mean that "image" is an image). So, the new channel created in the third line has to get its volume set too.

Yes, you are correct that the default of everything is 1. I think.

The RunTimeError stops the program, and the only possible way that you could do what you wanted to do in #5 is learn DirectX and create a new function in the UserLibs. (How, I don't know; my first language is Blitz.)

Putting EndGraphics before End isn't needed, as far as I can tell. It's the equivalant of putting ClearWorld before End in a 3D program. However, I am 99% sure that End (or just the Close button) will clear out the graphics as well. I haven't had any problems with neglecting the EndGraphics, and the AvailVidMem() doesn't change no matter how many times I run the program.

As for question #7, icons have been talked about on the forums for a while now; try searching. There are apparently programs on the Internet that'll create icons for you. (Never done it myself, so I couldn't tell you exactly how.)

Hope this helps!


HappyCat(Posted 2005) [#3]
SoundVolume - sets the volume of the sound before it is played - affects every time that sound is played thereafter.

ChannelVolume - sets the volume of a playing sound and only that one instance of the sound.

The final volume that you'll hear the sound at is SoundVolume * ChannelVolume.

---

Edit: I use SoundVolume to balance my sound effects as they're loaded, then to set the overall volume for my game I use a function called PlaySoundEffect which sets the ChannelVolume of the new sound to the game volume level straight after playing. For looping sound, I wrap them in a type, so that I can find their channel to change the ChannelVolume if the player changes the volume mid-game.


Drekinn(Posted 2005) [#4]
Thanks for your help guys. I think I understand ChannelVol better now. I was unaware that a channel becomes lost after each use. So that means I -do- have to set the channel volume every time the sound plays.

Deep Thought,
setting the SoundVolume to .5 will mean that each channel's volume, when set at 1, will be .5. (When set at .5, it will be .25)

I've done numerous tests on this issue and found that volumes set with ChannelVolume can indeed exceed the supposedly maximum volume set with SoundVolume.
I'm thinking that the volume of a channel the first time it is used (without changes to channel volume) matches the value set with SoundVolume.

Thanks again for the help.


Damien Sturdy(Posted 2005) [#5]
A little more info

when you "playsound", the command returns a new channel each time. each sound does not have a static channel located to it.

chennelvolume can be used to change the volume of a channel while a sound is playing. I used it in my "synth" system.

Soundvolume actually halves the volume of an actual sound rather than its channel, Because its effecting the sound and not the channel, you wont hear the change immediately.