Liberty BASIC Community Forum
« Still need help sending float to dll »

Welcome Guest. Please Login or Register.
Dec 12th, 2017, 07:56am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Still need help sending float to dll  (Read 675 times)
Roger Thomas
Junior Member
ImageImage


member is offline

Avatar




Homepage PM


Posts: 71
xx Re: Still need help sending float to dll
« Reply #15 on: Jan 29th, 2017, 01:46am »

Haha, finally got what I wanted working. After all this it seems simple, why couldn't I figure this out. Thanks for the help. It gave me the boost I needed to do it. I knew Liberty could too!!!

I also had to modify the BASSChannelSetAttribute call for the QWORD change in the newer dll.

Code:
'nomainwin
    slide0 = 50
    slide1 = 50
    WindowWidth = 400
    WindowHeight = 290

    graphicbox #w.g0, 20, 20, 102, 19
    statictext #w.st01, "0", 20, 5, 10, 15
    statictext #w.st02, "50", 62, 5, 20, 15
    statictext #w.st03, "100", 102, 5, 20, 15

    open "Slide test" for graphics_nsb as #w
    hWindow = hwnd(#w)
    #w "trapclose [quit]"

    #w.st01 "!font arial 10"
    #w.st02 "!font arial 10"
    #w.st03 "!font arial 10"
    #w.g0 "down"
    #w.g0 "when leftButtonMove [mouse0]"
    #w.g0 "when leftButtonDown [mouse0]"
    #w.g0 "when characterInput [key0]"

    PluginDir$ = StartupDir$'normal startup directory.
    open PluginDir$+"Plugins\"+"bass.dll", for dll as #dxbass

    BASSresult = BASSInit(-1,44100,0,hWindow,0)
    Err = BassErrorGetCode("BASSInit")

    if BASSresult=0 then 'error
        Notice "There has been an error initializing Bass: Player will close."
        goto [quit]
    end if

    m$ = "C:\file.mp3"
    BASSFALSE = 0
    handle = BASSStreamCreateFile(BASSFALSE,m$,0,0,0)
    Err = BassErrorGetCode("BASSStreamCreateFile")'to get the errorcode

    if handle=0 then 'error
        Notice "There has been an error creating file: Player will close."
        goto [quit]
    end if
    restart = 0
    r = BASSChannelPlay(handle,restart)
    Err = BassErrorGetCode("BASSChannelPlay")'to get the errorcode

    goto [display]
    wait

[key0]
    key=asc(right$(Inkey$,1))
    if key=_VK_LEFT then slide0=slide0-1
    if key=_VK_RIGHT then slide0=slide0+1
    goto [display]

[mouse0]
    slide0 = MouseX
    goto [display]


[display]
    if slide0 > 100 then slide0 = 100
    if slide0 < 0 then slide0 = 0

    value=R4(slide0/100)
    BASS.ATTRIB.VOL = 2
    BASSresult = BASSChannelSetAttribute(handle,BASS.ATTRIB.VOL,value)
    Err = BassErrorGetCode("BASSChannelSetAttribute")
    #w.st02, str$(slide0)
    #w.g0 "fill lightgray"
    #w.g0 "line 0 8 120 8"
    for x=10 to 90 step 10
    #w.g0, "place ";x;" 16 ; north ; go 4"
    next
    for x=2 to 98 step 2
    #w.g0, "place ";x;" 16 ; north ; go 2"
    next

    #w.g0, "place ";slide0-4;" 0 ; boxfilled  ";slide0+4;" 17"

    wait

[quit]
    calldll #dxbass, "BASS_Free", result as ulong 'unactivate the dll
    close #dxbass
    close #w
    end

function BASSInit(device,freq,flags,win,clsid)
calldll #dxbass, "BASS_Init",_
                device as long,_
                freq as ulong,_
                flags as ulong,_
                win as long,_
                clsid as long,_
                result as long
BASSInit = result
end function

Function BASSStreamCreateFile(mem,filename$,offset,length,flags)
BASSStreamCreateFile = BASSStreamCreateFile64(mem,filename$,offset,0,length,0,flags)
end function

function BASSStreamCreateFile64(mem,filename$,offset,offset2,length,length2,flags)
calldll #dxbass, "BASS_StreamCreateFile",_
                mem as long,_
                filename$ as ptr,_
                offset as ulong,_
                offset2 as ulong,_
                length as ulong,_
                length2 as ulong,_
                flags as ulong,_
                result as long
BASSStreamCreateFile64 = result
end function

function BASSChannelPlay(hndle,restart)
calldll #dxbass, "BASS_ChannelPlay",_
                hndle as long,_
                restart as long,_
                result as long
BASSChannelPlay = result
end function

function BASSChannelSetAttribute(hndle,attrib,value)
calldll #dxbass, "BASS_ChannelSetAttribute",_
                hndle as long,_
                attrib as ulong,_
                value as ulong,_
                result as long
BASSChannelSetAttribute = result
end function

function BassErrorGetCode(BassId$)
BASS.OK = 0
calldll #dxbass, "BASS_ErrorGetCode",_
                result as long
BassErrorGetCode = result
SELECT CASE BassErrorGetCode
    CASE BASS.OK
        print "BASS.OK ";BassId$
    CASE else
        print "BASS.NOTOK: ";BassErrorGetCode;" ";BassId$
    END SELECT
end function

'bay6software Brent's single type conversion
Function R4( R8 )
' Converts a 64-bit Double to a 32-bit number.
    Struct local1, R4 As ULong
    Open "oleaut32" For DLL As #oleaut32
    CallDLL #oleaut32, "VarR4FromR8", _
        R8 As Double, local1 As Struct, _
        ret As Long
    Close #oleaut32
    R4 = local1.R4.struct
End Function

Function R8( R4 )
' Converts a 32-bit number to a 64-bit Double.
    Struct local1, R8 As Double
    Open "oleaut32" For DLL As #oleaut32
    CallDLL #oleaut32, "VarR8FromR4", _
        R4 As ULong, local1 As Struct, _
        ret As Long
    Close #oleaut32
    R8 = local1.R8.struct
End Function

 

You'll have to change the plugin directory to where your bass.dll is.

Thanks, Roger
« Last Edit: Jan 29th, 2017, 01:56am by Roger Thomas » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is online

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5585
xx Re: Still need help sending float to dll
« Reply #16 on: Jan 30th, 2017, 02:04am »

So to recap, if the dll demands a "single" or a "float" there are two things to do. Firstly specify the struct member or variable passed as a "ulong" secondly fill that struct member or variable with the R4() function's return value.

That way you are passing the correct number of bits in the correct format.

If you receive a "single" or "float" value put it through the R8() function to return it to it's normal Liberty representation.
User IP Logged

Roger Thomas
Junior Member
ImageImage


member is offline

Avatar




Homepage PM


Posts: 71
xx Re: Still need help sending float to dll
« Reply #17 on: Jan 30th, 2017, 07:49am »

I think so, there was already some other calls in the older dll that used floats that I had already done this way.
It might be a little different according to the call, but they all should be similar to this.

This was one of the things that was holding me back from advancing my player. I was thinking about finding a different dll.
I didn't want to keep going with it only to find out later that I reach a part that couldn't be done.
It had been a while since I had attempted the newer dll.

I just got through converting all the calls that needed to be in my player and now its using the newest dll!!!grin
I still need to test it a little more.

Thanks for all the help and giving me the boost to attempt it again!!!
You don't know how many times I've tackled this.
I have no doubt the rest of it can be done now. grin

Roger
User IP Logged

Brandon Parker
Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1120
xx Re: Still need help sending float to dll
« Reply #18 on: Jan 30th, 2017, 5:08pm »

Sorry I was absent for a while there....

I feel like I set you up and then disappeared; sorry about that.

It's fantastic that you got it all working; it does really seem simple once you figure it out doesn't it.


{:0)

Brandon
« Last Edit: Jan 30th, 2017, 5:08pm by Brandon Parker » User IP Logged

Windows 7 Home Premium 64-bit Intel(R) Quad Core(TM) i5 CPU M 430 @ 2.27GHz 4GB DDR3 RAM
Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls