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

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 7419
Joined: May 28, 2005 3:28

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby D.J.Peters » Apr 23, 2018 22:19

It's more safe to do an error check also.
To make it in fbsound style I changed the name and added byval for -w pedantic.

Code: Select all

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
Only for info a sound can be in more states as playing or stopped.

Joshy

Something like this:

Code: Select all

enum eSoundState
  eUnknow = 0 ' may be not loaded aTM.
  eStopped ' fbs_Get_SoundLoops() nLoops = 0
  ePlaying ' fbs_Get_SoundLoops() nLoops = 1
  eLooping ' fbs_Get_SoundLoops() nLoops > 1
  ePaused ' fbs_Get_SoundPaused()
  eMuted ' fbs_Get_SoundMuted()
end enum

function fbs_Get_SoundState(byval hSound as integer) as eSoundState
...
end function
badidea
Posts: 752
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby badidea » Apr 25, 2018 22:43

Another question or comment. I am struggling to get fbs_Set_SoundPointers() working in a way that I understand.
I have modified the example a bit:

Code: Select all

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

const data_path = "../data/"
chdir(exepath())

dim as integer   hWave,hSound,nSamples,nChannels
dim as short ptr lpWaveStart,lpWaveEnd
dim as short ptr lpSoundStart,lpSoundPlay,lpSoundEnd

fbs_Init()
fbs_Load_WAVFile(data_path & "fbsloop44.wav",@.hWave)
fbs_Create_Sound(hWave,@hSound)
' Get start,end and number of channels from wave object
fbs_Get_WavePointers(hWave, @lpWaveStart, @lpWaveEnd, @nChannels)
nSamples = (lpWaveEnd - lpWaveStart) / (2 * nChannels)
print nSamples, lpWaveEnd, lpWaveStart, nChannels

' begin = start of the wave
lpSoundPlay = lpWaveStart + (nSamples \ 32) * 10 ' * nChannels ???
' any begin of playback region
lpSoundStart = lpWaveStart + (nSamples \ 32) * 20 ' * nChannels ???
' any end of playback region
lpSoundEnd = lpWaveEnd - (nSamples \ 32) * 16 * (nChannels * 2) '???
fbs_Set_SoundPointers(hSound, lpSoundStart, lpSoundPlay, lpSoundEnd)

fbs_Play_Sound(hSound, 1) ' 1 times

' wait on first sample
while fbs_Get_PlayingSounds()=0:sleep 10:wend

dim as double t = timer
while fbs_Get_PlayingSounds() and inkey()=""
  sleep 1
wend
print " Time:"; timer - t
'end

This plays (on my system) sound for ~1.94 seconds. I cannot find the logic behind it.
Imortis
Posts: 1556
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby Imortis » Apr 25, 2018 22:53

By the way: All tests were successful on Win7 64bit. Good work!
D.J.Peters
Posts: 7419
Joined: May 28, 2005 3:28

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby D.J.Peters » Apr 26, 2018 17:35

@Imortis thank you for testing :-)

@badidea » this would be right if you calculate with byte pointers
nSamples = (pWaveEnd - pWaveStart) / (2 * nChannels)

But if you use short pointers it's:
nSamples = (pWaveEnd - pWaveStart) / nChannels

But wait there is another mistake samples versus frames
nSamples = (pWaveEnd - pWaveStart)

nFrames = (pWaveEnd - pWaveStart) / nChannels

The number of Frames are independent from mono vs stereo samples

Setting the buffer pointers are an advanced feature and only for special cases.

Don't worry if your first results are not what you would accept.

I can help if you are tell me what you are trying to do with the pointers ?

May be it would be better to calculate new pointer positions by a time base.

Seconds or in milliseconds or BPM or ...

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

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby badidea » Apr 26, 2018 20:20

It is actually a modified version of 'fbs_set_get_pointers.bas' in the 'tests' directory.
What I am trying to do, is from e.g. a 10 seconds long sound, play second 3 to 5.
But I will do some more testing and tweaking, also under Windows. There seems to be a bug here.
paul doe
Posts: 535
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby paul doe » Apr 26, 2018 21:23

