[bb] Sound Managment (replacing playsound and emitsound) by Ziltch [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:42

Previous topic - Next topic

BlitzBot

Title : Sound Managment  (replacing playsound and emitsound)
Author : Ziltch
Posted : 1+ years ago

Description : Use this function instead of playsound and emitsound.
This should help manage your game sounds.

eg
  change   playsound(backtrack) to playsnd(backtrack)
  and      roar=emitsound(roar,lion) to roar=playsnd(roar,lion)

You can also set the samples volume using the vol parameter.

eg

  full volume   backingsample=playsnd(backtrack)
  half volume   backingsample=playsnd(backtrack,0,.5)


Code :
Code: blitzbasic
type sample
	field snd
end type

Function playsnd(snd,src_ent=0,vol#=1)
  nosounds = true
  If snd = 0 Then 
;   DebugLog "no sound to play"
    Return
  end if
  For as.sample = each sample
    If Not ChannelPlaying(assnd) Then 
      nosounds = false
      exit
    end if
  Next
  if nosounds then as.sample = new sample
  SoundVolume snd,vol
  
  If src_ent = 0 Then
    assnd=PlaySound(snd)
  Else 
    assnd=EmitSound(snd,src_ent)
  End If
  
;	debuglog snd +" = " +		assnd
  return assnd
		  
End Function


Comments : none...