fbsound 1.0 Win/Lin 32/64-bit (wav mp3 ogg mod it xm s3m)

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Post Reply
Rens
Posts: 256
Joined: Jul 06, 2005 21:09

Post by Rens »

Hello D.J. Peters,

After reading the conversation between you and redcrab talking about ticks in fbsound, i could hear them too and was searching for an answer to this.

The code:

Code: Select all

#libpath "./lib"
#include "./inc/fbsound.bi"
const plug_path = "./lib/"
const data_path = "./resources/"

' only if not same as exe path
fbs_Set_PlugPath(plug_path)

Dim As Integer         hWave,hSound
Dim As Single          w,wstep=pi2/44100.0*400
Dim As FBS_SAMPLE Ptr  lpSamples

fbs_Init(44100,1)
fbs_Create_Wave(44100,@hWave,@lpSamples)
For i As Integer=0 To 44099
  lpSamples[i]=Sin(w)*1000:w+=wstep
Next
screenres 512,512

dim as integer index=44100-256
line(0,255)-step(639,0),1
pset(0,lpSamples[index] shr 8),1
for x as integer=1 to 639
  index+=1
  if index<44100 then
    line -(x,256+lpSamples[index] *0.2),2
  else
    index mod=44100
    line -(x,256+lpSamples[index] *0.2),4
  end if
next  

fbs_Create_Sound(hWave,@hSound)
fbs_Play_Sound(hSound,-1) ' loop endless
? "playing clean sine wave for 5 seconds"
Sleep 5000
end
The ticks aren't random but i believe they occured at the start and then at every second. I can count six of them.

Can it be that the ticks occur when the samples are repeated, after one second?

Even more cleaner to hear this:

PS: Do'nt forget to lower the systems volume because if you do'nt then you may never hear any ticks any more!

Code: Select all

#libpath "./lib"
#include "./inc/fbsound.bi"
const plug_path = "./lib/"
const data_path = "./resources/"

' only if not same as exe path
fbs_Set_PlugPath(plug_path)

Dim As Integer         hWave,hSound
Dim As Single          w,wstep=pi2/44100.0*400
Dim As FBS_SAMPLE Ptr  lpSamples

fbs_Init(44100,1)
fbs_Create_Wave(44100,@hWave,@lpSamples)
For i As Integer=0 To 44099
  lpSamples[i]=Sin(w)*44100:w+=wstep
Next
fbs_Create_Sound(hWave,@hSound)
fbs_Play_Sound(hSound,-1) ' loop endless
? "playing clean sine wave for 5 seconds"
Sleep 5000
end
Is there any explanation for this?

I also have two questions about fbsound:

1) How to do crossfade between two sounds?
(Is it even possible to fade out a sound and fade in another sound at the same time?)

2) How to load one sound, play it, stop this sound, load another sound, play it and then stop that sound?

I think fbs_Set_SoundPaused() is'nt a good option for this. Neither do fbs_Stop(). But what is?

Please, correct me if i'm wrong.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

A question from a new thread:
darkhog wrote:How to stop currently playing sound without restarting FBSound subsystem? I hate to do this, since loading sounds (music in my case) takes up several seconds and I don't like to reload it when I just want to play other music.
darkhog
Posts: 132
Joined: Oct 05, 2011 21:19

Post by darkhog »

Rens wrote: PS: Do'nt forget to lower the systems volume because if you do'nt then you may never hear any ticks any more!
If that's the case and you don't hear it at notmal volume level, then that's a minor issue.

Also I'd like you to post answers to my question in my topic as I have e-mail notifications turned on for it (I could turn them on for this thread, but I don't want to be informed of every post in this thread, only ones related to my question).
Rens
Posts: 256
Joined: Jul 06, 2005 21:09

Post by Rens »

@darkhog

Huh, "answers to my question" ? I don't have answers, only questions!

The start of this topic is:
"This is the primary place for questions about the FBSound lib"

