Sound Channel Problem

Blitz3D Forums/Blitz3D Beginners Area/Sound Channel Problem

Steve Elliott(Posted 2004) [#1]
Has anybody got any *simple* code for over coming the problem of multiple sounds playing at the same time?

I've seen (and used) code several pages long which contains half a dozen functions - but to me this seems too inefficient.

As long as the same sound doesn't get played again and again - like an explosion say, that would great.

I thought this would be a simple matter, but identifying a unique sound like a laser of the same sound sample - but coming from 5 points (playing simultaineously) seems quite tricky.

Thanks


smilertoo(Posted 2004) [#2]
keep a list of available sounds and flag each sound thats being played, dont play it again until its flagged as not currently in use.


Neo Genesis10(Posted 2004) [#3]
Best done, IMO, by using types. You can create each type when the sounds are played and delete them when finished. You could start up several tunes at the same time (well, quick succession in actuality) and just remove them when finished.


GfK(Posted 2004) [#4]
I use this sort of method - ensures that no more than 5 explosions (0-4) can be playing at once. If it reaches a point where explosions are playing on all 5 'channels' (elements of the Explosion array), then the oldest one is stopped. Funny, took longer to explain it than it did to write the code that does it. :)
Dim Explosion%(4)
Global ExplosionPtr%

Function PlayExplosion()
  ExplosionPtr = ExplosionPtr + 1
  If ExplosionPtr > 4 Then ExplosionPtr = 0
  If ChannelPlaying(Explosion(ExplosionPtr))
    StopChannel Explosion(ExplosionPtr)
  EndIf
  Explosion(ExplosionPtr) = PlaySound(sndExplosion)
End Function



Steve Elliott(Posted 2004) [#5]
Thanks. Gfk, that's a neat peice of code - I guess I over complicate things at times when coding. ;-)