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
Roland Chastain
Posts: 993
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: FBSound for Linux and Windows. (*.wav, *.mp3, *.ogg)

Post by Roland Chastain »

Hello Joshy!

I can't download your archive (error 404). Could you check the link please?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FBSound for Linux and Windows. (*.wav, *.mp3, *.ogg)

Post by D.J.Peters »

Roland Chastain wrote:Could you check the link please?
done ;-)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

A new week why not a new version of fbsound ;-)

supported files: *.wav, *.mp3, *.mp2, *.ogg, *.mod, *.it, *.xm, *.s3m.

new: fbs_Load_ModFile(filename,@hWave,)

added: test31.bas, test32.bas, test33.bas, test34.bas

fbsound0.18 tested with FreeBASIC 0.24, 0.90.1 and 0.91.0. (linux86 and win32)

Joshy
Roland Chastain
Posts: 993
Joined: Nov 24, 2011 19:49
Location: France
Contact:

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

Post by Roland Chastain »

Compiled and executed successfully all the examples under Windows 8.1. Congratulations! It's a very nice library.
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: fbSound for linuxX86 win32 (wav mp3 ogg mod it xm s3m)

Post by VANYA »

Hi Joshy!

I tested examples test31.bas - test35.bas , work well.
*.wav, *.mp3, *.mp2, *.ogg, *.mod, *.it, *.xm, *.s3m.
Very cool! Another would be midi :)

In any case, you well done.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: fbSound for linuxX86 win32 (wav mp3 ogg mod it xm s3m)

Post by D.J.Peters »

Before I add a new DirectSound driver for windows could you test it please ?
Any emulated drivers (no hardware buffer) will be ignored and FBSound will use the mm driver instead.

Post the console output please.

Thank you

Joshy
debug: DS_DEVICE_DESCRIPTOR()
debug: DS_DEVICE_DESCRIPTOR()
debug: device(0):BD6DD71A-3DEB-11D1-B17100C04FC20001 Crystal SoundFusion(tm)
debug: device(1):BD6DD71A-3DEB-11D1-B17100C04FC20003 USB Headphone Set
debug: DS_PRIMARY_BUFFER()
debug: create primary buffer ok
debug: get primary caps hw buffersize 32768 ok
debug: get primary format ok
debug: release primary buffer ok
debug: create secondary buffer ok
debug: get secondary caps sw buffersize 49152 ok
debug: get secondary format ok
debug: get IID_IDirectSoundNotify ok
debug: m_pPositionNotify[0].dwOffset = 0
debug: m_pPositionNotify[1].dwOffset = 16384
debug: m_pPositionNotify[2].dwOffset = 32768
debug: IDirectSoundNotify_SetNotificationPositions ok
debug: secondary buffer looping ok
Be sure no other app will use the audio device (web browsers, messangers, etc.) while running the test.

Code: Select all

' file: test02.bas
' test of secondary DirectSoundBuffer
#include once "windows.bi"       ' <- BOOL, NULL ...
#include once "win/mmsystem.bi"  ' <- WAVEFORMETEX
#include once "win/dsound.bi"    ' <- IDirectSound
#include once "crt/string.bi"    ' <- memcpy

#inclib "dxguid"
#inclib "ole32"

#define DEBUG

#ifdef DEBUG
 #ifndef dprint
  #define dprint(msg) scope:dim as integer hFile=FreeFile():open err for output as #hFile:print #hFile,"debug: " & msg:close #hFile:end scope
 #endif
#else
 #ifndef dprint
  #define dprint(msg) :
 #endif
#endif

' GUID helper
function Guid2String(byval pGuid as LPGUID) as string
  if pGuid=0 then return "00000000-0000-0000-0000000000000000"
  dim as string tmp = hex(pGuid->Data1,8) & "-" & _
                      hex(pGuid->Data2,4) & "-" & _
                      hex(pGuid->Data3,4) & "-"
  for i as integer=0 to 7
     tmp &= hex(pGuid->Data4(i),2)
  next
  return tmp
end function

