audio lib bass (dynamic) Windows/Linux 32/64-bit

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by D.J.Peters »

The Audio library BASS (as dynamic loaded version) for Windows/Linux 32/64-bit.

download: libbass.zip

Joshy

edit: added dynamic loaded library bassmix

included:
libbass.bi
libbass.bas

libbassmix.bi
libbassmix.bas

Bass_BassMix.bas
Bass_ChannelSetSync.bas
Bass_CustomBeep.bas
Bass_WAVSampleLoad.bas
Bass_MP3SampleLoad.bas
Bass_StreamCreateFile.bas
Bass_StreamCreate.bas
Bass_StreamCreateFileUser.bas
Bass_StreamCreateURL.bas

jimi.mod
loop.wav
legends.mp3

doc/bass.chm <--- you should read it

win32/bass.dll
win32/bassmix.dll
win64/bass.dll
win64/bassmix.dll
linux32/libbass.so
linux32/libbassmix.so
linux64/libbass.so
linux64/libbassmix.so
Last edited by D.J.Peters on Sep 25, 2017 15:44, edited 8 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by D.J.Peters »

You have to replace the underscore from Bass commands with a dot eg. BASS_INIT() -> BASS.Init() etc.

Joshy

Code: Select all

#include once "libbass.bas"

BASS.Init()
var music=BASS.MusicLoad(0,@"jimi.mod",0,0,BASS_SAMPLE_SOFTWARE,0)
BASS.ChannelPlay(music,1)
sleep
here are the same with checking for errors.
(I added Bass.GetVersionsString(), BASS.IsErrorOnLoad, BASS.GetErrorString())

Code: Select all

#include once "libbass.bas"

chdir exepath()
if BASS.IsErrorOnLoad then
  print "error: while loading " & BASS_LIB_NAME
  beep:sleep:end 1
else
  print Bass.GetVersionsString()
end if

if BASS.Init() then
  var music=BASS.MusicLoad(0,@"jimi.mod",0,0,BASS_SAMPLE_SOFTWARE,0)
  if music then 
    if BASS.ChannelPlay(music,1) then
      print "playing 'jimi.mod'"
    else
      print "BASS.ChannelPlay() error: " & BASS.GetErrorString() & " !"
    end if
  else
    print "BASS.MusicLoad() error: " & BASS.GetErrorString() & " !"
  end if
else
  print "BASS.Init() error: " & BASS.GetErrorString() & " !"
end if
sleep
Last edited by D.J.Peters on Apr 23, 2015 11:43, edited 3 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by D.J.Peters »

Added dynamic loaded lib BASSMIX and changed the directories see first post.

Joshy
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by D.J.Peters »

Test of Bass.StreamCreateURL()

Joshy

Code: Select all

#include once "libbass.bas"


if BASS.IsErrorOnLoad then
  print "error: while loading " & BASS_LIB_NAME
  beep:sleep:end 1
end if

print Bass.GetVersionsString()
dim as ulong stream
if BASS.Init() then
  print "connect to server ..."
  stream=Bass.StreamCreateURL("https://uk.un4seen.com/test.mp3",0,BASS_STREAM_AUTOFREE,0,0)
  if stream then 
    if BASS.ChannelPlay(stream,1) then
      print "play test.mp3 from internet"
    else
      print "BASS.ChannelPlay() error: " & BASS.GetErrorString() & " !"
    end if
  else
    print "BASS.StreamCreateURL() error: " & BASS.GetErrorString() & " !"
  end if
else
  print "BASS.Init() error: " & BASS.GetErrorString() & " !"
end if
while inkey()="" andalso BASS.ChannelIsActive(stream)
  print "."; : sleep 1000
wend
Last edited by D.J.Peters on Apr 23, 2015 11:44, edited 2 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by D.J.Peters »

First test of the BASSMixer API.

Joshy
Image

Code: Select all

' test of loading dynamic loading Bass and BassMix 

#include once "libbass.bas"
#include once "libbassmix.bas"

ChDir ExePath()

print BASS.GetVersionsString()
print BASSMIX.GetVersionsString()

screenres 512,512
dim as integer iWin
ScreenControl 2,iWin

var hWin=cast(any ptr,iWin)
BASS.Init(,,,hWin)
var mixer = BASSMIX.StreamCreate(44100,2,0)
var music=BASS.MusicLoad(0,@"jimi.mod",0,0,BASS_MUSIC_DECODE,0)
BASSMIX.StreamAddChannel(mixer,music,BASS_MIXER_BUFFER)

