Code archives/Audio/Sound Managment (replacing playsound and emitsound)

This code has been declared by its author to be Public Domain code.

Download source code

Sound Managment (replacing playsound and emitsound) by Ziltch2002
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)
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(as\snd) Then 
      nosounds = false
      exit
    end if
  Next
  if nosounds then as.sample = new sample
  SoundVolume snd,vol
  
  If src_ent = 0 Then
    as\snd=PlaySound(snd)
  Else 
    as\snd=EmitSound(snd,src_ent)
  End If
  
;	debuglog snd +" = " +		as\snd
  return as\snd
		  
End Function

Comments

None.

Code Archives Forum