' WAVEFORMATEX helper
sub setWaveFormatEx(byref wf        as WAVEFORMATEX, _
                    byval nRate     as integer     , _
                    byval nChannels as integer)
  if nChannels<2 then nChannels=1 else nChannels=2
  wf.wFormatTag     = WAVE_FORMAT_PCM
  wf.nChannels      = nChannels
  wf.nSamplesPerSec = nRate
  wf.wBitsPerSample = 16
  wf.nBlockAlign    = nChannels*2
  wf.nAvgBytesPerSec=wf.nSamplesPerSec*wf.nBlockAlign
  wf.cbSize         =0
end sub

' primary DirectSoundBuffer
type DS_PRIMARY_BUFFER
  declare destructor
  declare constructor (byval nPlayrate as integer=44100, _
                       byval nChannels as integer=    2, _
                       byval nBuffers  as integer=    4, _
                       byval nSamples  as integer= 2048, _
                       byval pGuid     as LPGUID)
  declare function getRate       as integer
  declare function getBits       as integer
  declare function getChannels   as integer
  declare function getBuffers    as integer
  declare function getFrames     as integer
  declare function getFramesize  as integer
  declare function getBuffersize as integer
  declare function isPlaying     as integer
  declare function isLocked      as integer
  declare function getEvents     as LPHANDLE 
  declare function getCurrentPosition(byref CurrentPlayCursor  as DWORD, _
                                      byref CurrentWriteCursor as DWORD) as integer
  declare function LockPointers(byval from     as integer    , _
                                byval ppAudio1 as any ptr ptr, _
                                byval pSize1   as integer ptr, _
                                byval ppAudio2 as any ptr ptr, _
                                byval pSize2   as integer ptr) as integer
  declare function UnlockPointers(byval pAudio1 as any ptr, _
                                  byval Size1   as integer, _
                                  byval pAudio2 as any ptr, _
                                  byval Size2   as integer) as integer
  private:
  
  as LPDIRECTSOUND       m_pDirectSound

  as LPDIRECTSOUNDBUFFER m_pPrimaryBuffer
  as DSBUFFERDESC        m_PrimaryBufferDesc
  as DSBCAPS             m_PrimaryCaps
  as WAVEFORMATEX        m_PrimaryWaveFormat

  as LPDIRECTSOUNDBUFFER m_pSecondaryBuffer
  as DSBCAPS             m_SecondaryCaps
  as DSBUFFERDESC        m_SecondaryBufferDesc
  as WAVEFORMATEX        m_SecondaryWaveFormat
  
  as LPDIRECTSOUNDNOTIFY m_pSoundNotify
  as LPDSBPOSITIONNOTIFY m_pPositionNotify
  as LPHANDLE            m_phEvents
  as integer             m_nBuffers ' nBuffers * nFrames = getBuffersize()
  as integer             m_nFrames  ' samples per buffer
  as integer             m_nFramesize
  as integer             m_Playing
  as integer             m_Locked
end type

destructor DS_PRIMARY_BUFFER
  dprint("DS_PRIMARY_BUFFER~")
  if m_pDirectSound<>NULL then
    ' stop secondary buffers
    if m_pSecondaryBuffer<>NULL then
      dim as DWORD status
      if (IDirectSoundBuffer_GetStatus(m_pSecondaryBuffer,@status)=DS_OK) then
        if ((status and DSBSTATUS_PLAYING)<>0) then
          dprint("IDirectSoundBuffer_Stop(m_pSecondaryBuffer)")
          IDirectSoundBuffer_Stop(m_pSecondaryBuffer)
        end if
      end if
    end if
    ' delete event handles
    if m_phEvents then
      for i as integer=0 to m_nBuffers-1
        if m_phEvents[i]<>NULL then 
          dprint("CloseHandle(m_phEvents[" & i & "])")
          CloseHandle(m_phEvents[i])
        end if
      next
      delete[] m_phEvents
    end if
    ' free m_pPositionNotify
    if m_pPositionNotify then
      delete [] m_pPositionNotify
      m_pPositionNotify=0
    end if
    ' release sound notify
    if m_pSoundNotify<>NULL then
      dprint("IDirectSoundNotify_Release(m_pSoundNotify)")
      IDirectSoundNotify_Release(m_pSoundNotify)
      m_pSoundNotify=0
    end if
    ' release secondary buffer
    if m_pSecondaryBuffer<>NULL then
      dprint("IDirectSoundBuffer_Release(m_pSecondaryBuffer)")
      IDirectSoundBuffer_Release(m_pSecondaryBuffer)
      m_pSecondaryBuffer=0
    end if
    ' release direct sound
    dprint("IDirectSound_Release(m_pDirectSound)")
    IDirectSound_Release(m_pDirectSound)
    m_pDirectSound=0
  end if

  ' Uninitialize COM
  CoUninitialize()

  #ifdef DEBUG
  sleep 2000
  #endif