const as long nSamples        = 512
const as long nBytesPerSample = 4
const as long nChannels       = 2
const as long nBufferSize     = nSamples*nBytesPerSample
dim as short ptr pSamples=new short[nSamples*nChannels]

BASS.ChannelPlay(mixer,0)

while inkey="" andalso BASS.ChannelIsActive(music)
  var nBytes = BASSMIX.ChannelGetData(music,pSamples,nBufferSize)
  if nBytes=nBufferSize then
    screenlock:cls
    var pLeftSamples  = @pSamples[0]
    var pRightSamples = @pSamples[1]
    ' plot left channel
    line (0,128)-step(nSamples,0),15
    dim as long y = 128 + pLeftSamples[0] shr 8
    pset (0,y),1
    for x as long = 1 to nSamples-1
      y=128 + *pLeftSamples shr 8 :pLeftSamples+=2
      line -(x,y),2
    next
    ' plot right channel
    line (0,384)-step(nSamples,0),15
    y = 384 + pRightSamples[0] shr 8
    pset (0,y),3
    for x as long = 1 to nSamples-1
      y=384 + *pRightSamples shr 8 :pRightSamples+=2
      line -(x,y),3
    next
    screenunlock
  end if
  sleep 10
wend
Last edited by D.J.Peters on Sep 25, 2017 15:44, edited 3 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by D.J.Peters »

fixed a wrong declare in libbass.bi
Joshy

test of sync callback:

Code: Select all

#include once "libbass.bas"

if BASS.IsErrorOnLoad then
  print "error: while loading " & BASS_LIB_NAME
  beep:sleep:end 1
end if

sub SyncCB BASS_API (byval handle as HSYNC, byval channel as ulong, byval data_ as ulong, byval user as any ptr)
  print "SyncCB: BASS_SYNC_END"
end sub

chdir exepath()

BASS.Init()
var hStream  = BASS.StreamCreateFile(BASS_FALSE,@"loop.wav",0,0,BASS_SAMPLE_LOOP)
var hSync    = BASS.ChannelSetSync(hStream, BASS_SYNC_END, 0,@SyncCB,0)
var hChannel = BASS.ChannelPlay(hStream,0)
print "playing 'loop.wav' endless"
print "press any key ..."
sleep
Last edited by D.J.Peters on Jan 27, 2016 15:22, edited 2 times in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by D.J.Peters »

New download available.

changes:
libbass.bi works together with windows include files now.
(fixed problems with double defines of WORD, DWORD, QWORD, BOOL ...)

renamed:
TRUE in BASS_TRUE, FALSE in BASS_FALSE

removed:
runtime code from include files.

Tested with Windows 32-bit and Linux 32/64-bit.

I need feedback from windows 64-bit users.

Joshy
dafhi
Posts: 1641
Joined: Jun 04, 2005 9:51

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by dafhi »

works on 64
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by D.J.Peters »

new version published:

Joshy

fixed: one wrong declare
added: some more tests

First test of user stream/file callbacks.
If you implement this callbacks
you can load/stream your media
from files, memory, compressed achives, blue tooth,
USB devices, network or from any other source.

Code: Select all

#include once "libbass.bas"

#define GET_HFILE(x) *cptr(integer ptr,x)

sub CloseCB BASS_API (byval user as any ptr)
  close #GET_HFILE(user)
end sub

function LenCB BASS_API (byval user as any ptr) as ULongInt
  return LOF(GET_HFILE(user))
end function

function ReadCB BASS_API (byval buffer as any ptr, byval length as ulong, byval user as any ptr) as ulong
  dim as integer hFile=*cptr(integer ptr,user)
  dim as uinteger nBytes
  dim as ubyte ptr p8=buffer
  get #GET_HFILE(user),,*p8,length,nBytes
  return nBytes
end function

function SeekCB BASS_API (byval offset as ULongInt, byval user as any ptr) as ulong
  dim as integer hFile=*cptr(integer ptr,user)
  offset+=1
  if offset>LOF(hFile) then return 0
  seek #GET_HFILE(user),offset
  return 1
end function

'
' main
'
dim as BASS_FILEPROCS callbacks = type(@CloseCB, @LenCB, @ReadCB, @SeekCB)
dim as integer hFile = FreeFile()

chdir exepath()

if BASS.IsErrorOnLoad then
  print "error: while loading " & BASS_LIB_NAME
  beep:sleep:end 1
end if

if BASS.Init()=0 then
  print "BASS.Init() error: " & BASS.GetErrorString() & " !"
  beep:sleep:end 1
end if

if open("legends.mp3",for binary,access read,as #hFile) then
  print "error: open('legends.mp3')"
  beep:sleep:end 1
end if

var stream = BASS.StreamCreateFileUser(STREAMFILE_NOBUFFER, 0, callbacks,@hFile)
if stream=0 then
  print "BASS_StreamCreateFileUser() error: " & BASS.GetErrorString() & " !"
  beep:sleep:end
end if

if BASS.ChannelPlay(stream,1) then
  print "streaming 'legends.mp3'"
else
  print "BASS.ChannelPlay() error: " & BASS.GetErrorString() & " !"
  beep:sleep:end
end if


print "press any key or wait on end of stream"
while inkey()="" andalso BASS.ChannelIsActive(stream)
  print "."; : sleep 250
wend
Last edited by D.J.Peters on Jan 27, 2016 15:21, edited 1 time in total.
Rens
Posts: 256
Joined: Jul 06, 2005 21:09

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by Rens »

Hi,

I get a segmentation fault after compiling Bass_BassMix.bas

If i use (only) the following line:
#include once "libbass.bas"
(program exited with code: 0)
compiles and execute with no errors

If i use (only) the following 2 lines:
#include once "libbass.bas"
#include once "libbassmix.bas"
compiles but when running, i get a Segmentation fault

So it must be something to do with libbasmix.bas or libbasmix.bi and not with libbass.bi
I can't figure out what to do now. I use linux 32 bits.
Maybe there is something wrong with libbassmix.so ?

I appreciate your help, Thanx
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by D.J.Peters »

Hello Rens thank you for testing I get the same trouble on Linux here :-(
(looks like Win 32 / 64 - bit is ok)

Joshy
Linux wrote:joshy@P4:~/libbass$ fbc Bass_BassMix.bas
joshy@P4:~/libbass$ ./Bass_BassMix
Program received signal SIGSEGV, Segmentation fault.
joshy@P4:~/libbass$ fbc -exx Bass_BassMix.bas
joshy@P4:~/libbass$ ./Bass_BassMix
Program received signal SIGSEGV, Segmentation fault.
joshy@P4:~/libbass$ fbc -g -exx Bass_BassMix.bas
joshy@P4:~/libbass$ gdb ./Bass_BassMix
GNU gdb (Ubuntu 7.10-1ubuntu2) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
Reading symbols from ./Bass_BassMix...done.
(gdb) r
Starting program: /home/joshy/libbass/Bass_BassMix
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0xb7fcb8bd in ?? () from linux32/libbassmix.so
lordbla9
Posts: 11
Joined: Feb 25, 2016 6:55

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by lordbla9 »

' test of loading dynamic loading Bass and BassMix compiles fine but results in segmentation fault(core dumped) on Linux 64bit...how can this be fixed? Tried all the Fmod and Bass audio input examples I could find and still no working example under 64bit linux. Please let me know if anyone has got audio input example working under 64bit linux or if currently working on it. Thanks
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by lizard »

Great library. Here i have modified an example file to load and play .ogg. It is nothing more than to replace file name.

Code: Select all

'Bass_OGG_Load.bas

#include once "libbass.bas"
chdir exepath()
if BASS.IsErrorOnLoad then
  print "error: while loading " & BASS_LIB_NAME
  beep:sleep:end 1
end if

print Bass.GetVersionsString()

if BASS.Init() then
  var sample=BASS.SampleLoad(0,@"Violence.ogg",0,0,1,0) ' change here file name for .wav, .mp3 or .ogg
  if sample then
    if BASS.ChannelPlay(BASS.SampleGetChannel(sample,1),1) then
      print "play 'Violence.ogg'"
    else
      print "BASS.ChannelPlay() error: " & BASS.GetErrorString() & " !"
    end if
  else
    print "BASS.SampleLoad() error: " & BASS.GetErrorString() & " !"
  end if
else
  print "BASS.Init() error: " & BASS.GetErrorString() & " !"
end if
print "press any key ..."
sleep
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by MrSwiss »

@lizard,

just beware of the licensing terms of BASS, it's only free, for noncommercial use!
lizard
Posts: 440
Joined: Oct 17, 2017 11:35
Location: Germany

Re: audio lib bass (dynamic) Windows/Linux 32/64-bit

Post by lizard »

So is this here illegal? Must confess i am sometimes confused with all the licences.
Post Reply