Code archives/Audio/Sound libary
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
hello! are you looking for a good sound libary? here ya go: 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! | |||||
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 |
Comments
| ||
"when you play the sound again, he doesn't have to load it again" - But Blitz3D doesn't do that. He only loads everytime IF you use PlayMusic(). When you use LoadSound it's tainted in the RAM so next time you play it there wouldn't be a slowdown such as Playmusic has (that's also why I convert all my music into WAVs or MP3s, to load them with LoadSound as not to have Blitz3D loading them everytime and causing that HD slowdown in your game. And you have more control over when to play it or not). |
Code Archives Forum