end destructor

constructor DS_PRIMARY_BUFFER(byval nPlayrate as integer, _
                              byval nChannels as integer, _
                              byval nBuffers  as integer, _
                              byval nFrames   as integer, _
                              byval pGuid     as LPGUID)
  dprint("DS_PRIMARY_BUFFER()")
  ' Initialize COM
  CoInitialize(NULL)

  if nPlayrate<     11026 then
    nPlayrate=11025
  elseif nPlayrate< 22051 then
    nPlayrate=22050
  elseif nPlayrate< 32001 then
    nPlayrate=32000
  elseif nPlayrate< 38001 then
    nPlayrate=38000
  elseif nPlayrate< 44101 then
    nPlayrate=44100
  elseif nPlayrate< 48001 then
    nPlayrate=48000
  elseif nPlayrate<100000 then
    nPlayrate=96000
  else
    nPlayrate=100000
  end if

  if     nBuffers< 2 then
    nBuffers=2
  elseif nBuffers>64 then
    nBuffers=64
  end if

  if     nFrames<  513 then
    nFrames=512
  elseif nFrames< 1025 then
    nFrames=1024
  elseif nFrames< 2049 then
    nFrames=2048
  elseif nFrames< 4097 then
    nFrames=4096
  elseif nFrames< 8193 then
    nFrames=8192
  elseif nFrames<16385 then
    nFrames=16384
  else
    nFrames=32768
  end if

  ' create device
  if (DirectSoundCreate(pGUID,@m_pDirectSound,NULL)=DS_OK) then
    ' set cooperative level
    if (IDirectSound_SetCooperativeLevel(m_pDirectSound,GetForegroundWindow(),DSSCL_PRIORITY)=DS_OK) then
      ' create primary sound buffer
      with m_PrimaryBufferDesc
        .dwSize       =sizeof(DSBUFFERDESC)
        .dwFlags      =DSBCAPS_PRIMARYBUFFER
        .dwBufferBytes=0
        .lpwfxFormat  =NULL
      end with
      if (IDirectSound_CreateSoundBuffer(m_pDirectSound,@m_PrimaryBufferDesc,@m_pPrimaryBuffer,NULL)=DS_OK) then
        dprint("create primary buffer ok")
        ' get buffer caps
        m_PrimaryCaps.dwSize = sizeof(DSBCAPS) 
        if (IDirectSoundBuffer_GetCaps(m_pPrimaryBuffer,@m_PrimaryCaps)=DS_OK) then
          dim as integer hwbuffersize =  m_PrimaryCaps.dwBufferBytes
          dprint("get primary caps hw buffersize " & hwbuffersize & " ok")
          setWaveFormatEx(m_PrimaryWaveFormat,nPlayrate,nChannels)
          ' try format
          IDirectSoundBuffer_SetFormat(m_pPrimaryBuffer,@m_PrimaryWaveFormat)
          ' get curent format
          if IDirectSoundBuffer_GetFormat(m_pPrimaryBuffer,@m_PrimaryWaveFormat,sizeof(WAVEFORMATEX),NULL)=DS_OK then
            dprint("get primary format ok")
            ' create secondary sound buffer
            setWaveFormatEx(m_SecondaryWaveFormat,nPlayrate,nChannels)
            with m_SecondaryBufferDesc
              .dwSize       =sizeof(DSBUFFERDESC)
              .dwFlags      =DSBCAPS_CTRLPOSITIONNOTIFY or DSBCAPS_GETCURRENTPOSITION2
              .dwBufferBytes=nBuffers*nFrames*4
              while .dwBufferBytes<hwbuffersize
               nFrames shl=1
               .dwBufferBytes=nBuffers*nFrames*4
              wend
              .lpwfxFormat  =@m_SecondaryWaveFormat
            end with

            if IDirectSoundBuffer_Release(m_pPrimaryBuffer)=DS_OK then
              dprint("release primary buffer ok")
              m_pPrimaryBuffer=0
            end if

            if (IDirectSound_CreateSoundBuffer(m_pDirectSound,@m_SecondaryBufferDesc,@m_pSecondaryBuffer,NULL)=DS_OK) then
              dprint("create secondary buffer ok")
              ' get buffer caps
              m_SecondaryCaps.dwSize = sizeof(DSBCAPS) 
              if (IDirectSoundBuffer_GetCaps(m_pSecondaryBuffer,@m_SecondaryCaps)=DS_OK) then
                dim as integer swbuffersize=m_SecondaryCaps.dwBufferBytes
                dprint("get secondary caps sw buffersize " & swbuffersize & " ok")
                ' get curent format
                if IDirectSoundBuffer_GetFormat(m_pSecondaryBuffer,@m_SecondaryWaveFormat,sizeof(WAVEFORMATEX),NULL)=DS_OK then
                  dprint("get secondary format ok")
                  m_nFramesize = m_SecondaryWaveFormat.nBlockAlign
                  m_nBuffers   = nBuffers
                  m_nFrames    = swbuffersize\(m_nFramesize*nBuffers)
                  if IDirectSoundBuffer_QueryInterface(m_pSecondaryBuffer,@IID_IDirectSoundNotify,@m_pSoundNotify)=S_OK then
                    dprint("get IID_IDirectSoundNotify ok")
                    m_phEvents = new HANDLE[m_nBuffers]
                    m_pPositionNotify = new DSBPOSITIONNOTIFY[m_nBuffers]
                    for i as integer=0 to nBuffers-1
                      m_phEvents[i]=CreateEvent(NULL,FALSE,FALSE,NULL)
                      m_pPositionNotify[i].dwOffset=i*m_nFrames*m_nFramesize
                      m_pPositionNotify[i].hEventNotify=m_phEvents[i]
                      dprint("m_pPositionNotify[" & i & "].dwOffset = " & m_pPositionNotify[i].dwOffset)
                    next
                    if IDirectSoundNotify_SetNotificationPositions(m_pSoundNotify,m_nBuffers,m_pPositionNotify)=DS_OK then
                      dprint("IDirectSoundNotify_SetNotificationPositions ok")
                    end if
                  end if ' IID_IDirectSoundNotify
                end if ' m_SecondaryWaveFormat
              end if ' m_SecondaryCaps
            end if ' m_pSecondaryBuffer
          end if ' m_PrimaryWaveFormat
          m_Playing=(IDirectSoundBuffer_Play(m_pSecondaryBuffer,0,0,DSBPLAY_LOOPING)=DS_OK)
          dim as DWORD status
          if (IDirectSoundBuffer_GetStatus(m_pSecondaryBuffer,@status)=DS_OK) then
            if ((status and DSBSTATUS_PLAYING)<>0) then
              dprint("secondary buffer looping ok")
            end if
          end if ' status
        end if ' m_PrimaryCaps
      end if ' m_pPrimaryBuffer
    end if ' DSSCL_PRIORITY
  end if ' m_pDirectSound