D.J.Peters wrote:May be it would be better to calculate new pointer positions by a time base.

Seconds or in milliseconds or BPM or ...

Joshy

Hi Joshy,

Very nice lib, works ok so far here (Win10). About the question by badidea (who usually has good ideas =D), may I suggest a feature? Exposing some functions to easily manipulate the timing could prove useful. Something along the lines of...

Code: Select all

setPlaybackTime( byval milliseconds as double ) '' Sets the playback time in milliseconds
playSound( byval startTime as double, byval endTime as double ) '' Plays endTime - startTime milliseconds of a sound

...or something, to have a portable way to do these manipulations, so if you later change/fix/debug the library, compatibility isn't broken with the current codebase that uses the lib. That way the user end doesn't need, if he doesn't want/don't know how to, fiddle with pointers. Just a suggestion...
badidea
Posts: 752
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby badidea » Apr 26, 2018 23:29

Improved code. Setting the 'end time' seems to work, but not the 'start time'. (Linux and Windows).

Code: Select all

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

function main() as string
   dim as boolean ok
   dim as integer hWave

   ok = fbs_Init()
   if ok = false then return "Error: fbs_Init()" + FBS_Get_PlugError()
   print "Success: fbs_Init()"

   dim as string waveFileName = "../data/fbsloop44.wav"
   ok = fbs_Load_WAVFile(waveFileName, @hWave)
   if ok = false then return "Error: fbs_Load_WAVFile(" + waveFileName + ")"
   print "Success: fbs_Load_WAVFile(" + waveFileName + ")"

   'fbsloop44.wav details:
   '16-bit stereo: 2-byte left, 2-byte right, ... ?
   '1 frame = 4 bytes (left + right) ?
   '44100 Hz, 16-bit, stereo, ~3.85 seconds = ~679,140 bytes
   'filesize = 683,684 bytes

   dim as short ptr pWaveStart, pWaveEnd
   dim as integer nSamples, nBytes, nChannels, nFrames
   dim as single waveLength
    
   fbs_Get_WavePointers(hWave, @pWaveStart, @pWaveEnd, @nChannels)
   nSamples = pWaveEnd - pWaveStart
   nBytes = nSamples * 2 'sizeof(short)
   nFrames = nSamples \ nChannels
   waveLength = nFrames / 44100 'default value for now

   print "nBytes: " + str(nBytes)
   print "nSamples: " + str(nSamples)
   print "nFrames: " + str(nFrames)
   print "waveLength [s]: " + str(waveLength)

   dim as integer hSound

   fbs_Create_Sound(hWave, @hSound)

   dim as short ptr pSoundStart, pSoundPlay, pSoundEnd
   dim as single startTime, endTime 'seconds

   startTime = 1.0 'This does not work !?
   endTime = 2.0
   pSoundPlay = pWaveStart' + cint((startTime * 44100) * nChannels)
   pSoundStart = pWaveStart + cint((startTime * 44100) * nChannels)
   pSoundEnd = pWaveStart + cint((endTime * 44100) * nChannels)

   ok = fbs_Set_SoundPointers(hSound, pSoundStart, pSoundPlay, pSoundEnd)
   if ok = false then return "Error: fbs_Set_SoundPointers()"
   print "Success: fbs_Set_SoundPointers()"

   fbs_Play_Sound(hSound, 1) ' 1 times

   'wait for playing
   while fbs_Get_PlayingSounds() = 0
      sleep 1
   wend

   dim as double t = timer

   'wait for end of play
   while fbs_Get_PlayingSounds() <> 0
     sleep 1
   wend

   print "playTime [s]: " + str(timer - t)

   return "The end."
end function

print main()
end
D.J.Peters
Posts: 7419
Joined: May 28, 2005 3:28

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby D.J.Peters » Apr 27, 2018 0:08

Normally for game coders a sound library is low level.
The primary functionality are loading and playing sounds.

It comes with some tools to make more complex tasks by the user of the library.

Tools are:
Left and right channel paning
Volume control
different playback speed
10 user defined EQ's
Sound callbacks.
...

With this tools you an create:
Realistic 3D sounds with doppler effect
Indore vs outdoor switchable setups.
Sound sources with cone or sphere characteristic.
Inside the callback's you can calculate any DSP effect
and many more ...

I would encapsulate my sound objects from the low level stuff
like this pseudo code:

Code: Select all

type hWave as integer
type hSound as integer

type tWavePool
  declare function Load(Path as string) as hWave
  as hWave Poll()
  ' ...
end type

type tSound
  declare constructor(WaveID as hWave)
  declare constructor(Path as string)
  declare constructor(nSamples as integer, nChannesl as integer=2)
  declare function Play(nLoops as integer=1) as boolean
  declare function PlayFrom(timeStart as double, nLoops as integer=1) as boolean
  declare function PlayTo(timeEnd as double, nLoops as integer=1) as boolean
  declare function PlayRange(timeStart as double, timeEnd as double, nLoops as integer=1) as boolean
  declare property Pan as single
  declare property Pan(value as single)
  declare property Speed as single
  declare property Speed(value as single)
  ...
  as hSound ID
end type

type tSound3D extends tSound2D
  declare sub setPosition(x as single, x as single, z as single)
  declare sub getPosition(byref x as single, byref x as single, byref z as single)
  declare sub setVelocity(x as single, x as single, z as single)
  declare sub getVelocity(byref x as single, byref x as single, byref z as single)
  declare sub setCone(angle as single=60, umbra as single, penumbra as single)
  declare sub getCone(byref angle as single,byref umbra as single,byref penumbra as single)
  declare sub setSphere(radius as single)
  declare sub getSphere(byref radius as single)
  enum eMode
    bothoff
    cone
    sphere
  end enum   
  declare sub setMode(mode as eMode)
  ...
end type 
 
type tEffect extends tSound
  declare sub setEQ(index as integer, centerFrequency as single, db as single)
  declare sub getEQ(index as integer, byref centerFrequency as single, byref db as single)
  declare sub enableEQ(index as integer, onoff as boolean) 
 
  declare sub setEcho(roomSize as single, delaytime as single, intensity as single)
  declare sub getEcho(byref roomSize as single, byref delayTime as single, byref intensity as single)
  declare sub enableEcho(onoff as boolean) 
  ...
end type

type tEffect3D extends tEffect
  declare sub setDoppler(factor as single, minFrequency as single, db as single)
  declare sub getDoppler(byref factor as single, byref minFrequency as single, byref db as single)
  declare sub enableDoppler(onoff as boolean) 
 
  declare sub setEcho3D(roomWidth as single, roomHeight as single, roomDepth as single, intensity as single)
  declare sub getEcho3D(byref roomWidth as single, byref roomHeight as single, byref roomDepth as single, byref intensity as single)
  declare sub enableEcho3D(onoff as boolean) 
  ...
end type
paul doe
Posts: 535
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby paul doe » Apr 27, 2018 1:29

D.J.Peters wrote:Normally for game coders a sound library is low level.
The primary functionality are loading and playing sounds.

It comes with some tools to make more complex tasks by the user of the library.

I know. It was just a suggestion.
D.J.Peters
Posts: 7419
Joined: May 28, 2005 3:28

Re: fbsound 1.0 Linux Windows 32/64-bit (wav mp3 ogg mod it xm s3m)

Postby D.J.Peters » Apr 27, 2018 5:35

paul doe wrote:... It was just a suggestion.
Same here ;-)

Joshy
mrToad
Posts: 353
Joined: Jun 07, 2005 23:03
Location: USA
Contact:

Re: fbSound for Linux x86 Win32 (wav mp3 ogg mod it xm s3m)

Postby mrToad » Jun 06, 2018 11:43

D.J.Peters wrote:I edit 2,500 lines of assembler codes and it works now :- )

Just want to say thank you for all your hard work and many hours, Joshy! This was a really pleasant surprise.

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 2 guests