Sign in to follow this  
Followers 0
Simucal

Porting Fmod Sound Library To Autoit

8 posts in this topic

#1 ·  Posted (edited)

In order to get DJDeep's BPM script up and running.. it requires several DLL calls to fmod.dll.

Is there anyone who can help me convert these Visual Basic DLL Functions to autoit?

Public Declare Function FSOUND_DSP_GetSpectrum Lib "fmod.dll" Alias "_FSOUND_DSP_GetSpectrum@0" () As Long

Public Declare Function FSOUND_Stream_Open Lib "fmod.dll" Alias "_FSOUND_Stream_Open@16" (ByVal fileName As String, ByVal mode As FSOUND_MODES, ByVal offset As Long, ByVal length As Long) As Long

Public Declare Function FSOUND_Stream_Play Lib "fmod.dll" Alias "_FSOUND_Stream_Play@8" (ByVal Channel As Long, ByVal stream As Long) As Long

Public Declare Function FSOUND_DSP_Create Lib "fmod.dll" Alias "_FSOUND_DSP_Create@12" (ByVal callback As Long, ByVal Priority As Long, ByVal param As Long) As Long

Public Declare Function FSOUND_Stream_Stop Lib "fmod.dll" Alias "_FSOUND_Stream_Stop@4" (ByVal stream As Long) As Byte

Public Declare Function FSOUND_DSP_SetActive Lib "fmod.dll" Alias "_FSOUND_DSP_SetActive@8" (ByVal unit As Long, ByVal active As Integer) As Long

Public Declare Function FSOUND_DSP_Free Lib "fmod.dll" Alias "_FSOUND_DSP_Free@4" (ByVal unit As Long) As Long

Public Declare Function FSOUND_Stream_Close Lib "fmod.dll" Alias "_FSOUND_Stream_Close@4" (ByVal stream As Long) As Byte

Public Declare Function FSOUND_Init Lib "fmod.dll" Alias "_FSOUND_Init@12" (ByVal mixrate As Long, ByVal maxchannels As Long, ByVal Flags As FSOUND_INITMODES) As Byte

Public Declare Function FSOUND_Stream_Stop Lib "fmod.dll" Alias "_FSOUND_Stream_Stop@4" (ByVal stream As Long) As Byte

FSOUND_Modes is a VB enumeration:

Public Enum FSOUND_MODES

FSOUND_LOOP_OFF = 1 ' For non looping samples.

FSOUND_LOOP_NORMAL = 2 ' For forward looping samples.

FSOUND_LOOP_BIDI = 4 ' For bidirectional looping samples. (no effect if in hardware).

FSOUND_8BITS = 8 ' For 8 bit samples.

FSOUND_16BITS = 16 ' For 16 bit samples.

FSOUND_MONO = 32 ' For mono samples.

FSOUND_STEREO = 64 ' For stereo samples.

FSOUND_UNSIGNED = 128 ' For source data containing unsigned samples.

FSOUND_SIGNED = 256 ' For source data containing signed data.

FSOUND_DELTA = 512 ' For source data stored as delta values.

FSOUND_IT214 = 1024 ' For source data stored using IT214 compression.

FSOUND_IT215 = 2048 ' For source data stored using IT215 compression.

FSOUND_HW3D = 4096 ' Attempts to make samples use 3d hardware acceleration. (if the card supports it)

fsound_2d = 8192 ' Ignores any 3d processing. overrides FSOUND_HW3D. Located in software.

FSOUND_STREAMABLE = 16384 ' For realtime streamable samples. If you dont supply this sound may come out corrupted.

FSOUND_LOADMEMORY = 32768 ' For FSOUND_Sample_Load - name will be interpreted as a pointer to data

FSOUND_LOADRAW = 65536 ' For FSOUND_Sample_Load/FSOUND_Stream_Open - will ignore file format and treat as raw pcm.

FSOUND_MPEGACCURATE = 131072 ' For FSOUND_Stream_Open - scans MP2/MP3 (VBR also) for accurate FSOUND_Stream_GetLengthMs/FSOUND_Stream_SetTime.

FSOUND_FORCEMONO = 262144 ' For forcing stereo streams and samples to be mono - needed with FSOUND_HW3D - incurs speed hit

FSOUND_HW2D = 524288 ' 2d hardware sounds. allows hardware specific effects

FSOUND_ENABLEFX = 1048576 ' Allows DX8 FX to be played back on a sound. Requires DirectX 8 - Note these sounds cant be played more than once, or have a changing frequency