end constructor


function DS_PRIMARY_BUFFER.getRate as integer
  return m_SecondaryWaveFormat.nSamplesPerSec
end function
function DS_PRIMARY_BUFFER.getBits as integer
  return m_SecondaryWaveFormat.wBitsPerSample
end function
function DS_PRIMARY_BUFFER.getChannels as integer
  return m_SecondaryWaveFormat.nChannels
end function
function DS_PRIMARY_BUFFER.getBuffers as integer
  return m_nBuffers
end function
function DS_PRIMARY_BUFFER.getFrames as integer
  return m_nFrames
end function
function DS_PRIMARY_BUFFER.getFramesize as integer
  return m_nFramesize
end function
function DS_PRIMARY_BUFFER.getBuffersize as integer
  return m_nFrames*m_nFramesize
end function
function DS_PRIMARY_BUFFER.getEvents as LPHANDLE 
  return m_phEvents
end function
function DS_PRIMARY_BUFFER.isPlaying as integer
  return m_Playing
end function
function DS_PRIMARY_BUFFER.isLocked as integer
  return m_Locked
end function
function DS_PRIMARY_BUFFER.getCurrentPosition(byref CurrentPlayCursor  as DWORD, _
                                              byref CurrentWriteCursor as DWORD) as integer
  if (m_pSecondaryBuffer=NULL) then return 0
  return (IDirectSoundBuffer_GetCurrentPosition(m_pSecondaryBuffer,@CurrentPlayCursor,@CurrentWriteCursor)=DS_OK)
