Jump to content

Play XM music with ufmod.dll


Recommended Posts

Hello, i try for a long time to play xm music with ufmod.dll (only 10k).

But i don't obtain any sound, i think i don't call function correctly.

HotKeySet("{ESC}", "Terminate")

$xm = "J:\test.xm"

Local $hDLL = DllOpen("ufmod.dll")

$return = DllCall($hDLL, "HANDLE", "uFMOD_PlaySong", "STR*", $xm, "INT", 0, "INT", 2)

If @error = 0 Then

    ConsoleWrite("OK" & @CRLF)

    While True
        Sleep(100)
    WEnd

Else
    ConsoleWrite("KO " & @error & @CRLF)

EndIf


Func Terminate()
    Exit 0
    DllClose($hDLL)
EndFunc   ;==>Terminate

dll and examples can be download from :  https://ufmod.sourceforge.io , on top left. 

Inside 7z file, directory ufmodlib\dll

 

a lot of xm file can be download from : https://github.com/sxiii/keygen-music/tree/master/music

How can i make my code works?

 

 

 

Edited by kaz
Link to comment
Share on other sites

Try

$return = DllCall($hDLL, "int", "uFMOD_PlaySong", "str", $xm, "uint", 0, "uint", 2)

"STR*" is a string pointer which is wrong here.

Before exiting the script I would suggest to stop the player by

DllCall($hDLL, "int", "uFMOD_PlaySong", "str", 0, "uint", 0, "uint", 0)

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Posted (edited)

thanks, but i still have no sound.

i try to add : DllCall($hDLL, "none", "uFMOD_SetVolume", "uint", 15)

to be sure volume is not 0.

But still nothing 😞

it seems program not responding, esc key do nothing and program don't exit.

 

After debugging, i think call to waveOutWrite (winmm.dll) get an error.

Edited by kaz
Link to comment
Share on other sites

with the changes suggested by @UEZ it works for me

try putting #AutoIt3Wrapper_UseX64=n at the beginning of the script

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

still no sound with this otion.

i'm on W10, i will try on another PC.

While debugging, i see parameter passed to uFMOD_PlaySong function, but ...

Link to comment
Share on other sites

Posted (edited)

Thanks UEZ, player on this link works fine.

I thought it should be easy tu use this small dll.

I tried on a W10 VM, no sound

On a W11 desktop, loop on first notes only.

with or without the while loop.

 

Edited by kaz
Link to comment
Share on other sites

This works for me:

;Coded by UEZ build 2024-06-29
#include <WinAPIConv.au3>
#AutoIt3Wrapper_UseX64=n

Global Const $XM_RESOURCE = 0, $XM_MEMORY = 1, $XM_FILE = 2, $XM_NOLOOP = 8, $XM_SUSPENDED = 16, $uFMOD_MIN_VOL = 0, $uFMOD_MAX_VOL = 25, $uFMOD_DEFAULT_VOL = 25
Global $g_iDLLPath = DllOpen(@ScriptDir & "\ufmod.dll")

Func uFMOD_PlaySongFile($sFilename, $param = 0, $fdwSong = $XM_FILE)
    Local Const $aReturn = DllCall($g_iDLLPath, "ptr", "uFMOD_PlaySong", "str", $sFilename, "ulong", $param, "ulong", $fdwSong)
    If @error Or Not IsArray($aReturn) Then Return SetError(1, 0, 0)
    If Not $aReturn[0] Then Return SetError(2, 0, 0)
    Return $aReturn[0]
EndFunc

Func uFMOD_PlaySongMem($pMem, $iSize, $fdwSong = $XM_MEMORY)
    Local Const $aReturn = DllCall($g_iDLLPath, "ptr", "uFMOD_PlaySong", "ptr", $pMem, "ulong", $iSize, "ulong", $fdwSong)
    If @error Or Not IsArray($aReturn) Then Return SetError(1, 0, 0)
    If Not $aReturn[0] Then Return SetError(2, 0, 0)
    Return $aReturn[0]
EndFunc

Func uFMOD_StopSong()
    DllCall($g_iDLLPath, "ptr", "uFMOD_PlaySong", "str", "", "long", 0, "long", 0)
    Return 1
EndFunc

Func uFMOD_PauseSong()
    DllCall($g_iDLLPath, "none", "uFMOD_Pause")
    Return 1
EndFunc

Func uFMOD_ResumeSong()
    DllCall($g_iDLLPath, "none", "uFMOD_Resume")
    Return 1
EndFunc

Func uFMOD_SetVolume($iVol)
    DllCall($g_iDLLPath, "none", "uFMOD_SetVolume", "long", $iVol)
    Return 1
EndFunc

Func uFMOD_GetStats()
    Local Const $aReturn = DllCall($g_iDLLPath, "int", "uFMOD_GetStats")
    If @error Or Not IsArray($aReturn) Then Return SetError(1, 0, 0)
    If Not $aReturn[0] Then Return SetError(2, 0, 0)
    Local $aRMS[] = [_WinAPI_HiWord($aReturn[0]), _WinAPI_LoWord($aReturn[0])] ;L / R channel
    Return $aRMS
EndFunc

Func uFMOD_GetRowOrder()
    Local Const $aReturn = DllCall($g_iDLLPath, "int", "uFMOD_GetRowOrder")
    If @error Or Not IsArray($aReturn) Then Return SetError(1, 0, 0)
    If Not $aReturn[0] Then Return SetError(2, 0, 0)
    Return $aReturn[0]
EndFunc

Func uFMOD_GetTime()
    Local Const $aReturn = DllCall($g_iDLLPath, "long", "uFMOD_GetTime")
    If @error Or Not IsArray($aReturn) Then Return SetError(1, 0, 0)
    If Not $aReturn[0] Then Return SetError(2, 0, 0)
    Return $aReturn[0]
EndFunc

Func uFMOD_GetTitle()
    Local Const $aReturn = DllCall($g_iDLLPath, "str", "uFMOD_GetTitle")
    If @error Or Not IsArray($aReturn) Then Return SetError(1, 0, 0)
    If Not $aReturn[0] Then Return SetError(2, 0, 0)
    Return $aReturn[0]
EndFunc

Func uFMOD_Jump2Pattern($iPattern)
    DllCall($g_iDLLPath, "none", "uFMOD_Jump2Pattern", "long", $iPattern)
    Return 1
EndFunc

uFMOD_PlaySongFile(<YOUR XM FILE>) ;<<<<<<<<<<<<<<<<<<< change it

While Sleep(10)
    If uFMOD_GetTime() > 10000 Then ExitLoop
WEnd

uFMOD_StopSong()
DllClose($g_iDLLPath)

 

Important is to load the DLL via DllOpen() otherwise it will crash.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

thanks UEZ for your works.

unfortunatly, it doesn't works on my computers, no sound.

If i add uFMOD_StopSong() before uFMOD_PlaySongFile, i obtain a loop on first notes, but nothing more (W10 and W11)

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...