For someone looking for similar problem solution (may be i found not best 
solution, please correct me if i wrong):

Looks like this header is too complex for c2nim (or i am not familyar with 
c/nim/c2nim) So, i find another way for it. I write small header for 
basslib.so, convert it 2 nim with c2nim, and look at generated code and write 
nim wrapper manualy

So, wraper looks like:
    
    
    {.deadCodeElim: on.}
    ## # Dynamically link to the correct library for our system:
    
    when defined(windows):
      const
        basslib* = "libbass.dll"
    elif defined(macosx):
      const
        basslib* = "libbass.dylib"
    else:
      const
        basslib* = "libbass.so"
    
    template HIWORD*(a: expr): expr =
      (WORD)((a) shr 16)
    
    type
      DWORD* = uint32
      WORD* = uint16
      QWORD* = uint64
      BOOL* = cint
      HSTREAM* = DWORD
      
      BASS_INFO* = object
        flags*: DWORD              ## # device capabilities (DSCAPS_xxx flags)
        hwsize*: DWORD             ## # size of total device hardware memory
        hwfree*: DWORD             ## # size of free device hardware memory
        freesam*: DWORD            ## # number of free sample slots in the 
hardware
        free3d*: DWORD             ## # number of free 3D sample slots in the 
hardware
        minrate*: DWORD            ## # min sample rate supported by the 
hardware
        maxrate*: DWORD            ## # max sample rate supported by the 
hardware
        eax*: BOOL                 ## # device supports EAX? (always FALSE if 
BASS_DEVICE_3D was not used)
        minbuf*: DWORD             ## # recommended minimum buffer length in ms 
(requires BASS_DEVICE_LATENCY)
        dsver*: DWORD              ## # DirectSound version
        latency*: DWORD            ## # delay (in ms) before start of playback 
(requires BASS_DEVICE_LATENCY)
        initflags*: DWORD          ## # BASS_Init "flags" parameter
        speakers*: DWORD           ## # number of speakers available
        freq*: DWORD               ## # current output rate
    
    proc BASS_GetDeviceInfo*(device:DWORD,info:object):BOOL {.importc, dynlib: 
basslib}
    proc BASS_GetVersion*():DWORD {.importc, dynlib: basslib}
    proc BASS_Init*(device:int, freq:DWORD,  flags:DWORD, win: pointer; dsguid: 
pointer): BOOL {.importc, dynlib: basslib}
    proc BASS_StreamCreateFile*(mem: BOOL; file: cstring; offset: QWORD; 
length: QWORD; flags: DWORD): HSTREAM {.cdecl,
        importc: "BASS_StreamCreateFile", dynlib: basslib.}
    proc BASS_ChannelPlay*(handle: DWORD; restart: BOOL): BOOL {.cdecl,
        importc: "BASS_ChannelPlay", dynlib: basslib.}
    proc BASS_ChannelIsActive*(handle: DWORD): BOOL {.importc, dynlib: basslib}
    proc BASS_Free*(): BOOL {.importc, dynlib: basslib}
    

And usage of library now pretty simple (dummy example playing file):
    
    
    import bass,os
    
    echo "version:",HIWORD(BASS_GetVersion())
    var info:BASS_INFO
    discard BASS_GetDeviceInfo(0,info)
    echo "freq",info.freq
    let init = BASS_Init(-1,44100,0,nil,nil)
    echo "init bass:",init
    let filename = "/Users/recoilme/Music/01.mp3"
    let chan=BASS_StreamCreateFile(0,filename,0,0,0);
    echo "channel:",chan
    let play = BASS_ChannelPlay(chan,0)
    while BASS_ChannelIsActive(chan)>0:
      sleep 50
    discard BASS_Free
    

Reply via email to