end function

function DS_PRIMARY_BUFFER.LockPointers(byval from     as integer    , _
                                        byval ppAudio1 as any ptr ptr, _
                                        byval pSize1   as integer ptr, _
                                        byval ppAudio2 as any ptr ptr, _
                                        byval pSize2   as integer ptr) as integer
  if (m_pSecondaryBuffer=NULL) then return 0
  if (m_Locked) then return 0
  dim as integer nBytes=m_nFrames*m_nFramesize
  dim as HRESULT ret=IDirectSoundBuffer_Lock(m_pSecondaryBuffer,from,nBytes,ppAudio1,pSize1,ppAudio2,pSize2,0)
  if ret=DSERR_BUFFERLOST then
    dprint("buffer lost !")
    if IDirectSoundBuffer_Restore(m_pSecondaryBuffer)=DS_OK then
      if IDirectSoundBuffer_Lock(m_pSecondaryBuffer,from,nBytes,ppAudio1,pSize1,ppAudio2,pSize2,0)=DS_OK then
        m_Locked=-1
      end if
    end if
  elseif ret=DS_OK then
    m_Locked=-1
  end if
  return m_Locked
end function

function DS_PRIMARY_BUFFER.UnlockPointers(byval pAudio1 as any ptr, _
                                          byval Size1   as integer, _
                                          byval pAudio2 as any ptr, _
                                          byval Size2   as integer) as integer
  if (m_pSecondaryBuffer=NULL) then return 0
  if (m_Locked=0) then return 0
  if (IDirectSoundBuffer_Unlock(m_pSecondaryBuffer,pAudio1,Size1,pAudio2,Size2)=DS_OK) then
    m_Locked=0
  end if
  return (m_Locked=0)
end function

type DS_DEVICE_DESCRIPTOR
  public:
  declare destructor
  declare constructor(byval pGuid        as LPGUID, _
                      byval pDescription as LPCSTR, _
                      byval pModule      as LPCSTR)
  declare operator cast as string
  declare function getGuid as LPGUID
  private:
  as LPGUID m_pGuid
  as LPCSTR m_pDescription
  as LPCSTR m_pModule
end type
type PDS_DEVICE_DESCRIPTOR as DS_DEVICE_DESCRIPTOR ptr

destructor DS_DEVICE_DESCRIPTOR
  dprint("DS_DEVICE_DESCRIPTOR~")
  if m_pGuid then 
    delete m_pGuid
    m_pGuid=0
  end if
  if m_pDescription then
    delete[] m_pDescription
    m_pDescription=0
  end if
  if m_pModule then
    delete[] m_pModule
    m_pModule=0
  end if
end destructor

constructor DS_DEVICE_DESCRIPTOR(byval pGuid        as LPGUID, _ 
                                 byval pDescription as LPCSTR, _
                                 byval pModule      as LPCSTR)
  dprint("DS_DEVICE_DESCRIPTOR()")
  if (pGuid<>0) then
    m_pGuid=new GUID
    *m_pGUID=*pGuid
  end if
  if (pDescription<>NULL) then
    dim as integer nChars=len(*pDescription)+1
    m_pDescription=new ubyte[nChars]
    *m_pDescription=*pDescription
  end if
  if (pModule<>NULL) then
    dim as integer nChars=len(*pModule)+1
    m_pModule=new ubyte[nChars]
    *m_pModule=*pModule
  end if
end constructor

operator DS_DEVICE_DESCRIPTOR.cast as string
  dim as string tmp = Guid2String(m_pGuid) & " " & *m_pDescription
  operator = tmp
end operator

function DS_DEVICE_DESCRIPTOR.getGuid as LPGUID
  return m_pGuid
end function


