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

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


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 676 times)
Roger Thomas
Junior Member
ImageImage


member is offline

Avatar




Homepage PM


Posts: 71
xx Still need help sending float to dll
« Thread started on: Jan 28th, 2017, 12:23am »

I'm still trying to figure out how to do this. I still don't understand it or something.

Here's part of the code that I am trying to it with. You would still have to initialize the dll and all that to get this to work, so I added a few comments with the values that is returned to give some understanding of what is going on.
Code:
struct ATTVALUE, value$ as ptr

[GetVolume]
BASSresult = BASSChannelGetAttribute(StreamHandle,BASS.ATTRIB.VOL,ATTVALUE)

floatvalue$ = ATTVALUE.value$.struct
value$ = Trim$(Using("################.#", fromFloat(val(floatvalue$))))
print "value$ ";ATTVALUE.value$.struct'reads 1065353216 in the program
print "value$ ";value$'reads 1.0 in the program
wait

[SetVolume]
value$ = Trim$(Using("################", toFloat(val(value$))))
print value$'returns 1065353216 in the program: same as ATTVALUE.value$.struct but will not set the volume
BASSresult = BASSChannelSetAttribute(StreamHandle,BASS.ATTRIB.VOL,value$)
wait

function BASSChannelGetAttribute(hndle,attrib,ATTVALUE)
calldll #bass, "BASS_ChannelGetAttribute",_
                hndle as long,_
                attrib as ulong,_
                ATTVALUE as struct,_
                result as long
BASSChannelGetAttribute = result
end function

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

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

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


Thanks, Roger
User IP Logged

Dan Teel
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1130
xx Re: Still need help sending float to dll
« Reply #1 on: Jan 28th, 2017, 12:46am »

I've never had any luck with using doubles with DLL's, I would also be curious if anyone else has.
User IP Logged

ZPtr.net
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

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

We need to check a few things out. It would be much easier if you could post Liberty code that opened the bass.dll and played a sample, perhaps with your attempt at volume control.

But here is the docs

Quote:
Retrieves the value of a channel's attribute.

BOOL BASS_ChannelGetAttribute(
DWORD handle,
DWORD attrib,
float *value
);

Parameters
handle
The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD.
attrib
The attribute to get the value of... one of the following.
BASS_ATTRIB_EAXMIX
EAX wet/dry mix. (HCHANNEL/HMUSIC/HSTREAM only)
BASS_ATTRIB_BITRATE
Average bitrate. (HSTREAM)
BASS_ATTRIB_CPU
CPU usage. (HMUSIC/HSTREAM)
BASS_ATTRIB_FREQ
Sample rate.
BASS_ATTRIB_MUSIC_ACTIVE
Active channel count. (HMUSIC)
BASS_ATTRIB_MUSIC_AMPLIFY
Amplification level. (HMUSIC)
BASS_ATTRIB_MUSIC_BPM
BPM. (HMUSIC)
BASS_ATTRIB_MUSIC_PANSEP
Pan separation level. (HMUSIC)
BASS_ATTRIB_MUSIC_PSCALER
Position scaler. (HMUSIC)
BASS_ATTRIB_MUSIC_SPEED
Speed. (HMUSIC)
BASS_ATTRIB_MUSIC_VOL_CHAN
A channel volume level. (HMUSIC)
BASS_ATTRIB_MUSIC_VOL_GLOBAL
Global volume level. (HMUSIC)
BASS_ATTRIB_MUSIC_VOL_INST
An instrument/sample volume level. (HMUSIC)
BASS_ATTRIB_NET_RESUME
Buffer level to resume stalled playback. (HSTREAM)
BASS_ATTRIB_NOBUFFER
Playback buffering switch. (HMUSIC/HSTREAM)
BASS_ATTRIB_NORAMP
Playback ramping switch.
BASS_ATTRIB_PAN
Panning/balance position.
BASS_ATTRIB_SRC
Sample rate conversion quality.
BASS_ATTRIB_VOL
Volume level.
other attributes may be supported by add-ons, see the documentation.
value
Pointer to a variable to receive the attribute value.

Return value
If successful, then TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code.



You can see that the call to the dll sends two doublewords, as parameters, the channel handle and the attribute you wish to set or check. In this case BASS_ATTRIB_VOL. This is actually a constant and is numeric 2. Firstly have you set that as constant in your program and set it to the value 2?
The call returns a numeric value but you have set the struct up to receive a string. In Brents functions you would normally pass in numeric data and receive numeric data,all as ulong types but internally the ulong will look like a float type.

Any chance of some extract code to open and play a sample?

User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5585
xx Re: Still need help sending float to dll
« Reply #3 on: Jan 28th, 2017, 05:42am »

Also this is worth aread. http://libertybasic.conforums.com/index.cgi?board=api&action=display&num=1156254588&start=15
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5585
xx Re: Still need help sending float to dll
« Reply #4 on: Jan 28th, 2017, 08:45am »

Some progress but it isn't right yet. The volume changes but the values are not correct.

Out of time just now but if anyone can see what is wrong with my attempt at forming and reading a "single" value to pass to and from the .dll please shout. Everything works apart from the fact that the vol value is missed up, perhaps I have the functions back to front.

The volume value between 0 and 1 should be passed as a single type, four bytes, it comes back as a single but since liberty does not support single values we need Brents conversions.

Code:
open "bass.dll", for dll as #dxbass

calldll #dxbass, "BASS_Init", -1 as ulong, 44100 as ulong,_
0 as ulong, 0 as ulong, 0 as ulong, result as long

if result=0 then 'error
calldll #dxbass, "BASS_ErrorGetCode", e as short
close #dxbass
print "error code : ";e
end if

calldll #dxbass, "BASS_SampleLoad", 0 as ulong, "test.mp3" as ptr,_
0 as ulong, 0 as ulong, 0 as ulong, 1 as ulong, 0 as ulong, handle as ulong

if handle=0 then 'error
calldll #dxbass, "BASS_ErrorGetCode", e as short 'to get the errorcode
close #dxbass
print "error code : ";e
end if



calldll #dxbass, "BASS_SampleGetChannel", handle as ulong, 0 as ulong, channel as ulong




calldll #dxbass, "BASS_ChannelPlay", channel as ulong, 0 as ulong, r as ulong
print "playing: ";r

[check]
input "press 1 or 2 or 3"; chk$
if chk$="1" then
    vol=R4(.5)
    calldll #dxbass, "BASS_SetVolume", vol as ulong, result as long
end if
if chk$="2" then
    vol=R4(1)
    calldll #dxbass, "BASS_SetVolume", vol as ulong, result as long
end if
if chk$="3" then
    calldll #dxbass, "BASS_Free", result as boolean 'unactivate the dll
    close #dxbass
    print "program ended"
    end
end if
calldll #dxbass, "BASS_GetVolume", vol as ulong
vol=R8(vol)
print "Volume=";vol
print
goto [check]


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

 


VB defs
Quote:
Declare Function BASS_SetVolume Lib "bass.dll" (ByVal volume As Single) As Long
Declare Function BASS_GetVolume Lib "bass.dll" () As Single

« Last Edit: Jan 28th, 2017, 08:50am by Rod » 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 #5 on: Jan 28th, 2017, 09:46am »

on Jan 28th, 2017, 04:22am, Rod wrote:
Firstly have you set that as constant in your program and set it to the value 2?


Yea, I have the constants set up.

Quote:
Any chance of some extract code to open and play a sample?


Looks like you already initialized everything below, so probably don't need this now.
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 #6 on: Jan 28th, 2017, 09:51am »

on Jan 28th, 2017, 08:45am, Rod wrote:
Some progress but it isn't right yet. The volume changes but the values are not correct.

Out of time just now but if anyone can see what is wrong with my attempt at forming and reading a "single" value to pass to and from the .dll please shout. Everything works apart from the fact that the vol value is missed up, perhaps I have the functions back to front.

The volume value between 0 and 1 should be passed as a single type, four bytes, it comes back as a single but since liberty does not support single values we need Brents conversions.

Code:
open "bass.dll", for dll as #dxbass

calldll #dxbass, "BASS_Init", -1 as ulong, 44100 as ulong,_
0 as ulong, 0 as ulong, 0 as ulong, result as long

if result=0 then 'error
calldll #dxbass, "BASS_ErrorGetCode", e as short
close #dxbass
print "error code : ";e
end if

calldll #dxbass, "BASS_SampleLoad", 0 as ulong, "test.mp3" as ptr,_
0 as ulong, 0 as ulong, 0 as ulong, 1 as ulong, 0 as ulong, handle as ulong

if handle=0 then 'error
calldll #dxbass, "BASS_ErrorGetCode", e as short 'to get the errorcode
close #dxbass
print "error code : ";e
end if



calldll #dxbass, "BASS_SampleGetChannel", handle as ulong, 0 as ulong, channel as ulong




calldll #dxbass, "BASS_ChannelPlay", channel as ulong, 0 as ulong, r as ulong
print "playing: ";r

[check]
input "press 1 or 2 or 3"; chk$
if chk$="1" then
    vol=R4(.5)
    calldll #dxbass, "BASS_SetVolume", vol as ulong, result as long
