Very useful sound libary

Miscellaneous Forums/Blitz Showcase/Very useful sound libary

hello!
are you looking for a good sound libary?
here ya go:

Type Sound
	Field path$, snd, snd3d
End Type
Type Channel
	Field ch
End Type

Function InitSoundLib(path$)
CreateListener(Cam)
End Function

Function FreeSoundLib()
For snd.Sound = Each Sound
	If snd\snd Then FreeSound snd\snd
	If snd\snd3d Then FreeSound snd\snd3d
	Delete snd
Next
End Function

Function CreateSound(path$, ent = 0, volume_times = 1)
For snd.Sound = Each Sound
	If snd\path$ = path$ Then
		For i = 1 To volume_times
			ch.Channel = New Channel
			If ent Then ch\ch = EmitSound(snd\snd3d, ent) Else ch\ch = PlaySound(snd\snd)
		Next
		Return
	EndIf
Next
snd.Sound = New Sound
snd\path$ = path$
snd\snd = LoadSound(path$)
snd\snd3d = Load3DSound(path$)
CreateSound(path$)
End Function

Function UpdateSoundLib()
For ch.Channel = Each Channel
	If ChannelPlaying(ch\ch) = False Then
		Delete ch
	Else
	EndIf
Next
End Function


how it works:
you have to call createsound like that:
CreateSound("Sound\Test.wav")


within this command he loads the sound from your disk. when you play the sound again, he doesn't have to load it again, because it IS already in the RAM, so he just plays it from RAM.
this is practical because if you have got a complicated game, he doesnt have to load the sound of the last level while playing the first ;-)
and you dont have to make 20 values global and then load them apart!

so where's the actual library then...?

Lol, don't be mean grey ;)

Devils Child, (hmm, you stole my name...) This is quite a handy little thing really, but it's not a sound library, more of a sound organisation library or something :)

However, it looks like youre trying to have a "Double volume" feature that simply won't work, it will distort the speakers when using high quality sounds....


Also,

Function InitSoundLib(path$)
CreateListener(Cam)
End Function


perhaps should be

Function InitSoundLib(path$,Parent)
CreateListener(Parent)
End Function


sounds like you are very happy about this :(...

but for noobs: this is practicaly for your games, because you dont have to pre-load each sound!

I didn't mean to sound negative, however, my suggestions are an improvement for your code. :)

well, it will be updated during the next month(s), so you can change the volume by UpdateSoundLib() and so on...

I asked about the libray because CreateListener doesn't exist. I thought this was some kind of library wrapper (at a glance)

CreateListener doesn't exist


Think you might have the wrong flavour of Blitz in mind.

Creates a listener entity and returns its handle. Currently, only a single listener is supported.


Lol, Grey. its B3D :) it looked like you were being a meanie!!

oh I see I tried it in BMax and BPlus.

OK some advice, please post which Blitz the code is to be used with in future, thanks :-)