type DS_DEVICE_LIST
  declare destructor
  as integer                   nDevices
  as PDS_DEVICE_DESCRIPTOR ptr  pDevices
end type
type PDS_DEVICE_LIST as DS_DEVICE_LIST ptr

destructor DS_DEVICE_LIST
  if (pDevices<>NULL) then
    if nDevices>0 then
      for i as integer=0 to nDevices-1
        if (pDevices[i]<>NULL) then
          delete pDevices[i]
          pDevices[i]=0
        end if
      next
      nDevices=0
    end if
    deallocate pDevices
    pDevices=0
  end if
  dprint("DS_DEVICE_LIST~")
end destructor


function DSDeviceEnumCB(byval pGuid as LPGUID, byval pDescription as LPCSTR, byval pModule as LPCSTR, byval pUserdata as LPVOID) as BOOL
  dim as DS_DEVICE_LIST ptr pList=cptr(DS_DEVICE_LIST ptr,pUserdata)
  if (pList=NULL) then 
    dprint("DSDeviceEnumCB error: pList=NULL !")
    return 0 ' interrupt enumeration
  end if
  ' the first primary (default) device does not have a GUID 
  ' (ignore it here it will be two times in the list)
  if pGUID=0 then return 1 ' get next device
  ' be sure it's not an emulated DirectSound device
  ' it's better to use the MM AudioDevice directly as an emulated DirectSound device
  dim as LPDIRECTSOUND ds
  ' craete the device interface if bussy try next device
  if (DirectSoundCreate(pGuid,@ds,NULL)<>DS_OK) then return 1
  dim as integer AddDeviceToList=0
  ' get device caps
  dim as DSCAPS caps
  caps.dwSize=sizeof(DSCAPS)
  if IDirectSound_GetCaps(ds,@caps)=DS_OK then
    ' not an emulated MM device ?
    if (caps.dwFlags and DSCAPS_EMULDRIVER)=0 then 
      ' 16 bit primary sound buffer ?
      if (caps.dwFlags and DSCAPS_PRIMARY16BIT) then
        ' stereo primary sound buffer ?
        if (caps.dwFlags and DSCAPS_PRIMARYSTEREO) then
          if (IDirectSound_SetCooperativeLevel(ds,GetForegroundWindow(),DSSCL_PRIORITY)=DS_OK) then
            AddDeviceToList=1
          end if
        end if
      end if
    end if
  end if
  ' free the interface
  IDirectSound_Release(ds)
  if AddDeviceToList<>0 then
    ' allocate new item in list
    pList->pDevices=reallocate(pList->pDevices,sizeof(PDS_DEVICE_DESCRIPTOR)*(pList->nDevices+1))
    pList->pDevices[pList->nDevices]=new DS_DEVICE_DESCRIPTOR(pGuid,pDescription,pModule)
    pList->nDevices+=1
  end if
  return 1 ' allow next device enumeration
end function

sub FillBuffer(byval pBuffer as short ptr, byval nSamples as integer)
  static as single w1=0
  static as single w2=0
  static as single w3=0
  static as single w4=0
  dim as short ptr p=pBuffer
  for i as integer=0 to nSamples-1
    dim as single s=sin(w1+w2)
    dim as single c=cos(w2)
    *p=s*16000:p+=1
    *p=c*16000:p+=1
    w1+=6.28/44100.0*440
    w3+=6.28/44100.0*(10*sin(w4))
    w2+=6.28/44100.0*(880+sin(w3)*440)
    w4+=0.00001
  next
end sub