end if
if chk$="2" then
    vol=R4(1)
    calldll #dxbass, "BASS_SetVolume", vol as ulong, result as long
end if
if chk$="3" then
    calldll #dxbass, "BASS_Free", result as boolean 'unactivate the dll
    close #dxbass
    print "program ended"
    end
end if
calldll #dxbass, "BASS_GetVolume", vol as ulong
vol=R8(vol)
print "Volume=";vol
print
goto [check]


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

 


VB defs



I'll check this out later. Better than what I came up with. I was getting fatigued trying to find a solution I hadn't tried yet.

I'll see what I can do with this one.

Thanks, Roger
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5585
xx Re: Still need help sending float to dll
« Reply #7 on: Jan 28th, 2017, 12:12pm »

OK This is working and controls the master volume of the default sound device. You can experiment with channel specific volume yourself.

I have not had time to get the return value converted but Brent's functions will do the trick.

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
    #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]"


    open "bass.dll", for dll as #dxbass

    calldll #dxbass, "BASS_Init", -1 as ulong, 44100 as ulong,_
    0 as ulong, 0 as ulong, 0 as ulong, result as long

    if result=0 then 'error
        calldll #dxbass, "BASS_ErrorGetCode", e as short
        close #dxbass
        print "error code : ";e
    end if

    calldll #dxbass, "BASS_SampleLoad", 0 as ulong, "test.mp3" as ptr,_
    0 as ulong, 0 as ulong, 0 as ulong, 1 as ulong, 0 as ulong, handle as ulong

    if handle=0 then 'error
        calldll #dxbass, "BASS_ErrorGetCode", e as short 'to get the errorcode
        close #dxbass
        print "error code : ";e
    end if

    calldll #dxbass, "BASS_SampleGetChannel", handle as ulong, 0 as ulong, channel as ulong
    calldll #dxbass, "BASS_ChannelPlay", channel as ulong, 0 as ulong, r as ulong
    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

    vol=R4(slide0/100)
    calldll #dxbass, "BASS_SetVolume", vol as ulong, result as long
    #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

'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


 
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 #8 on: Jan 28th, 2017, 12:22pm »

I'll check that out right now.

Thanks.
User IP Logged

Colin McMurchie
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 226
xx Re: Still need help sending float to dll
« Reply #9 on: Jan 28th, 2017, 12:22pm »

Hi Roger,

I am not sure this will work, it depends perhaps on your other code, but look at this.

http://libertybasic.conforums.com/index.cgi?board=LB3&num=1082167646&action=display&start=15

It is a conversion function, in native LB, that takes an LB numeric variable and converts it into 32 bit single float form. It may be what you need.

Bear in mind that it is from 2004. I have not tested it lately, so ther may be some adjustments needed with LB 4.5

Colin McMurchie
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 #10 on: Jan 28th, 2017, 1:13pm »

on Jan 28th, 2017, 12:12pm, Rod wrote:
OK This is working and controls the master volume of the default sound device. You can experiment with channel specific volume yourself.

I have not had time to get the return value converted but Brent's functions will do the trick.

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
    #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]"


    open "bass.dll", for dll as #dxbass

    calldll #dxbass, "BASS_Init", -1 as ulong, 44100 as ulong,_
    0 as ulong, 0 as ulong, 0 as ulong, result as long

    if result=0 then 'error
        calldll #dxbass, "BASS_ErrorGetCode", e as short
        close #dxbass
        print "error code : ";e
    end if

    calldll #dxbass, "BASS_SampleLoad", 0 as ulong, "test.mp3" as ptr,_
    0 as ulong, 0 as ulong, 0 as ulong, 1 as ulong, 0 as ulong, handle as ulong

    if handle=0 then 'error
        calldll #dxbass, "BASS_ErrorGetCode", e as short 'to get the errorcode
        close #dxbass
        print "error code : ";e
    end if

    calldll #dxbass, "BASS_SampleGetChannel", handle as ulong, 0 as ulong, channel as ulong
    calldll #dxbass, "BASS_ChannelPlay", channel as ulong, 0 as ulong, r as ulong
    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

    vol=R4(slide0/100)
    calldll #dxbass, "BASS_SetVolume", vol as ulong, result as long
    #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

'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


 


Thanks, I didn't even notice "BASS_SetVolume" in the initialization section where I was working with streams and channels.
This seems to mean that it can be done as I will have to look at some of the other functions in bass.dll that use float to see if I can keep using this dll.
This makes it look promising.

Thanks a lot.

Roger
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 #11 on: Jan 28th, 2017, 1:15pm »

on Jan 28th, 2017, 12:22pm, Colin McMurchie wrote:
Hi Roger,

I am not sure this will work, it depends perhaps on your other code, but look at this.

http://libertybasic.conforums.com/index.cgi?board=LB3&num=1082167646&action=display&start=15

It is a conversion function, in native LB, that takes an LB numeric variable and converts it into 32 bit single float form. It may be what you need.

Bear in mind that it is from 2004. I have not tested it lately, so ther may be some adjustments needed with LB 4.5

Colin McMurchie


Thanks, I'll read up on this.

Roger
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 #12 on: Jan 28th, 2017, 3:20pm »

Since we've came this far, I just thought I would add that I have already been setting a float in my player for the equalizer. I has been a little while since I worked that out and everytime I would look at it, it seems I would lose my memory. ;D

Not asking for more help on this. Just thought I would mention it.
I used arrays and structs like this.

Code:
    struct BASSFXPARAMEQ,fCenter As ulong,fBandwidth As ulong,fGain As ulong

    gain(12) = gain
    center(12) = 16000
    Bandwidth = toFloat(16)
    Bandwidth(12) = Bandwidth
    BASSFXPARAMEQ.fBandwidth.struct = Bandwidth
    BASSFXPARAMEQ.fGain.struct = toFloat(gain)
    BASSFXPARAMEQ.fCenter.struct = toFloat(16000)
    FXSetParameters = BASSFXSetParameters(fx(12),BASSFXPARAMEQ)


function BASSFXSetParameters(hndle,BASSFXPARAMEQ)
calldll #bass, "BASS_FXSetParameters",_
                hndle as ulong,_
                BASSFXPARAMEQ as struct,_
                result as long
BASSFXSetParameters = result
end function
 


I seems like something is different with some of the float calls in this dll, but I may look in to something like this for the BASSChannelSetAttribute function.

The above is an actual part of code from my player that works, so.
I can't give too much of my hard studying. ;)
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 #13 on: Jan 28th, 2017, 8:15pm »

Quote:
Code:
    struct BASSFXPARAMEQ,fCenter As ulong,fBandwidth As ulong,fGain As ulong

    gain(12) = gain
    center(12) = 16000
    Bandwidth = toFloat(16)
    Bandwidth(12) = Bandwidth
    BASSFXPARAMEQ.fBandwidth.struct = Bandwidth
    BASSFXPARAMEQ.fGain.struct = toFloat(gain)
    BASSFXPARAMEQ.fCenter.struct = toFloat(16000)
    FXSetParameters = BASSFXSetParameters(fx(12),BASSFXPARAMEQ)


function BASSFXSetParameters(hndle,BASSFXPARAMEQ)
calldll #bass, "BASS_FXSetParameters",_
                hndle as ulong,_
                BASSFXPARAMEQ as struct,_
                result as long
BASSFXSetParameters = result
end function 


The float is in the structure on this call so this is not the same as BASSChannelSetAttribute call, so back to the drawing board.

Quote:
I can't give too much of my hard studying. ;)


I was just joking. If I ever get it working I'll post it here to save someone else the headache.

Roger
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 #14 on: Jan 28th, 2017, 9:51pm »

on Jan 28th, 2017, 12:12pm, Rod wrote:
OK This is working and controls the master volume of the default sound device. You can experiment with channel specific volume yourself.

I have not had time to get the return value converted but Brent's functions will do the trick.

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
    #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]"


    open "bass.dll", for dll as #dxbass

    calldll #dxbass, "BASS_Init", -1 as ulong, 44100 as ulong,_
    0 as ulong, 0 as ulong, 0 as ulong, result as long

    if result=0 then 'error
        calldll #dxbass, "BASS_ErrorGetCode", e as short
        close #dxbass
        print "error code : ";e
    end if

    calldll #dxbass, "BASS_SampleLoad", 0 as ulong, "test.mp3" as ptr,_
    0 as ulong, 0 as ulong, 0 as ulong, 1 as ulong, 0 as ulong, handle as ulong

    if handle=0 then 'error
        calldll #dxbass, "BASS_ErrorGetCode", e as short 'to get the errorcode
        close #dxbass
        print "error code : ";e
    end if

    calldll #dxbass, "BASS_SampleGetChannel", handle as ulong, 0 as ulong, channel as ulong
    calldll #dxbass, "BASS_ChannelPlay", channel as ulong, 0 as ulong, r as ulong
    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

    vol=R4(slide0/100)
    calldll #dxbass, "BASS_SetVolume", vol as ulong, result as long
    #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

'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


 


Hey, I got BASSChannelSetAttribute working following your example here. I'm not sure if its working right yet but it changed the volume.

As soon as I go through it, clean the code up and see how it works, I'll post a snippet here.

Thanks for the help to everyone.
Roger
User IP Logged

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