FSOUND_MPEGHALFRATE = 2097152 ' For FMODCE only - decodes mpeg streams using a lower quality decode, but faster execution

FSOUND_XADPCM = 4194304 ' For XBOX only - Describes a user sample that its contents are compressed as XADPCM

FSOUND_VAG = 8388608 ' For PS2 only - Describes a user sample that its contents are compressed as Sony VAG format.

FSOUND_NONBLOCKING = 16777216 ' For FSOUND_Stream_OpenFile - Causes stream to open in the background and not block the foreground app - stream plays only when ready.

FSOUND_GCADPCM = &H2000000 ' For Gamecube only - Contents are compressed as Gamecube DSP-ADPCM format */

FSOUND_MULTICHANNEL = &H4000000 ' For PS2 only - Contents are interleaved into a multi-channel (more than stereo) format */

FSOUND_USECORE0 = &H8000000 ' For PS2 only - Sample/Stream is forced to use hardware voices 00-23 */

FSOUND_USECORE1 = &H10000000 ' For PS2 only - Sample/Stream is forced to use hardware voices 24-47 */

FSOUND_LOADMEMORYIOP = &H20000000 ' For PS2 only - "name" will be interpreted as a pointer to data for streaming and samples. The address provided will be an IOP address

FSOUND_STREAM_NET = &H80000000 ' Specifies an internet stream

FSOUND_NORMAL = FSOUND_16BITS Or FSOUND_SIGNED Or FSOUND_MONO

End Enum

and same with FSOUND_INITMODES:

Public Enum FSOUND_INITMODES

FSOUND_INIT_USEDEFAULTMIDISYNTH = &H1 'Causes MIDI playback to force software decoding.

FSOUND_INIT_GLOBALFOCUS = &H2 'For DirectSound output - sound is not muted when window is out of focus.

FSOUND_INIT_ENABLEOUTPUTFX = &H4 'For DirectSound output - Allows FSOUND_FX api to be used on global software mixer output!

FSOUND_INIT_ACCURATEVULEVELS = &H8 'This latency adjusts FSOUND_GetCurrentLevels, but incurs a small cpu and memory hit

FSOUND_INIT_PS2_DISABLECORE0REVERB = &H10 'PS2 only - Disable reverb on CORE 0 to regain SRAM

FSOUND_INIT_PS2_DISABLECORE1REVERB = &H20 'PS2 only - Disable reverb on CORE 1 to regain SRAM

FSOUND_INIT_PS2_SWAPDMACORES = &H40 'PS2 only - By default FMOD uses DMA CH0 for mixing, CH1 for uploads, this flag swaps them around

FSOUND_INIT_DONTLATENCYADJUST = &H80 'Callbacks are not latency adjusted, and are called at mix time. Also information functions are immediate

FSOUND_INIT_GC_INITLIBS = &H100 'Gamecube only - Initializes GC audio libraries

FSOUND_INIT_STREAM_FROM_MAIN_THREAD = &H200 'Turns off fmod streamer thread, and makes streaming update from FSOUND_Update called by the user

End Enum

These 10 functions are the only ones we would presently need converted.. however, once those were finished it would be easy to convert the rest of them (a few hundred) and have a fully working FMOD Sound Library port to autoit (Which would allow for some fairly advanced audio scripts).

If someone did one.. I could go from there.

I think it would be something like a series of:

Func FSOUND_Stream_Play(ByVal $fileName As String, ByVal mode As $FSOUND_MODES, ByVal $offset As Long, ByVal $length As Long)

DllCall("fmod.dll", Long, "FSOUND_Stream_Play", ByVal $fileName As String, ByVal mode As $FSOUND_MODES, ByVal $offset As Long, ByVal $length As Long)

EndFunc

That is a very clunky pseudo code. If anyone can illuminate what one should look like, it would be very helpful.

fmod.dll

Edited by Simucal

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites



I (think) I can get you started:

Public Declare Function FSOUND_DSP_GetSpectrum Lib "fmod.dll" Alias "_FSOUND_DSP_GetSpectrum@0" () As Long

Translation: DllCall ("fmod.dll", "long", "FSOUND_DSP_GetSpectrum")

Public Declare Function FSOUND_Stream_Open Lib "fmod.dll" Alias "_FSOUND_Stream_Open@16" (ByVal fileName As String, ByVal mode As FSOUND_MODES, ByVal offset As Long, ByVal length As Long) As Long

First steps: $FileNameString = "path to file"

