Load Sound in Memory (FBSound 1.2)

General FreeBASIC programming questions.
Post Reply
amegas999
Posts: 2
Joined: Feb 25, 2020 20:24

Load Sound in Memory (FBSound 1.2)

Post by amegas999 »

Hi All!
I want to use FBsoud 1.2.
Is it possible, to load all sound in Memery and play them from different Subs? If yes, i would be very thankful for an example. Excuse my poor english. Regards
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Load Sound in Memory (FBSound 1.2)

Post by D.J.Peters »

What a funny question :-)
All sounds are played from memory loaded before.

Joshy
amegas999
Posts: 2
Joined: Feb 25, 2020 20:24

Re: Load Sound in Memory (FBSound 1.2)

Post by amegas999 »

I'm sorry that the question is stupid...
I know that this is possible:
Load Sound (in memory)
Play Sound
My question was, if this is possible:
Main:
Load Sound A
Load Sound B
Load Sound C
Sub X:
Play Sound A
SubY:
Play Sound B
Play Sound C

or should i do this:

SubX:
Load Sound A
Pay Sound A
SubY:
Load Sound B
Load Sound C
Play Sound B
Play Sound C
?
Again im sorry, if this is a stupid question, my coding-skills are not so high and i never used sound librarys. I used MCISendString but there is a delayproblem, with RealTek Soundchips.
@Joshy: Thank you, for all your great work,
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Load Sound in Memory (FBSound 1.2)

Post by D.J.Peters »

Yes load all sounds you need and than play it in any order or together or looped or ...

Joshy
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Load Sound in Memory (FBSound 1.2)

Post by badidea »

amegas999 wrote: ...
My question was, if this is possible:
...
or should i do this:
...
Both are possible.

Your question is not so much about fbsound, but more about how to access memory or variables from subroutines. What may complicate understanding is that fbsound uses ID's (integers) to access the memory (sounds / waves) instead of via pointers directly.

Here is one of many ways to do what you ask:
For fbsound 1.1, I will install and try fbsound 1.2 later

Code: Select all

'Replace the 2 lines below with your own magic code to get fbsound working
#include "fbsound-1.1/inc/fbsound_dynamic.bi"
fbs_Set_PlugPath("fbsound-1.1/") 

function fbs_Get_SoundPlaying(byval hSound as integer) as boolean
	dim as integer nLoops
	if fbs_Get_SoundLoops(hSound, @nLoops) = false then return false
	return iif(nLoops, true, false)
end function

'~ Main:
if fbs_Init() = 0 then
	print "fbs_Init(): Error: " & FBS_Get_PlugError()
	sleep 1000 : end -1
else
	print "fbs_Init(): Ok"
end if

dim as string fileName
'The easy way: with global variables
dim shared as integer hWaveA, hWaveB, hWaveC
dim shared as integer hSoundA, hSoundB, hSoundC

'~ Load Sound A
fileName = "Ford_model_T.wav"
if fbs_Load_WAVFile(fileName, @hWaveA) = 0 then
	print "fbs_Load_WAVFile: Error: " + fileName
	sleep 1000 : end -1
else
	print "fbs_Load_WAVFile: Ok: " + fileName
	fbs_Create_Sound(hWaveA, @hSoundA)
end if

'~ Load Sound B
fileName = "OOGAhorn.wav"
if fbs_Load_WAVFile(fileName, @hWaveB) = 0 then
	print "fbs_Load_WAVFile: Error: " + fileName
	sleep 1000 : end -1
else
	print "fbs_Load_WAVFile: Ok: " + fileName
	fbs_Create_Sound(hWaveB, @hSoundB)
end if

'~ Load Sound C
fileName = "car-breaking-skid-01.wav"
if fbs_Load_WAVFile(fileName, @hWaveC) = 0 then
	print "fbs_Load_WAVFile: Error: " + fileName
	sleep 1000 : end -1
else
	print "fbs_Load_WAVFile: Ok: " + fileName
	fbs_Create_Sound(hWaveC, @hSoundC)
end if

sub X
	print "fbs_Play_Sound(hSoundA)"
	fbs_Play_Sound(hSoundA)
	while fbs_Get_SoundPlaying(hSoundA)
		sleep 10
	wend
end sub

sub Y
	print "fbs_Play_Sound(hSoundB)"
	fbs_Play_Sound(hSoundB)
	print "fbs_Play_Sound(hSoundC)"
	fbs_Play_Sound(hSoundC)
	while fbs_Get_SoundPlaying(hSoundC) or fbs_Get_SoundPlaying(hSoundB)
		sleep 10
	wend
end sub

X 'play wave/sound A and wait to fishing playing
Y 'play wave/sound B & C and wait for both to finish

print "End"
The 3 waves are here: https://nr100.home.xs4all.nl/badidea/car_sounds/
Stolen from https://freesound.org/ but I hope that no one will notice that.
Post Reply