So now my question to you is: Are you trying to Πss me off? My post was for D.J. Peters.

And no more nitpicking about a few notifications please.
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Post by maddogg6 »

darkhog wrote:How to stop currently playing sound without restarting FBSound subsystem? I hate to do this, since loading sounds (music in my case) takes up several seconds and I don't like to reload it when I just want to play other music.
It looks like only 'MP3Streams' can be halted;
"_DF FBS_End_MP3Stream () as fbsboolean"

Last line in the fbsound.bi file of fbsound 03c that I have handy - so this may have changed.

It sort of makes sense to me, game sounds are in short uncompressed .wav files you can usually just let finish (this is usually demanded actually) and just stop creating new streams, but music is usually long and compressed as an MP3 - and there's a app fo... erm... a func to end those streams... so...

edit/
Additionally...
I recall DJPeters looking to keep the lib fast for doing realtime dsp stuff, adding a mechanism(s) to stop all streams may be the undoing of that goal... ???
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Post by maddogg6 »

1) How to do crossfade between two sounds?
(Is it even possible to fade out a sound and fade in another sound at the same time?)
It 'looks like' you; get all stream info, get the handle of the stream the mp3Stream is using (or remember it when creating the stream ??) - change its volume (decrease over time) while also creating a new stream who's vol is '0' and changing it's volume (increasing over time), then when the first streams vol hits '0' - halt that stream if its an mp3 - or let it finish at 0 volume if its a wav.
2) How to load one sound, play it, stop this sound, load another sound, play it and then stop that sound?
See my last post.

Disclaimer - I am just a passerby sharing what I 'think' I understand... I am in now way an expert on fbsound.. so... just sayin what I would attempt based on what I do know.. :)
darkhog
Posts: 132
Joined: Oct 05, 2011 21:19

Post by darkhog »

maddogg6 wrote:It sort of makes sense to me, game sounds are in short uncompressed .wav files you can usually just let finish (this is usually demanded actually) and just stop creating new streams, but music is usually long and compressed as an MP3 - and there's a app fo... erm... a func to end those streams... so...
I have nothing against wavs, just let OGG sounds to be stopped. MP3 is known to have some silence at beginning of file when you exporting via Audacity and it breaks music loops which works great with oggs. Also oggs have better compression with same quality.
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Post by maddogg6 »

darkhog wrote:I have nothing against wavs, just let OGG sounds to be stopped. MP3 is known to have some silence at beginning of file when you exporting via Audacity and it breaks music loops which works great with oggs. Also oggs have better compression with same quality.
Ahh.. audio loops - hmmmm....

Looks like you would;

Load 2 ogg files into memory;
Play ogg1 - and 'Optional you can create an hSound object too.'
- the sound object allows tou to change its stream properties in real time play/pause, volume, pan.

psudo code

set vol1 to max and vol2 to min;

start ogg1 stream (play wave and create sound object)
get play position of ogg1 steam
if = position to start crossfade
start ogg2 stream
if > position to crossfade
vol1 = vol1 - 1
vol2 = vol2 + 1
if vol1 = 0 then pause ogg1 stream; destroy ogg1 from memory

But..... I bet you export 'stereo' files from audacity - which will complicate that. I think you need to load each stereo channel as a separate stream to be played as sound object in FB sound instead of 'wave'.

Again, I am not an eggpurt or anything...
edit/
But I see;
functions: fbs_Create_Sound() and fbs_Play_Sound().

fbs_Create_Sound(hWave,@hSound) as FBSBOOLEAN
fbs_Play_Sound(hSound, [nLoops]) as FBSBOOLEAN
Create an hSound object hWave object with fbs_Create_Sound(). Start the hSound playback with fbs_Play_Sound()

The main difference between playing an hWave handle with fbs_Play_Wave() and playing an hSound handle with fbs_Play_Sound() is that you can change all properties of a playing hSound while it is playing/created/stopped or paused.
darkhog
Posts: 132
Joined: Oct 05, 2011 21:19

Post by darkhog »

Yeah, but that will make loading sounds even longer. In my game I have pretty long loop (over 5min., around 7 MB in OGG) and it loads over half minute. All I can do is write on screen "Loading sounds, please wait", I can't even make damn progress bar.
Converting to hsound will make loading even longer.
maddogg6
Posts: 824
Joined: Dec 07, 2005 22:58
Contact:

Post by maddogg6 »

darkhog wrote:I have pretty long loop (over 5min., around 7 MB in OGG) and it loads over half minute.
wow 5 mins and you still call it a 'loop'.. ??!! ok

I think you burried the lead on this one.... lol
darkhog
Posts: 132
Joined: Oct 05, 2011 21:19

Post by darkhog »

Yeah, it's loop. Very long, but still loop. Because all loops are looping and this one is looping. Doesn't contain fadeout/in and it loops.

So yes, I call it loop. ;)
creek23
Posts: 261
Joined: Sep 09, 2007 1:57
Location: Philippines
Contact:

Post by creek23 »

I'm trying to have a BG Music for my game's Main Menu and another BG Music when in-game.

I need them to be looped forever.

When I played Main Menu's BG Music, the in-game BG Music, plays as well.

Below is a snippet that replicates the problem.

Code: Select all

#LibPath "C:\test\fbsound0.12\lib"
#Include "C:\test\fbsound0.12\inc\fbsound.bi"

Dim As Integer sndMain, sndGame
Dim hWave As Integer

fbs_Set_PlugPath("C:\test\fbsound0.12\lib\")
fbs_Init()
print "loading main..."
	fbs_Load_WAVFile("music_main.wav", @hWave)
		fbs_Create_Sound(hWave,@sndMain)
print "loading game..."
	fbs_Load_WAVFile("music_game.wav", @hWave)
		fbs_Create_Sound(hWave,@sndGame)
	
fbs_Set_SoundLoops(sndMain, -1)
fbs_Set_SoundLoops(sndGame, -1)
	fbs_Play_Sound(sndMain)

' wait for it to play
While fbs_Get_PlayingSounds() = 0
	print "..."
	Sleep 10
Wend
print "playing sound"
Sleep
~creek23
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

Have a look at
  • fbs_Set_SoundPaused(sndMain, TRUE)
creek23
Posts: 261
Joined: Sep 09, 2007 1:57
Location: Philippines
Contact:

Post by creek23 »

Thanks for the work around TJF.

Hope Joshy would have the time to fix the problem on the library.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

hello Rens,
if you create ticks in your samples FBSound will play it back while the sound is looping. :-)

there is a jump between the start and the end of your sound.
Image

Code: Select all

#libpath "../lib"
#include "../inc/fbsound.bi"

const plug_path = "../lib/"
const data_path = "../data/"

fbs_Set_PlugPath(plug_path)
if fbs_Init(44100,1)=0 then
  ? "error: in fbs_Init() !"
  beep:sleep:end
end if

screenres 512,512

Dim As Integer         hWave,hSound
Dim As Single          w,wstep=pi2/44100.0*400
Dim As FBS_SAMPLE Ptr  lpSamples

fbs_Create_Wave(44100,@hWave,@lpSamples)
For i As Integer=0 To 44099
  lpSamples[i]=Sin(w)*44100:w+=wstep
Next

for x as integer=0 to 255
  ' plot first 256 samples
  pset(x,240+lpSamples[x]*0.001),2
  ' plot last 256 samples
  pset(255+x,240+lpSamples[44099-256+x]*0.001),3
next
sleep:end
by the way the max amplitude is 16 bit -32768<-> +32767
this means Samples[index]=Sin(wStep)*44100 is out of range

you know it ?

Joshy
Last edited by D.J.Peters on Oct 03, 2017 5:24, edited 1 time in total.
Post Reply