sound volume

Blitz3D Forums/Blitz3D Programming/sound volume

barryem(Posted 2004) [#1]
I want to have an engine sound vary with speed and attitude, etc and I've loaded an engine sound and used loopsound and playsound and it's playing okay but soundvolume and soundpitch and channelvolume and channelpitch don't seem to have any effect.

I'm not sure if I should be using the sound or channel commands for one thing. I wish the docs were clearer on that.

I have three global variables at the start of the program; sndEngine, chnEngine and engineVolume. All are specifically declared as global. I then set the value of engineVolume to 0.5. Then, inside a function I change the value of engineVolume but that doesnt seem to take. Since the variable is global I would assume it's still in scope inside the function. Is that not correct? But debuglog shows it to be 0.

I've tried every combination I can think but nothing works. Does anyone have any ideas?

Thanks,
Barry


jfk EO-11110(Posted 2004) [#2]
Not sure if I entirely understood you Question.

Of course, alligning a new Value to the Variable EngineVolume does in no way automaticly alter the Volume of the engines soundchannel. Instead you need to set the Volume using the Commands "ChannelVolume" every time you want to alter the Volume etc.

Always use the PlaySound Command with a Return Value:

(example)

snd_handle=LoadSound("ding.wav")
LoopSound snd_handle
...
channel=PlaySound(snd_handle)
ChannelVolume channel, 0.5
ChannelPitch channel, 22050


ICECAP(Posted 2004) [#3]
Yes, jfk is right, but to put it more simply in the game loop just put:

ChannelVolume chnEngine, engineVolume


That should work then.


barryem(Posted 2004) [#4]
Sorry if I wasn't clear. I'm already doing what you suggest and it doesn't seem to have any effect.

I start the volume at 0.5 at the start of the program. That seems to be working. Then in the loop I add 0.1 to the volume variable and issue the channelvolume command again. Or the soundvolume command. I've tried both. Nothing happens. Debuglog shows me the value of that variable is 0 but the sound keeps on going.

Barry


John Blackledge(Posted 2004) [#5]
Make sure your channel variables are held as globals - a simple one, but it caught me out.


GfK(Posted 2004) [#6]
JFK is right. Post some code, you're probably doing something wrong somewhere.


VIP3R(Posted 2004) [#7]
Just a thought, have you declared your volume and pitch variables as floating point with '#'? (i.e. Global engvolume#=0.5)

If you haven't then the variable will be an integer and will have no effect when you alter it by fractional amounts. This will also explain why the debug shows zero values.


barryem(Posted 2004) [#8]
The program is too large and spread out to post easily. It's basically the xfighter demo program that I used as a starting point to build on.

I'll play with it some more and if I can't get anywhere I'll post some parts of it.

Thanks,
Barry


barryem(Posted 2004) [#9]
> Just a thought, have you declared your volume and pitch
> variables as floating point with '#'? (i.e. Global
> engvolume#=0.5)

That was the problem. As soon as I read your post I remembered reading that variables default to integer but I had forgotten.

Thanks for paying attention. It's working fine now.

Barry


VIP3R(Posted 2004) [#10]
Your welcome :)

It's caught me out a couple of times too.