'
' main
'
dim as DS_DEVICE_LIST DeviceList
dim as DS_PRIMARY_BUFFER ptr pBuffer
' get list of none emulated DirectSound devices
DirectSoundEnumerate(@DSDeviceEnumCB,@DeviceList)
if DeviceList.nDevices>0 then
  for i as integer=0 to DeviceList.nDevices-1
    dprint("device(" & i & "):" & *DeviceList.pDevices[i] )
  next
  pBuffer = new DS_PRIMARY_BUFFER(44100,2,3,2048,DeviceList.pDevices[0]->getGuid())
  dim as integer PlayCursor,WriteCursor
  dim as short ptr pAudio1,pAudio2
  dim as integer Size1,Size2
  dim as integer counter,running=1
  while running 
    if len(inkey()) then running=0
    dim as DWORD ret = MsgWaitForMultipleObjects(pBuffer->getBuffers(),pBuffer->getEvents(),0,INFINITE,QS_POSTMESSAGE)
    if (running<>0) andalso (ret<pBuffer->getBuffers()) then
      dim as integer BufferIndex=(ret+1) mod pBuffer->getBuffers()
      dim as integer position=BufferIndex*pBuffer->getBuffersize()
      if pBuffer->LockPointers(position,@pAudio1,@Size1,@pAudio2,@Size2) then
        if pAudio1<>NULL then FillBuffer(pAudio1,Size1\pBuffer->getFramesize())
        if pAudio2<>NULL then FillBuffer(pAudio2,Size2\pBuffer->getFramesize())
        pBuffer->UnlockPointers(pAudio1,Size1,pAudio2,Size2)
      end if
    end if
  wend
  ' trigger destructor
  delete pBuffer
else
  dprint("sorry no hardware DirectSound device !")
end if
Last edited by D.J.Peters on Aug 26, 2014 2:52, edited 4 times in total.
Roland Chastain
Posts: 993
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: fbSound for linuxX86 win32 (wav mp3 ogg mod it xm s3m)

Post by Roland Chastain »

Hello D.J.Peters!

Here is the result of a test under Windows 8.1.
debug: DS_DEVICE_DESCRIPTOR()
debug: device(0):2BCBCF2C-D2DA-4DBE-AF8022B9CB9867C8 Son (Realtek High Definition Audio)
debug: DS_PRIMARY_BUFFER()
debug: create primary buffer ok
debug: get primary caps hw buffersize 32768 ok
debug: get primary format ok
debug: release primary buffer ok
debug: create primary buffer ok
debug: get secondary caps sw buffersize 49152 ok
debug: get secondary format ok
debug: get IID_IDirectSoundNotify ok
debug: m_pPositionNotify[0].dwOffset = 0
debug: m_pPositionNotify[1].dwOffset = 16384
debug: m_pPositionNotify[2].dwOffset = 32768
debug: IDirectSoundNotify_SetNotificationPositions ok
debug: secondary buffer looping ok
debug: DS_PRIMARY_BUFFER~
debug: IDirectSoundBuffer_Stop(m_pSecondaryBuffer)
debug: CloseHandle(m_phEvents[0])
debug: CloseHandle(m_phEvents[1])
debug: CloseHandle(m_phEvents[2])
debug: IDirectSoundNotify_Release(m_pSoundNotify)
debug: IDirectSoundBuffer_Release(m_pSecondaryBuffer)
debug: IDirectSound_Release(m_pDirectSound)
debug: DS_DEVICE_DESCRIPTOR~
debug: DS_DEVICE_LIST~
Last edited by Roland Chastain on Aug 26, 2014 6:02, edited 1 time in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: fbSound for linuxX86 win32 (wav mp3 ogg mod it xm s3m)

Post by D.J.Peters »

Thank you Roland do you got any sound also ?

Joshy
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: fbSound for linuxX86 win32 (wav mp3 ogg mod it xm s3m)

Post by VANYA »

Hi All!

windows 7:
debug: DS_DEVICE_DESCRIPTOR()
debug: device(0):1900CFFC-DFFB-436D-9D3A9E2AC03E0CEA Динамики (VIA High Definition Audio)
debug: DS_PRIMARY_BUFFER()
debug: create primary buffer ok
debug: get primary caps hw buffersize 32768 ok
debug: get primary format ok
debug: release primary buffer ok
debug: create secondary buffer ok
debug: get secondary caps sw buffersize 49152 ok
debug: get secondary format ok
debug: get IID_IDirectSoundNotify ok
debug: m_pPositionNotify[0].dwOffset = 0
debug: m_pPositionNotify[1].dwOffset = 16384
debug: m_pPositionNotify[2].dwOffset = 32768
debug: IDirectSoundNotify_SetNotificationPositions ok
debug: secondary buffer looping ok
debug: DS_PRIMARY_BUFFER~
debug: IDirectSoundBuffer_Stop(m_pSecondaryBuffer)
debug: CloseHandle(m_phEvents[0])
debug: CloseHandle(m_phEvents[1])
debug: CloseHandle(m_phEvents[2])
debug: IDirectSoundNotify_Release(m_pSoundNotify)
debug: IDirectSoundBuffer_Release(m_pSecondaryBuffer)
debug: IDirectSound_Release(m_pDirectSound)
I got the sound.
Last edited by VANYA on Aug 26, 2014 7:59, edited 1 time in total.
Roland Chastain
Posts: 993
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: fbSound for linuxX86 win32 (wav mp3 ogg mod it xm s3m)

