Sound commands

Blitz3D Forums/Blitz3D Beginners Area/Sound commands

Drekinn(Posted 2005) [#1]
Greetings all,

I've been having troubles understanding the Blitz3D sound command set. Any assistance would be appreciated.

1) If two or more sounds are played in the same channel, subsequent channel commands only affect the last sound that was played in that channel, resulting in the earlier sounds continuing to play without being able to stop them! (ie. if looped) Why don't the channel commands affect all sounds currently playing in the specified channel?? What then is the point of having separate Sound and Channel commands for seemingly the same purpose? (Eg. SoundVolume vs ChannelVolume, SoundPitch vs ChannelPitch, SoundPan vs ChannelPan etc.)

With other programs, playing a second sound in a channel that is already playing a sound would cut short the first sound and take new precedence of that channel. Is this not so in Blitz? Do I need to create a new channel for each sound I want to manipulate?

2) Is there a command to find out the normal pitch a of sound?

3) Is it possible to set the overall volume level of the whole program?

4) How do I unloop a sound previously looped with the LoopSound command?


If someone could please explain the intricacies of Blitz sound (especially with a demo) I would be grateful.

Thanks.


WolRon(Posted 2005) [#2]
1. All sounds played are assigned their own channels. The Channel commands only affect the channel specified. IIRC, the Sound commands affect all sounds (don't quote me on this though...).

2. Not to my knowledge. But if you know what it is beforehand, you can certainly alter it.

3. SoundVolume

4. AFAIK, you can't. I think the intent was to set up a sound as looping or non-looping indefinitely. If you are attempting to only loop a sound a finite amount of times, then do something like this:
sound = LoadSound("asound.wav")
channel = PlaySound sound
Repeat
  If Not ChannelPlaying(channel)
    channel = PlaySound sound
    loops = loops + 1
  EndIf
Until loops = 5



Drekinn(Posted 2005) [#3]
Wolron,

1,2) Not true. SoundVolume only affects the specified sound (as do the other Sound~ commands). So I'm still none-the-wiser as to the purpose of the separate Sound~ and Channel~ commands. Anyone?


Rob Farley(Posted 2005) [#4]
I think, athough I could be wrong:

Sound volume sets the volume for that sound so if you've got a loud sound that you want to balance with your other sounds you can set it's volume to .5 say. Then it's channel volume will be from 0 - 1 which in reality go from 0 - .5. Also you can use a sound twice, so if you have say a bang noise you might want to use the sound "Bang" at a high volume and a low volume therefore these would be channel volumes and not sound volumes.


_PJ_(Posted 2005) [#5]
You need to set SoundVolume for EACH sound. You can use a variable and set the soun volume for each sound to the variable, however, of course different sounds are 'recorded' at different levels too.

The separate channels are required for giving more control. So that you cna affect the volume While a channel is playing, STOP a loop-ed sound (LoopSound) etc.

hope this helps


WolRon(Posted 2005) [#6]
Not true. SoundVolume only affects the specified sound (as do the other Sound~ commands).
Oh, well then perhaps you could explain this straight from the docs:

ChannelVolume channel_handle, volume#
Parameters
channel_handle = variable assigned to the channel when played
volume# = volume level floating value between 0 and 1

Description
While SoundVolume happily changes the volume of the entire program, this command will let you adjust volume rates on a 'per channel' basis. Extremely useful.

The volume value is a floating point value between 0 and 1 (0 = silence, .5 = half volume, 1= full volume). You can do other cool stuff like ChannelPitch and ChannelPan too!




Drekinn(Posted 2005) [#7]
Rob,
Thanks for the helpful feedback. Nicely explained.

Malice,
Ah thank you for clearing that up. ie. the Channel commands can be applied -while- the sound is playing. Understood!

WolRon,
I wish I could explain. Look at the info for the SoundVolume command:

SoundVolume sound_variable,volume#
Parameters
sound_variable = any valid sound variable previously created with the LoadSound command.
volume# = floating point number from 0 (silence) to 1 (full volume)

Description
Alter the playback volume of your sound effect with this command. This command uses a floating point number from 0 to 1 to control the volume level.


As you can see there's no mention of this command controlling the volume of the entire program, which it doesn't anyway. This is confirmed by the reference to a specific sound within the command's syntax.

Unfortunately the documentation for this and many other commands seem to have been typed up in a couple of seconds, without proof reading. Either that or cut and pasted from other commands with minor alterations.

I surely hope the docs for BlitzMax have been given the attention they deserve.


Drekinn(Posted 2005) [#8]
5) By the way, is there an easy way to set the volume level of the entire program, or do I have to set the volume of each loaded sound individually with SoundVolume?

6) The sounds in my program seem to be playing at differing volumes each time they play! I have used the SoundVolume command to set the volume levels for each sound, but this is before the main program loop, with no other changes to volume levels during the program. Why are these volume jumps occuring?? Please help! :(


WolRon(Posted 2005) [#9]
5. Wish I knew...

6. Can't really say. You may have to post some code in order for us to figure it out.


_PJ_(Posted 2005) [#10]
Hmm dunno about 5

as for 6 - Are you referring to the sounds directly or are you using channels.

Bear in mind if you change a Channel's volume, the next sound placed in that channel will maintain that same volume, I believe. Plus after 'so many' channels, they will be re-used, so a particular sound may overwrite into a channel already used.

Not 100%, more of a guess as to what's happening....


Drekinn(Posted 2005) [#11]
WolRon, Malice,

To narrow down the problem I reduced my code to its simplest state, ie. just loading the sound into a variable with LoadSound outside the main program loop (with no alterations to sound volume etc.) and then within the program loop played the sound using PlaySound (with reference to a channel) every time the mouse was clicked. The same sudden jumps in volume still occurred!
So no idea what's going on there. Anyone know?

I am happy to announce though that by executing StopChannel with reference to the channel in question just before playing the sound seems to fix the volume jump problem. Hooray!

I'd still like to know why these volume jumps occur though.

Malice,
Hmm.. if your 'channels are re-used and overwritten' theory holds true then that would most likely be the reason for my troubles as I am sometimes using hundreds of channels at any one time.
How many sound channels are available to Blitz?


_PJ_(Posted 2005) [#12]
I would think the number of channels available would be limited by your sound-card or chip.

The same may in fact be the reason for the jumps etc.

What hardware are you running for sound and have you got the latest drivers?

---
Im not sure about this, but it's just a logical step to eradicate possibilities.


Yan(Posted 2005) [#13]
I seem to remember Mark adding the ability to use up to 1024 channels simultaneously (fairly recently). AFAIK FMOD mixes the channels down internally.


For the global volume, you could use something like:
Global g_snd_volume# = 0.5
...
chn = MyPlaySound(bang, 0.5)
...
End

Function MyPlaySound(snd, vol#=1)
 Local chn
 
 If g_snd_volume = 0 Then Return
 
 chn = PlaySound(snd)
 ChannelVolume chn, vol# * g_snd_volume#

 Return chn
end Function

Function MyChannelVolume(chn, vol#)
  If chn then ChannelVolume chn, vol# * g_snd_volume#
End Function
Or did you mean more of a 'normalising' type of affair?


Rob Farley(Posted 2005) [#14]
Definately go the route of creating your own sound control library. For example in the Alien Breed code I've written a sound control library that sets the volume and pan based on where you are and where the sound is. Also this will take into account global volume settings etc.


Drekinn(Posted 2005) [#15]
Malice,
I'm using a Sound Blaster Live! card. Guess I could check if there's a more recent driver out there.

Neville,
1024? Wow, that's reassuring to know. Thanks also for the global volume code.

Rob,
Sounds great (no pun intended). I've never delved into libraries before. How do I go about creating my own? Where can I find more info about libraries in general?

Thanks all,