Sound Channel volume inconsistency

Blitz3D Forums/Blitz3D Programming/Sound Channel volume inconsistency

Drackbolt(Posted 2005) [#1]
Hi everyone!

I've researched this and I'm not sure what the problem is... I'm using channels to playback multiple sound effects in an RTS game, but when too many guns are firing at once, the sounds start drifting in an out. It seems like I can't successfully get more than three or four sounds to play at once without losing global volume or losing sounds altogether. I'm not modifying volume levels for sounds or channels directly in any way. Aside from this, my code is doing what it is supposed to do. Is this a limitation of my sound card (Realtek AC97)? Thanks,

Jesse


Damien Sturdy(Posted 2005) [#2]
There are a few causes.

The Main one i can think of is this:

Sound1+Sound1=sound1 at twice the volume
sound1+sound1+sound1+sound1=sound1 at 4x the volume

If you play a sound many times on top of each other, They will distort and eventually you will hear nothing.

The sound Could be phasing.

Sound1+inverted sound1=no sound.


umm... Hard to describe.... The second theory wont tend to happen anyway.


VP(Posted 2005) [#3]
Sound levels are a strange thing. We humans hear loudness on a logarithmic scale.

Layering sounds on top of each other in a game can be quite problematic. Either play a few sounds loudly, or many sounds quietly. Of course, playing everything quietly is not really the best option.

If I were you, I would add some code to lower the volume of all channels as more and more sounds are playing simultaneously. With the right weightings, you will still be tricked into believing that as in-game action increases, overall sound volume does also, even though everything overall remains quite level.

**EDIT**

Hmm... better explain how Blitz is playing sounds.

Sound1 plays at full volume, and it sounds perfect.

Sound1+Sound2 both play at full volume, sound distorts because the sounds are 'added' together, summing their waveforms and creating an overly-loud (and now clipped) output waveform.


What should happen, but doesn't, is that sound1+sound2 when played together have their waveforms mixed (add them together and divide amplitude by 2). This overlays one sound on the other with no increase in volume. Has a side effect that when you play 2 exact same sounds out of phase, you get... well... phasing :) Sounds like a weird whooshing sound.

Sounds great in a club when you're on acid with 2 records playing in phase, but I digress! (don't do drugs, they're bad and I'm joking, okay?).


IPete2(Posted 2005) [#4]
Do mono sounds phase? If not, you could make all the sound files into mono (not stereo) and thus solve the problem??? Maybe???


IPete2.


Jams(Posted 2005) [#5]
" Do mono sounds phase?"

Yeah they suffer from the same problem.

Perhaps there's some userlib out there that can let b3d interface with onboard DSP? so you could (on some soundcards) activate an on-board compressor?


Ross C(Posted 2005) [#6]
Or, you could manually control the volume. Keep track of how many sounds are playing, and adjust the channel volumes manually :o)


Drackbolt(Posted 2005) [#7]
First of all, thanks a lot for all the replies... Very helpful. Great community here.

I should give a bit more detail. All the sounds are mono, in wave format. I have an array of sound channels set up so that when a new sound is requested, it receives its own channel and has its pitch altered appropriately. The problem has more to do with losing volume and sounds altogether than anything else. If two or three are playing, they sound beautiful. If four or five are playing, they're all barely audible. If more than that are playing the volume of the game goes completely dead until a less "busy" time. I don't know why I'm running into this... I can't imagine it would be an uncommon problem unless I'm doing something wrong in particular. If I have to, it wouldn't be too hard to add a control routine for the volume based on quantity of waves, but I don't see the results as being all that smooth. Thanks again for all your help.


octothorpe(Posted 2005) [#8]
Can you create a small program to demonstrate the problem?


Ross C(Posted 2005) [#9]
Sounds like the sound waves cancelling each other out or amplifying till there not audible...


John Blackledge(Posted 2005) [#10]
If more than that are playing the volume of the game goes completely dead until a less "busy" time

This is a bit of a giveaway - I suspect a WIndows/system timesharing deficiency.


Drackbolt(Posted 2005) [#11]
Well, here's the code for my "playsound" function. It calls an array of sound channels, which call an array of sounds. Let me know if anything looks amiss.

For a = 0 To 99
If ChannelPlaying(rSoundChannel(a)) = 0 ;if channel not in use
Select fvSound
Case 1,2,3,4,5,6,7,8,9,10,11 ;weaponfire
rSoundChannel(a) = PlaySound(rFiresound(fvSound))
ChannelPitch rSoundChannel(a),30000
End Select
Exit
EndIf
Next

I've tested this out, and it's iterating properly. I have also had the time to test it on other computers, and they all had the same problem. Please help!


Sledge(Posted 2005) [#12]
The fact that you seem to want to entertain the playback of 100 samples simultaneously at full volume looks amiss.

Consider maybe 5 channels instead, pumping through samples at 20% of their full volume. You could have a channel for explosions, one for fire, another for alerts etc; and once an explosion (for example) with a higher priority than the one that is already playing is requested, then the old one simply has to shut up.


skidracer(Posted 2005) [#13]
The simplest fix I would guess is to play every gun shot at a slightly different frequency.


Drackbolt(Posted 2005) [#14]
I first tried 8 channels, and then went down to 4, without any difference in the problem. I then read in this forum somewhere that you could have up to 1024, so I figured why not and went to 100. It didn't make a difference anyway. No system seems capable of playing more than 3 at once without drastic reduction in volume.

Having only one channel for sound effects of a given type is fine for music, but not for combat... I was really hoping to avoid going that route. Any suggestions or more info anybody?


Sledge(Posted 2005) [#15]

Having only one channel for sound effects of a given type is fine for music, but not for combat... I was really hoping to avoid going that route.



You already said it yourself (I think) - you could keep track of how much stuff is going on and lower/raise the volume of each channel as and when it's needed. It just takes more cycles to manage than the more simplistic method I suggested. Realistically, though, your players aren't going to be able to discern 100 noises at once (and audio is there to communicate what is going on, remember, and help the player react to circumstances) and if all you need is a cacophony of gunfire then 5-10 dedicated channels for that purpose will probably suffice.


Drackbolt(Posted 2005) [#16]
I guess what's confusing is that multiple sound effects would decrease the perceptible volume instead of increase it. Since everything defaults to a volume of 1, I can't increase the volume beyond that for individual sounds in Blitz. So, how would I go about increasing the volume for each sound when more are playing? I have no idea what ratios to use. I've tried starting all sound volumes at 0.1, then increasing by 0.1 per other sound playing, but that pattern still breaks down beyond four or five sounds at once. Unless anyone has any epiphanies here, I think I'm just going to end up going the single- or dual-channel route.


RGR(Posted 2005) [#17]
Maybe a stupid question: Are you shure all your variables used for Volume are floating point ?

Second guess: I noticed a sound problem only on one computer I had and could not fix the problem. One of my Blitz3D games that ran normal on every other system, played the sound at about 1/4 of the volume (distorted when I put the main volume in the sound panel) on this one computer. If I stopped the game and started new - everthing worked normal... obviously it had to do with the initialzing of the sound card - done wrong at first try. Driver update didn't fix it. Other games (Blitz or others) worked normal... wrong code should have had an effect on other computers as well...


lo-tekk(Posted 2007) [#18]
This thread is kinda old, but sadly not for me. I stumbled into exactly the same problem right now. Lowering the volume has no real effect. If i play 16 channels and set the volume to 1/16 each, i hear nothing anymore. Currently i have set a limit of 16 channels that can play simultaneously but that did not solve the problem of garbled or distorted sound. Maybe i get the channel-concept wrong.
Had anyone else this problem and how can it be solved ?