Post by Roland Chastain »

D.J.Peters wrote:do you got any sound also ?
Yes, I got the sound.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: fbSound for linuxX86 win32 (wav mp3 ogg mod it xm s3m)

Post by fxm »

Windows XP (build 2600, Service Pack 3):
debug: DS_DEVICE_DESCRIPTOR()
debug: device(0):BD6DD71A-3DEB-11D1-B17100C04FC20001 Conexant HD Audio output
debug: DS_PRIMARY_BUFFER()
debug: create primary buffer ok
debug: get primary caps hw buffersize 32768 ok
debug: get primary format ok
debug: release primary buffer ok
debug: create secondary buffer ok
debug: get secondary caps sw buffersize 49152 ok
debug: get secondary format ok
debug: get IID_IDirectSoundNotify ok
debug: m_pPositionNotify[0].dwOffset = 0
debug: m_pPositionNotify[1].dwOffset = 16384
debug: m_pPositionNotify[2].dwOffset = 32768
debug: IDirectSoundNotify_SetNotificationPositions ok
debug: secondary buffer looping ok
debug: DS_PRIMARY_BUFFER~
debug: IDirectSoundBuffer_Stop(m_pSecondaryBuffer)
debug: CloseHandle(m_phEvents[0])
debug: CloseHandle(m_phEvents[1])
debug: CloseHandle(m_phEvents[2])
debug: IDirectSoundNotify_Release(m_pSoundNotify)
debug: IDirectSoundBuffer_Release(m_pSecondaryBuffer)
debug: IDirectSound_Release(m_pDirectSound)
debug: DS_DEVICE_DESCRIPTOR~
debug: DS_DEVICE_LIST~
Sound OK.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: fbSound for linuxX86 win32 (wav mp3 ogg mod it xm s3m)

Post by D.J.Peters »

All tested devices with 32KB memory must be the minimum specs. for a DirectSound compatible device.

Thank you for testing.

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

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

Post by D.J.Peters »

You can download and test fbSound version 0.19 :-)

Joshy
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

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

Post by angros47 »

Tested on my laptop, under windows xp (I haven't installed updates since 2007, so an old system). I hear the sound.
debug: DS_DEVICE_DESCRIPTOR()
debug: device(0):BD6DD71A-3DEB-11D1-B17100C04FC20000 Realtek AC97 Audio
debug: DS_PRIMARY_BUFFER()
debug: create primary buffer ok
debug: get primary caps hw buffersize 32768 ok
debug: get primary format ok
debug: release primary buffer ok
debug: create secondary buffer ok
debug: get secondary caps sw buffersize 49152 ok
debug: get secondary format ok
debug: get IID_IDirectSoundNotify ok
debug: m_pPositionNotify[0].dwOffset = 0
debug: m_pPositionNotify[1].dwOffset = 16384
debug: m_pPositionNotify[2].dwOffset = 32768
debug: IDirectSoundNotify_SetNotificationPositions ok
debug: secondary buffer looping ok
debug: DS_PRIMARY_BUFFER~
debug: IDirectSoundBuffer_Stop(m_pSecondaryBuffer)
debug: CloseHandle(m_phEvents[0])
debug: CloseHandle(m_phEvents[1])
debug: CloseHandle(m_phEvents[2])
debug: IDirectSoundNotify_Release(m_pSoundNotify)
debug: IDirectSoundBuffer_Release(m_pSecondaryBuffer)
debug: IDirectSound_Release(m_pDirectSound)
debug: DS_DEVICE_DESCRIPTOR~
debug: DS_DEVICE_LIST~
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

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

Post by D.J.Peters »

Thank you for testing the DirectSound driver plug-ds.dll is included now.

You can test fbsound0.19.zip it if you like.

Joshy
Post Reply