$ModeStruct = DllStructCreate ("int" ...) ; make struct of all modes (each one is an int i think.. maybe uint), then DllStructSetData for each mode value. Easiest to make it an array (but I'm not sure if it'll work.. I'm really not that familiar with DllCalls)

Translation: DllCall ("fmod.dll", "long", "FSOUND_Stream_Open", "str", $FileNameString, "ptr", DllStructGetPtr ($ModeStruct), "long", $Offset, "long", $Length)

I think that should be a start. I may have made some mistakes, but it shouldn't be anything that can't be fixed.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

greenmachine,

That is very helpful indeed. Is there anychance you can throw together an example for the second one on the list? If I could get that one.. I should be able to get them all.

Edited by Simucal

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

This may or may not work (I don't have the Dll, so I can't test), but it seems like the general idea.

$ModeStruct = DllStructCreate ("uint[32]")
For $i = 0 To 29
    DllStructSetData ($ModeStruct, $i, 2^$i)
Next
DllStructSetData ($ModeStruct, 30, 0x80000000)
DllStructSetData ($ModeStruct, 31, BitOR (16, 256, 32))

Func CallThisDLL($FileNameString, $ModeStruct, $Offset, $Length)
    $Return = DllCall ("fmod.dll", "long", "FSOUND_Stream_Open", "str", $FileNameString, "ptr", DllStructGetPtr ($ModeStruct), "long", $Offset, "long", $Length)
    If @error Then MsgBox (0, "Error", "Dll Call failed with code: " & @error)
    Return $Return
EndFunc

I made it into a func so you can call it with your own stuff and I don't have to make up an example for a file that doesn't exist.

Share this post


Link to post
Share on other sites

@GreenMachine,

Hey mate, I'm still attempting to get these 10 dll calls ported. I wanted to ask you a couple questions about the example you posted:

$ModeStruct = DllStructCreate ("uint[32]")
For $i = 0 To 29
    DllStructSetData ($ModeStruct, $i, 2^$i)
Next
DllStructSetData ($ModeStruct, 30, 0x80000000)
DllStructSetData ($ModeStruct, 31, BitOR (16, 256, 32))

Func CallThisDLL($FileNameString, $ModeStruct, $Offset, $Length)
    $Return = DllCall ("fmod.dll", "long", "FSOUND_Stream_Open", "str", $FileNameString, "ptr", DllStructGetPtr ($ModeStruct), "long", $Offset, "long", $Length)
    If @error Then MsgBox (0, "Error", "Dll Call failed with code: " & @error)
    Return $Return
EndFunc

Firstly, Can you describe your DllStructCreate to me? And its corresponding SetData? I've read.. and re-read the help file on DllStructCreate and DllStructSetData and I'm still a little lost.

Am I going to have a series of StructCreates/SetData's for each DLL call I am making? Is there any general literature you can point me to .. to help me in my endevor other than the help file? Thanks,

-Simucal


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

Well, I honestly was just guessing there. The struct is a collection of the modes (I used unsigned integers so they could hold large enough values). So DllStructCreate creates the struct - an array of unsigned ints. Then, in order to get the struct to have anything in it, I used DllStructSetData on each location in the array to match it with the enumeration of the modes you gave. You only need the struct when the dll call requires it.

The struct for InitModes is:

$InitModesStruct = DllStructCreate ("int[10]")
For $i = 0 to 9
    DllStructSetData ($InitModesStruct, $i, 2^$i)
Next

I only used the helpfile, so I'd still reccommend it. Of course, MSDN may be useful, but it also could just be more confusing.

Share this post


Link to post
Share on other sites

Well, I honestly was just guessing there. The struct is a collection of the modes (I used unsigned integers so they could hold large enough values). So DllStructCreate creates the struct - an array of unsigned ints. Then, in order to get the struct to have anything in it, I used DllStructSetData on each location in the array to match it with the enumeration of the modes you gave. You only need the struct when the dll call requires it.

The struct for InitModes is:

$InitModesStruct = DllStructCreate ("int[10]")
For $i = 0 to 9
    DllStructSetData ($InitModesStruct, $i, 2^$i)
Next

I only used the helpfile, so I'd still reccommend it. Of course, MSDN may be useful, but it also could just be more confusing.

Did you guys give up? Any sample code, that can I play around with?...Guys?

Share this post


Link to post
Share on other sites

Settings up DLL Structs and their corresponding calls in AutoIt is a little beyond me at the moment. I'm looking into it, but right now most of my time is devoted to C#.

However, this isnt entirely bad as I hope it will improve some of the areas in AutoIt where I lack the real base knowledge to do some of the advanced stuff.

If you get someone to get FMOD calls ported to AutoIt I'll write the rest for you.


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0