eukalyptus
Active Members-
Posts
123 -
Joined
-
Last visited
-
Days Won
3
eukalyptus last won the day on October 1 2014
eukalyptus had the most liked content!
Recent Profile Visitors
754 profile views
eukalyptus's Achievements
-
ioa747 reacted to a post in a topic: IconDock - Mac style Icon toolbar
-
AZJIO reacted to a post in a topic: BigNum UDF
-
Gianni reacted to a post in a topic: BigNum UDF
-
Danyfirex reacted to a post in a topic: Direct2D UDF
-
LukeLe reacted to a post in a topic: DirectSound UDF
-
funkey reacted to a post in a topic: Super Mario game gdi+
-
Xandy reacted to a post in a topic: BASS Function Library (Sound and Music Functions)
-
Xandy reacted to a post in a topic: BASS Function Library (Sound and Music Functions)
-
PionnerCast reacted to a post in a topic: DirectSound UDF
-
wakillon reacted to a post in a topic: the creation of the AutoIt-Logo ;)
-
Replace "jpg" by "bmp"
-
You can use this: Func _ATan2($fY, $fX) Local $aResult = DllCall("msvcrt.dll", "double:cdecl", "atan2", "double", $fY, "double", $fX) If @error Then Return SetError(@error, @extended, False) Return $aResult[0] EndFunc ;==>_Atan2
-
Direct2D UDF Is Direct2D the new GDIPlus? Hmm - I think it is not! It is too complicated and Microsoft failed at the design But Direct2D is hardware accelerated and it has some features I always missed in GDIPlus, like loading/saving animated GIF´s, combining path´s or drawing bitmap´s in a perspective view... check out the examples to see, what can be done Download: https://autoit.de/index.php/Attachment/70-Direct2D-7z/ Or visit the original topic at the german forum - link in my signature
-
DirectSound UDF play audio files, record microphone, apply effects or create your own sound - check out the examples Download: https://autoit.de/index.php/Attachment/69-DirectSound-7z/ Or visit the original topic at the german forum - link in my signature
- 3 replies
-
- DirectSound
- MP3
- (and 4 more)
-
Some Screensavers I wrote (and more to come) using Direct2D. Download: AutoItScreenSavers.7z Run the scripts in TestMode by pressing F5 in SciTE Or compile them by pressing F7 and select the Screensaver in the Windows-Screensaver Settings The Direct2D-UDF in the download file is not the latest one - you find the newest version in my signature:
-
Creating Alpha Mask Using Difference Between Two Images
eukalyptus replied to user2037's topic in AutoIt GUI Help and Support
You can blit one image on the other using the XOR operator: #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> Global $hGui = GUICreate("", 604, 202) GUISetBkColor(0x0000FF) Global $hDC = _WinAPI_GetDC($hGui) Global $hCDC = _WinAPI_CreateCompatibleDC($hDC) GUISetState() Global $hBMP_1, $hBMP_2 _CreateGraphics($hBMP_1, $hBMP_2) Local $hOBJ = _WinAPI_SelectObject($hCDC, $hBMP_1) _WinAPI_BitBlt($hDC, 1, 1, 200, 200, $hCDC, 0, 0, $SRCCOPY) _WinAPI_SelectObject($hCDC, $hBMP_2) _WinAPI_BitBlt($hDC, 202, 1, 200, 200, $hCDC, 0, 0, $SRCCOPY) Global $iMode = 0 Global $iTimer = TimerInit() While GUIGetMsg() <> -3 If TimerDiff($iTimer) > 500 Then $iTimer = TimerInit() Switch $iMode Case 1 _WinAPI_SelectObject($hCDC, $hBMP_2) _WinAPI_BitBlt($hDC, 403, 1, 200, 200, $hCDC, 0, 0, $SRCCOPY) $iMode = 2 Case 2 _WinAPI_SelectObject($hCDC, $hBMP_1) _WinAPI_BitBlt($hDC, 403, 1, 200, 200, $hCDC, 0, 0, $SRCCOPY) _WinAPI_SelectObject($hCDC, $hBMP_2) _WinAPI_BitBlt($hDC, 403, 1, 200, 200, $hCDC, 0, 0, $SRCINVERT) ;<---- XOR $iMode = 0 Case Else _WinAPI_SelectObject($hCDC, $hBMP_1) _WinAPI_BitBlt($hDC, 403, 1, 200, 200, $hCDC, 0, 0, $SRCCOPY) $iMode = 1 EndSwitch EndIf WEnd _WinAPI_SelectObject($hCDC, $hOBJ) _WinAPI_DeleteObject($hBMP_1) _WinAPI_DeleteObject($hBMP_2) _WinAPI_DeleteDC($hCDC) _WinAPI_ReleaseDC($hGui, $hDC) Func _CreateGraphics(ByRef $hBMP_1, ByRef $hBMP_2) _GDIPlus_Startup() Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(200, 200) Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hContext, 2) _GDIPlus_GraphicsClear($hContext, 0xFFFFFFFF) Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, 5) For $i = 1 To 10 _GDIPlus_PenSetColor($hPen, BitOR(0xFF000000, BitShift(Random(0, 255, 1), -16), BitShift(Random(0, 255, 1), -8), Random(0, 255, 1))) _GDIPlus_GraphicsDrawLine($hContext, Random(0, 200), Random(0, 200), Random(0, 200), Random(0, 200), $hPen) Next $hBMP_1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) For $i = 1 To 4 _GDIPlus_PenSetColor($hPen, BitOR(0xFF000000, BitShift(Random(0, 255, 1), -16), BitShift(Random(0, 255, 1), -8), Random(0, 255, 1))) _GDIPlus_GraphicsDrawLine($hContext, Random(0, 200), Random(0, 200), Random(0, 200), Random(0, 200), $hPen) Next $hBMP_2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hContext) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndFunc ;==>_CreateGraphics -
Without Bass.dll you can use my DirectSound UDF to decode the mp3.: http://autoit.de/index.php?page=Thread&postID=361564#post361564 And then look for the peaks. #include "DirectSound.au3" Global $hFile = FileOpen("Test.mp3", 16) Global $bMP3 = FileRead($hFile) FileClose($hFile) Local $aWav = _DSnd_MP3Decode($bMP3) _FindSilence($aWav) Func _FindSilence($aWav, $fThreshold = 0.05) Local $iWavLen = BinaryLen($aWav[0]) Local $iSamples = $iWavLen * 0.5 Local $tWav = DllStructCreate("byte[" & $iWavLen & "];") Local $tWavSmp = DllStructCreate("short[" & $iSamples & "];", DllStructGetPtr($tWav)) DllStructSetData($tWav, 1, $aWav[0]) Local $iThrHld = 32768 * $fThreshold Local $iStart = 0 For $i = 1 To $iSamples * 0.5 If Abs(DllStructGetData($tWavSmp, 1, $i)) >= $iThrHld Then ExitLoop $iStart = $i Next Local $iEnd = $iSamples For $i = $iSamples To $iSamples * 0.5 Step -1 $iEnd = $i If Abs(DllStructGetData($tWavSmp, 1, $i)) >= $iThrHld Then ExitLoop Next Local $fMSStart = $iStart / $aWav[1].SamplesPerSec / $aWav[1].Channels * 1000 Local $fMSEnd = $iEnd / $aWav[1].SamplesPerSec / $aWav[1].Channels * 1000 ConsoleWrite("> MSStart:" & $fMSStart & " MSEnd:" & $fMSEnd & @CRLF) EndFunc ;==>_FindSilence E Edit: faster, using ASM ;#include "FASM.au3" #include "DirectSound.au3" #include <Memory.au3> Global Const $bASM_SilenceStart_32 = "0x538B5424088B4C240C668B5C2410668B026609C0790366F7D86639D87C0489C8EB0883C20283E9017FE45BC20C00" Global Const $bASM_SilenceStart_64 = "0x668B016609C0790366F7D8664439C07C0489D0EB094883C10283EA017FE2C3" Global Const $bASM_SilenceEnd_32 = "0x538B5424088B4C240C668B5C241001CA01CA83EA02668B026609C0790366F7D86639D87C0489C8EB0583E9017FE45BC20C00" Global Const $bASM_SilenceEnd_64 = "0x4801D14801D14883E902668B016609C0790366F7D8664439C07C0489D0EB0583EA017FE2C3" Global $hFile = FileOpen("Test.mp3", 16) Global $bMP3 = FileRead($hFile) FileClose($hFile) Global $aWav = _DSnd_MP3Decode($bMP3) Global $aCut = _FindSilence($aWav) Global $bNew = _CutMP3($bMP3, $aCut[0], $aCut[1]) $hFile = FileOpen("New.mp3", 18) FileWrite($hFile, $bNew) FileClose($hFile) Func _FindSilence($aWav, $fThreshold = 0.1) Local $pASM_Start, $_pASM_Start, $pASM_End, $_pASM_End Switch @AutoItX64 Case 0 $pASM_Start = __ASMCreate($bASM_SilenceStart_32, $_pASM_Start) $pASM_End = __ASMCreate($bASM_SilenceEnd_32, $_pASM_End) Case Else $pASM_Start = __ASMCreate($bASM_SilenceStart_64, $_pASM_Start) $pASM_End = __ASMCreate($bASM_SilenceEnd_64, $_pASM_End) EndSwitch Local $iWavLen = BinaryLen($aWav[0]) Local $iSamples = $iWavLen * 0.5 Local $tWav = DllStructCreate("byte[" & $iWavLen & "];") DllStructSetData($tWav, 1, $aWav[0]) Local $iThrHld = 32768 * $fThreshold Local $aResult = DllCallAddress("uint", $pASM_Start, "struct*", $tWav, "uint", $iSamples, "short", $iThrHld) Local $iStart = $iSamples - $aResult[0] Local $aResult = DllCallAddress("uint", $pASM_End, "struct*", $tWav, "uint", $iSamples, "short", $iThrHld) Local $iEnd = $aResult[0] Local $fMSStart = $iStart / $aWav[1].SamplesPerSec / $aWav[1].Channels * 1000 Local $fMSEnd = $iEnd / $aWav[1].SamplesPerSec / $aWav[1].Channels * 1000 _MemVirtualFree($_pASM_Start, 0, $MEM_RELEASE) _MemVirtualFree($_pASM_End, 0, $MEM_RELEASE) Local $aRet[2] $aRet[0] = $fMSStart $aRet[1] = $fMSEnd Return $aRet EndFunc ;==>_FindSilence Func _CutMP3(ByRef $bMP3, $iMSStart, $iMSEnd, $bID3v2 = True) $iMSStart /= 1000 $iMSEnd /= 1000 Local $iMP3Len = BinaryLen($bMP3) Local $tMP3 = DllStructCreate("char[" & $iMP3Len * 2 & "]; byte[2882];") Local $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, StringTrimLeft($bMP3, 2)) Local $aHeader = _MP3_GetHeaders($bMP3) Local $bNew = BinaryMid(0, 1, 0) If $bID3v2 And $aHeader[1][0] > 0 Then ;Id3v2Tag $bNew = BinaryMid($bMP3, 1, $aHeader[1][0]) ;ID3v2 EndIf Local $iFirstHeader = 1 Local $iXingVBRIFrames = __MP3_GetFrameCountXINGVBRI($pMP3 + $aHeader[1][0] * 2) If Not @error And $iXingVBRIFrames > 0 Then $iFirstHeader = 2 ;Skip XING / VBRI Frame Local $iMS = 0, $iFrameStart = $iFirstHeader For $i = $iFirstHeader To $aHeader[0][0] ;Skip $iMSStart Milliseconds $iMS += $aHeader[$i][5] / $aHeader[$i][2] If $iMS >= $iMSStart Then ExitLoop $iFrameStart = $i Next Local $iFrameEnd For $i = $iFrameStart To $aHeader[0][0] ;Add Frames $iMSStart to $iMSEnd $iFrameEnd = $i $iMS += $aHeader[$i][5] / $aHeader[$i][2] If $iMS > $iMSEnd Then ExitLoop Next $tMP3 = DllStructCreate("byte[" & $iMP3Len * 2 & "];") $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, $bMP3) Local $tNew = DllStructCreate("byte[" & $aHeader[$iFrameEnd][0] - $aHeader[$iFrameStart][0] & "]", $pMP3 + $aHeader[$iFrameStart][0]) $bNew &= DllStructGetData($tNew, 1) Return $bNew EndFunc ;==>_CutMP3 Func _MP3_GetHeaders(Const ByRef $bMP3, $iMaxHeaders = -1, $iMaxErrors = 99, $bToolTip = True) ;by Eukalyptus AutoIt.de Local $iMP3Len = BinaryLen($bMP3) Local $tMP3 = DllStructCreate("char[" & $iMP3Len * 2 & "]; byte[2882];") Local $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, StringTrimLeft($bMP3, 2)) Local $aHeader[128][6] = [[0, "BitRate", "SampleRate", "Chan", "FrameSize", "Samples"]] __MP3_GetHeaders($pMP3, $iMP3Len, $aHeader, $iMaxHeaders, $iMaxErrors, $bToolTip) Return $aHeader EndFunc ;==>_MP3_GetHeaders ;############################################################################################################ ;# Internal MP3 Functions ;############################################################################################################ Func __MP3_GetHeaders($pMP3, $iMP3Len, ByRef $aHeader, $iMaxHeaders = -1, $iMaxErrors = 99, $bToolTip = True) ;by Eukalyptus AutoIt.de $iMaxHeaders = Dec(Hex($iMaxHeaders, 8), 2) ;-1=4294967295 Local $iMP3Pos = 0, $iCnt = 1, $iTmpOff, $iError = 0 While $iCnt <= $iMaxHeaders $iTmpOff = $iMP3Pos If Not __MP3_GetFrameHeaderInfo($pMP3 + $iMP3Pos * 2, $iMP3Pos, $aHeader[$iCnt][1], $aHeader[$iCnt][2], $aHeader[$iCnt][3], $aHeader[$iCnt][4], $aHeader[$iCnt][5]) Then If $iMP3Pos >= $iMP3Len - 1440 Then $aHeader[$iCnt][0] = $iMP3Pos $iCnt += 1 ExitLoop ;End of file EndIf $iMP3Pos = $iTmpOff __MP3_SkipID3v2TAG($pMP3 + $iMP3Pos * 2, $iTmpOff) ;maybe ID3v2 inside MP3 Stream!? If $iTmpOff = $iMP3Pos Then ;no ID3v2 or no FrameHeader ahead $iError += 1 If $iError > $iMaxErrors Then ExitLoop $iMP3Pos += 26 ;try offset of MinFrameSize (8KBit, 22050Hz) Else $iMP3Pos = $iTmpOff; ID3v2 offset EndIf Else $aHeader[$iCnt][0] = $iMP3Pos - $aHeader[$iCnt][4] $iCnt += 1 If $iCnt >= UBound($aHeader) Then ReDim $aHeader[$iCnt * 2][6] If $bToolTip And Not Mod($iCnt, 1000) Then ToolTip(StringFormat("%.2f%%", $iMP3Pos * 100 / $iMP3Len)) EndIf WEnd If $bToolTip Then ToolTip("") $aHeader[0][0] = $iCnt - 1 ReDim $aHeader[$iCnt][6] Return $iError EndFunc ;==>__MP3_GetHeaders Func __MP3_GetFrameHeaderInfo($pMP3, ByRef $iMP3Pos, ByRef $iBitRate, ByRef $iSampleRate, ByRef $iChan, ByRef $iFrameSize, ByRef $iSamples) ;by Eukalyptus AutoIt.de ;[ Byte 1 ][ Byte 2 ][ Byte 3 ][ Byte 4 ] ;[1][1][1][1][1][1][1][1][1][1][1][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] ;|_______________________________|| ||____|| ||__________|| ||_|| ||____|| ||_|| ||____| ; |____| |_| |____| |_| |____| |_| ; Sync Layer BitRate Pad Chan Copy Emph ; ID Protect Freq Prv ModEx Orig Local $aRegExp, $iRegExpOff, $iMod, $iHeader, $iID, $iBRate, $iBRM, $fBRF, $iPad Local $tMP3 = DllStructCreate("char[2882];", $pMP3) $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "FF[FE][23AB].{4}", 1) ;Match Header Mpeg(1/2/2.5) - Layer_III - ProtectionBit ON/OFF If @error Then Return SetError(1, 1, False) $iRegExpOff = @extended - 9 $iMod = Mod($iRegExpOff, 2) $iRegExpOff += $iMod $iMP3Pos += $iRegExpOff * 0.5 If Not $iMod Then ;Byte boundaries $iHeader = Dec($aRegExp[0], 1) $iID = BitAND(BitShift($iHeader, 19), 0x3) Switch $iID Case 0, 2 ;Mpeg2/2.5 $iSamples = 576 Case 3 ;Mpeg1 $iSamples = 1152 Case Else ; 1 = reserved Return SetError(1, 2, False) EndSwitch If BitAND(BitShift($iHeader, 17), 0x3) <> 1 Then Return SetError(1, 3, False) ; <> Layer III $iBRate = BitAND(BitShift($iHeader, 12), 0xF) Switch $iID Case 3 ;MPEG Version 1 $iBRM = Mod($iBRate + 2, 4) + 1 $fBRF = 2 ^ BitShift($iBRate + 2, 2) $iBitRate = 16 * $fBRF + 4 * $fBRF * $iBRM Case Else ;MPEG Version 2.5 + MPEG Version 2 $iBRM = Mod($iBRate - 1, 8) + 1 $fBRF = 2 ^ BitShift($iBRate - 1, 3) $iBitRate = 8 * $fBRF * $iBRM + 64 * ($fBRF - 1) EndSwitch Switch BitAND(BitShift($iHeader, 10), 0x3) Case 0 $iSampleRate = 11025 Case 1 $iSampleRate = 12000 Case 2 $iSampleRate = 8000 Case Else ; 3 = reserved Return SetError(1, 4, False) EndSwitch Switch $iID Case 2 $iSampleRate *= 2 ;Mpeg2 = 16000, 24000, 22050 Case 3 $iSampleRate *= 4 ;Mpeg1 = 32000, 48000, 44100 EndSwitch $iPad = BitAND(BitShift($iHeader, 9), 0x1) $iChan = (BitAND(BitShift($iHeader, 6), 0x3) <> 4) + 1 ;0,1=Stereo 2=DualMono 3=Mono $iFrameSize = Int((($iSamples / 0.008) * $iBitRate / $iSampleRate)) + $iPad $tMP3 = DllStructCreate("char[3];", $pMP3 + $iRegExpOff + $iFrameSize * 2) Switch DllStructGetData($tMP3, 1) Case "FFF", "FFE" $iMP3Pos += $iFrameSize Case Else Return SetError(1, 5, False) ;FrameSize offset does not match a FrameHeader - something went wrong EndSwitch Return True EndIf Return SetError(1, 6, False) EndFunc ;==>__MP3_GetFrameHeaderInfo Func __MP3_SkipID3v2TAG($pMP3, ByRef $iMP3Pos) ;by Eukalyptus AutoIt.de ;[49][44][33][xx][xx][yy][zz][zz][zz][zz] ;| ||______|| ||______________| ;|__________| |__| ; Version TagSize ; "ID3" Flags Local $iPos, $iHeader, $iFlags Local $tMP3 = DllStructCreate("char[2882];", $pMP3) Local $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "494433.{14}", 1) If @error Then Return SetError(0, 0, False) $iPos = @extended - 21 If Mod($iPos, 2) Then Return SetError(1, 0, False) ;TAG not at Byte-Boundaries $iPos *= 0.5 $iHeader = Dec(StringRight($aRegExp[0], 8)) If BitAND($iHeader, 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 8), 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 16), 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 24), 0xFF) > 0x7F Then Return SetError(1, 1, False);Size Bytes <= 7F! If BitAND(BitShift($iHeader, 40), 0xFF) = 0xFF Or BitAND(BitShift($iHeader, 48), 0xFF) = 0xFF Then Return SetError(1, 2, False);Version Bytes <> FF! $iFlags = Dec(StringLeft(StringTrimLeft($aRegExp[0], 10), 2)) $iPos += BitOR(BitAND($iHeader, 0x7F), BitShift(BitAND($iHeader, 0x7F00), 1), BitShift(BitAND($iHeader, 0x7F0000), 2), BitShift(BitAND($iHeader, 0x7F000000), 3)) + (10 * BitShift(BitAND($iFlags, 0x8), 3)) + 10 $tMP3 = DllStructCreate("char[3];", $pMP3 + $iPos * 2) Switch DllStructGetData($tMP3, 1) Case "FFF", "FFE" $iMP3Pos += $iPos Case Else Return SetError(1, 3, False) ;Pos does not match a FrameHeader - something went wrong EndSwitch Return True EndFunc ;==>__MP3_SkipID3v2TAG Func __MP3_GetFrameCountXINGVBRI($pMP3) ;by Eukalyptus AutoIt.de Local $tMP3 = DllStructCreate("char[2882];", $pMP3) ;[58][69][6E][67][xx][xx][xx][xx][yy][yy][yy][yy][zz][zz][zz][zz][tt][tt][tt][tt][tt][tt]... ;|______________|| ||______________||______________||__________________________ ; |______________| ; "Xing" Frames Bytes 100 [Bytes] TOC ; Flags: 0x1 0x2 0x4 Local $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "(58696E67)(.{8})(.{8})", 3) ;"Xing" If Not @error Then If BitAND(Dec($aRegExp[1]), 1) = 1 Then Return Dec($aRegExp[2]) Else ;[56][42][52][49][xx][xx][yy][yy][zz][zz][xx][xx][xx][xx][yy][yy][yy][yy][zz][zz][xx][xx][yy][yy][zz][zz][xx][xx][xx][xx][xx]... ;|______________|| ||______|| ||______________|| ||______|| ||______|| ||______________________ ; |______| |______| |______________| |______| |______| ; "VBRI" Delay Bytes TOC Count Size TOC [size*count) ; Version Quality Frames Scale Frames/Entry $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "(56425249)(.{4})(.{4})(.{4})(.{8})(.{8})", 3) ;"VBRI" If Not @error Then Return Dec($aRegExp[5]) EndIf Return 0 EndFunc ;==>__MP3_GetFrameCountXINGVBRI #ASM _ASM_SilenceStart_32 # use32 # push ebx # mov edx, [esp+8] # mov ecx, [esp+12] # mov bx, [esp+16] # _Loop: # mov ax, [edx] # or ax, ax # jns _AbsResult # neg ax # _AbsResult: # cmp ax, bx # jl _Cont # mov eax, ecx # jmp _Ret # _Cont: # add edx, 2 # sub ecx, 1 # jg _Loop # _Ret: # pop ebx # ret 12 #ASMEND #ASM _ASM_SilenceStart_64 # use64 # _Loop: # mov ax, [rcx] # or ax, ax # jns _AbsResult # neg ax # _AbsResult: # cmp ax, r8w # jl _Cont # mov eax, edx # jmp _Ret # _Cont: # add rcx, 2 # sub edx, 1 # jg _Loop # _Ret: # ret #ASMEND #ASM _ASM_SilenceEnd_32 # use32 # push ebx # mov edx, [esp+8] # mov ecx, [esp+12] # mov bx, [esp+16] # add edx, ecx # add edx, ecx # _Loop: # sub edx, 2 # mov ax, [edx] # or ax, ax # jns _AbsResult # neg ax # _AbsResult: # cmp ax, bx # jl _Cont # mov eax, ecx # jmp _Ret # _Cont: # sub ecx, 1 # jg _Loop # _Ret: # pop ebx # ret 12 #ASMEND #ASM _ASM_SilenceEnd_64 # use64 # add rcx, rdx # add rcx, rdx # _Loop: # sub rcx, 2 # mov ax, [rcx] # or ax, ax # jns _AbsResult # neg ax # _AbsResult: # cmp ax, r8w # jl _Cont # mov eax, edx # jmp _Ret # _Cont: # sub edx, 1 # jg _Loop # _Ret: # ret #ASMEND Func __ASMCreate(Const ByRef $bBinaryCode, ByRef $pPtr) Local $iSize = BinaryLen($bBinaryCode) $pPtr = _MemVirtualAlloc(0, $iSize + 16, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) Local $pStruct = Number($pPtr) $pStruct = $pStruct + 16 - Mod($pStruct, 16) Local $tStruct = DllStructCreate("byte[" & $iSize & "];", $pStruct) DllStructSetData($tStruct, 1, $bBinaryCode) Return $pStruct EndFunc ;==>__ASMCreate
-
Or you trim the frames yourself: ;#include <Array.au3> Global $hFile = FileOpen("Test.mp3", 16) Global $bMP3 = FileRead($hFile) FileClose($hFile) ;MP3: [..........................................] ; | | ; 2s 6s ; |_______________| ; 4s Global $bNew = _CutMP3($bMP3, 2000, 6000) $hFile = FileOpen("New.mp3", 18) FileWrite($hFile, $bNew) FileClose($hFile) Func _CutMP3(ByRef $bMP3, $iMSStart, $iMSEnd, $bID3v2 = True) $iMSStart /= 1000 $iMSEnd /= 1000 Local $iMP3Len = BinaryLen($bMP3) Local $tMP3 = DllStructCreate("char[" & $iMP3Len * 2 & "]; byte[2882];") Local $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, StringTrimLeft($bMP3, 2)) Local $aHeader = _MP3_GetHeaders($bMP3) ;_ArrayDisplay($aHeader) Local $bNew = BinaryMid(0, 1, 0) If $bID3v2 And $aHeader[1][0] > 0 Then ;Id3v2Tag $bNew = BinaryMid($bMP3, 1, $aHeader[1][0]) ;ID3v2 EndIf Local $iFirstHeader = 1 Local $iXingVBRIFrames = __MP3_GetFrameCountXINGVBRI($pMP3 + $aHeader[1][0] * 2) If Not @error And $iXingVBRIFrames > 0 Then $iFirstHeader = 2 ;Skip XING / VBRI Frame Local $iMS = 0, $iFrameStart = $iFirstHeader For $i = $iFirstHeader To $aHeader[0][0] ;Skip $iMSStart Milliseconds $iMS += $aHeader[$i][5] / $aHeader[$i][2] If $iMS >= $iMSStart Then ExitLoop $iFrameStart = $i Next For $i = $iFrameStart To $aHeader[0][0] ;Add Frames $iMSStart to $iMSEnd $bNew &= BinaryMid($bMP3, $aHeader[$i][0], $aHeader[$i][4]) $iMS += $aHeader[$i][5] / $aHeader[$i][2] If $iMS > $iMSEnd Then ExitLoop Next Return $bNew EndFunc ;==>_CutMP3 Func _MP3_GetHeaders(Const ByRef $bMP3, $iMaxHeaders = -1, $iMaxErrors = 99, $bToolTip = True) ;by Eukalyptus AutoIt.de Local $iMP3Len = BinaryLen($bMP3) Local $tMP3 = DllStructCreate("char[" & $iMP3Len * 2 & "]; byte[2882];") Local $pMP3 = DllStructGetPtr($tMP3) DllStructSetData($tMP3, 1, StringTrimLeft($bMP3, 2)) Local $aHeader[128][6] = [[0, "BitRate", "SampleRate", "Chan", "FrameSize", "Samples"]] __MP3_GetHeaders($pMP3, $iMP3Len, $aHeader, $iMaxHeaders, $iMaxErrors, $bToolTip) Return $aHeader EndFunc ;==>_MP3_GetHeaders ;############################################################################################################ ;# Internal MP3 Functions ;############################################################################################################ Func __MP3_GetHeaders($pMP3, $iMP3Len, ByRef $aHeader, $iMaxHeaders = -1, $iMaxErrors = 99, $bToolTip = True) ;by Eukalyptus AutoIt.de $iMaxHeaders = Dec(Hex($iMaxHeaders, 8), 2) ;-1=4294967295 Local $iMP3Pos = 0, $iCnt = 1, $iTmpOff, $iError = 0 While $iCnt <= $iMaxHeaders $iTmpOff = $iMP3Pos If Not __MP3_GetFrameHeaderInfo($pMP3 + $iMP3Pos * 2, $iMP3Pos, $aHeader[$iCnt][1], $aHeader[$iCnt][2], $aHeader[$iCnt][3], $aHeader[$iCnt][4], $aHeader[$iCnt][5]) Then If $iMP3Pos >= $iMP3Len - 1440 Then $aHeader[$iCnt][0] = $iMP3Pos $iCnt += 1 ExitLoop ;End of file EndIf $iMP3Pos = $iTmpOff __MP3_SkipID3v2TAG($pMP3 + $iMP3Pos * 2, $iTmpOff) ;maybe ID3v2 inside MP3 Stream!? If $iTmpOff = $iMP3Pos Then ;no ID3v2 or no FrameHeader ahead $iError += 1 If $iError > $iMaxErrors Then ExitLoop $iMP3Pos += 26 ;try offset of MinFrameSize (8KBit, 22050Hz) Else $iMP3Pos = $iTmpOff; ID3v2 offset EndIf Else $aHeader[$iCnt][0] = $iMP3Pos - $aHeader[$iCnt][4] $iCnt += 1 If $iCnt >= UBound($aHeader) Then ReDim $aHeader[$iCnt * 2][6] If $bToolTip And Not Mod($iCnt, 1000) Then ToolTip(StringFormat("%.2f%%", $iMP3Pos * 100 / $iMP3Len)) EndIf WEnd If $bToolTip Then ToolTip("") $aHeader[0][0] = $iCnt - 1 ReDim $aHeader[$iCnt][6] Return $iError EndFunc ;==>__MP3_GetHeaders Func __MP3_GetFrameHeaderInfo($pMP3, ByRef $iMP3Pos, ByRef $iBitRate, ByRef $iSampleRate, ByRef $iChan, ByRef $iFrameSize, ByRef $iSamples) ;by Eukalyptus AutoIt.de ;[ Byte 1 ][ Byte 2 ][ Byte 3 ][ Byte 4 ] ;[1][1][1][1][1][1][1][1][1][1][1][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ] ;|_______________________________|| ||____|| ||__________|| ||_|| ||____|| ||_|| ||____| ; |____| |_| |____| |_| |____| |_| ; Sync Layer BitRate Pad Chan Copy Emph ; ID Protect Freq Prv ModEx Orig Local $aRegExp, $iRegExpOff, $iMod, $iHeader, $iID, $iBRate, $iBRM, $fBRF, $iPad Local $tMP3 = DllStructCreate("char[2882];", $pMP3) $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "FF[FE][23AB].{4}", 1) ;Match Header Mpeg(1/2/2.5) - Layer_III - ProtectionBit ON/OFF If @error Then Return SetError(1, 1, False) $iRegExpOff = @extended - 9 $iMod = Mod($iRegExpOff, 2) $iRegExpOff += $iMod $iMP3Pos += $iRegExpOff * 0.5 If Not $iMod Then ;Byte boundaries $iHeader = Dec($aRegExp[0], 1) $iID = BitAND(BitShift($iHeader, 19), 0x3) Switch $iID Case 0, 2 ;Mpeg2/2.5 $iSamples = 576 Case 3 ;Mpeg1 $iSamples = 1152 Case Else ; 1 = reserved Return SetError(1, 2, False) EndSwitch If BitAND(BitShift($iHeader, 17), 0x3) <> 1 Then Return SetError(1, 3, False) ; <> Layer III $iBRate = BitAND(BitShift($iHeader, 12), 0xF) Switch $iID Case 3 ;MPEG Version 1 $iBRM = Mod($iBRate + 2, 4) + 1 $fBRF = 2 ^ BitShift($iBRate + 2, 2) $iBitRate = 16 * $fBRF + 4 * $fBRF * $iBRM Case Else ;MPEG Version 2.5 + MPEG Version 2 $iBRM = Mod($iBRate - 1, 8) + 1 $fBRF = 2 ^ BitShift($iBRate - 1, 3) $iBitRate = 8 * $fBRF * $iBRM + 64 * ($fBRF - 1) EndSwitch Switch BitAND(BitShift($iHeader, 10), 0x3) Case 0 $iSampleRate = 11025 Case 1 $iSampleRate = 12000 Case 2 $iSampleRate = 8000 Case Else ; 3 = reserved Return SetError(1, 4, False) EndSwitch Switch $iID Case 2 $iSampleRate *= 2 ;Mpeg2 = 16000, 24000, 22050 Case 3 $iSampleRate *= 4 ;Mpeg1 = 32000, 48000, 44100 EndSwitch $iPad = BitAND(BitShift($iHeader, 9), 0x1) $iChan = (BitAND(BitShift($iHeader, 6), 0x3) <> 4) + 1 ;0,1=Stereo 2=DualMono 3=Mono $iFrameSize = Int((($iSamples / 0.008) * $iBitRate / $iSampleRate)) + $iPad $tMP3 = DllStructCreate("char[3];", $pMP3 + $iRegExpOff + $iFrameSize * 2) Switch DllStructGetData($tMP3, 1) Case "FFF", "FFE" $iMP3Pos += $iFrameSize Case Else Return SetError(1, 5, False) ;FrameSize offset does not match a FrameHeader - something went wrong EndSwitch Return True EndIf Return SetError(1, 6, False) EndFunc ;==>__MP3_GetFrameHeaderInfo Func __MP3_SkipID3v2TAG($pMP3, ByRef $iMP3Pos) ;by Eukalyptus AutoIt.de ;[49][44][33][xx][xx][yy][zz][zz][zz][zz] ;| ||______|| ||______________| ;|__________| |__| ; Version TagSize ; "ID3" Flags Local $iPos, $iHeader, $iFlags Local $tMP3 = DllStructCreate("char[2882];", $pMP3) Local $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "494433.{14}", 1) If @error Then Return SetError(0, 0, False) $iPos = @extended - 21 If Mod($iPos, 2) Then Return SetError(1, 0, False) ;TAG not at Byte-Boundaries $iPos *= 0.5 $iHeader = Dec(StringRight($aRegExp[0], 8)) If BitAND($iHeader, 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 8), 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 16), 0xFF) > 0x7F Or BitAND(BitShift($iHeader, 24), 0xFF) > 0x7F Then Return SetError(1, 1, False);Size Bytes <= 7F! If BitAND(BitShift($iHeader, 40), 0xFF) = 0xFF Or BitAND(BitShift($iHeader, 48), 0xFF) = 0xFF Then Return SetError(1, 2, False);Version Bytes <> FF! $iFlags = Dec(StringLeft(StringTrimLeft($aRegExp[0], 10), 2)) $iPos += BitOR(BitAND($iHeader, 0x7F), BitShift(BitAND($iHeader, 0x7F00), 1), BitShift(BitAND($iHeader, 0x7F0000), 2), BitShift(BitAND($iHeader, 0x7F000000), 3)) + (10 * BitShift(BitAND($iFlags, 0x8), 3)) + 10 $tMP3 = DllStructCreate("char[3];", $pMP3 + $iPos * 2) Switch DllStructGetData($tMP3, 1) Case "FFF", "FFE" $iMP3Pos += $iPos Case Else Return SetError(1, 3, False) ;Pos does not match a FrameHeader - something went wrong EndSwitch Return True EndFunc ;==>__MP3_SkipID3v2TAG Func __MP3_GetFrameCountXINGVBRI($pMP3) ;by Eukalyptus AutoIt.de Local $tMP3 = DllStructCreate("char[2882];", $pMP3) ;[58][69][6E][67][xx][xx][xx][xx][yy][yy][yy][yy][zz][zz][zz][zz][tt][tt][tt][tt][tt][tt]... ;|______________|| ||______________||______________||__________________________ ; |______________| ; "Xing" Frames Bytes 100 [Bytes] TOC ; Flags: 0x1 0x2 0x4 Local $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "(58696E67)(.{8})(.{8})", 3) ;"Xing" If Not @error Then If BitAND(Dec($aRegExp[1]), 1) = 1 Then Return Dec($aRegExp[2]) Else ;[56][42][52][49][xx][xx][yy][yy][zz][zz][xx][xx][xx][xx][yy][yy][yy][yy][zz][zz][xx][xx][yy][yy][zz][zz][xx][xx][xx][xx][xx]... ;|______________|| ||______|| ||______________|| ||______|| ||______|| ||______________________ ; |______| |______| |______________| |______| |______| ; "VBRI" Delay Bytes TOC Count Size TOC [size*count) ; Version Quality Frames Scale Frames/Entry $aRegExp = StringRegExp(DllStructGetData($tMP3, 1), "(56425249)(.{4})(.{4})(.{4})(.{8})(.{8})", 3) ;"VBRI" If Not @error Then Return Dec($aRegExp[5]) EndIf Return 0 EndFunc ;==>__MP3_GetFrameCountXINGVBRI E
-
I did some speed tests on Map and Scripting.Dictionary. Map is superfast - yeah! And I think, I've discovered a bug: Global $oDic = ObjCreate('Scripting.Dictionary') $oDic.Add(1, 1) $oDic.Add(1, 1) gives this output: "D:AutoItBetaTestTest_Dict.au3" (3) : ==> Unknown function name.: $oDic.Add(1, 1) $oDic^ ERROR
-
What if Default gives the optional params of a function their optional value? So the output of _Foo and _Bar is identically: _Foo(Default, Default, 300) _Bar(Default, Default, 300) Func _Foo($sStr = "Blabla", $iX = 0, $iY = 20) ConsoleWrite($sStr & " " & $iX & " " & $iY & @CRLF) EndFunc ;==>_Foo Func _Bar($sStr = "Blabla", $iX = 0, $iY = 20) If $sStr = Default Then $sStr = "Blabla" If $iX = Default Then $iX = 0 If $iY = Default Then $iY = 20 ConsoleWrite($sStr & " " & $iX & " " & $iY & @CRLF) EndFunc ;==>_Bar This would save some lines of code (e.g. Array.au3)
-
_ArraySearch Finds "BigString" inside a '0'
eukalyptus replied to LeCarre's topic in AutoIt Technical Discussion
This is because 0 = "String" returns True (line 48 in _Array_Search) $sStr = "BigString" $iNull = 0 If $iNull = $sStr Then ConsoleWrite("! " & $iNull & " = " & $sStr & @CRLF) Else ConsoleWrite("+ " & $iNull & " <> " & $sStr & @CRLF) EndIf If $iNull == $sStr Then ConsoleWrite("! " & $iNull & " == " & $sStr & @CRLF) Else ConsoleWrite("+ " & $iNull & " <> " & $sStr & @CRLF) EndIf -
"Expected a variable in user function call." - error if you pass a map´s value to a function as byref or const byref: #AutoIt3Wrapper_Version = B #AutoIt3Wrapper_Run_Au3Check=N #include <WinAPI.au3> $tString = DllStructCreate("wchar Text[128];") $tString.Text = "Abcdefg" Global $mMap[] $mMap.String = DllStructCreate("wchar Text[128];") $mMap.String.Text = "Abcdefg" Global $iLen $iLen = _WinAPI_StringLenW($tString);<- working ConsoleWrite("> Len: " & $iLen & @CRLF) $iLen = DllCall("kernel32.dll", "int", "lstrlenW", "struct*", $mMap.String)[0];<- working ConsoleWrite("> Len: " & $iLen & @CRLF) $iLen = _WinAPI_StringLenW($mMap.String);<- not working ConsoleWrite("> Len: " & $iLen & @CRLF)
-
Alternative to DllStructGetData()
eukalyptus replied to JScript's topic in AutoIt Technical Discussion
nothing is wrong, but please don´t tell me, that it´s easier to handle and to read some ugly pseudocode screenshots: -
Alternative to DllStructGetData()
eukalyptus replied to JScript's topic in AutoIt Technical Discussion
This "feature" was discovered by Minx and Mars (autoit.de). I like using structs as objects! #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) HotKeySet("{ESC}", "_Exit") _GDIPlus_Startup() Global $tWin = _Win_Create(0, 0, @DesktopWidth, @DesktopHeight) Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00) Global $fX, $fY, $fW, $fH While Sleep(500) _GDIPlus_GraphicsClear($tWin.GFX, 0) For $i = 1 To 10 _GDIPlus_BrushSetSolidColor($hBrush, BitOR(0x80000000, BitShift(Random(0, 0xFF, 1), -16), BitShift(Random(0, 0xFF, 1), -8), Random(0, 0xFF, 1))) $fW = Random(50, 300) $fH = Random(50, 300) $fX = Random(0, @DesktopWidth - $fW) $fY = Random(0, @DesktopHeight - $fH) _GDIPlus_GraphicsFillEllipse($tWin.Gfx, $fX, $fY, $fW, $fH, $hBrush) Next _Win_Draw($tWin) WEnd Func _Win_Create($iX, $iY, $iW, $iH) Local $tWin = DllStructCreate("int X; int Y; int W; int H; hwnd Gui; hwnd DC; handle GFX; handle BMP; hwnd CDC; hwnd OBJ; int Src[2]; byte Blend[4];") $tWin.Blend(3) = 0xFF $tWin.Blend(4) = 1 $tWin.X = $iX $tWin.Y = $iY $tWin.W = $iW $tWin.H = $iH $tWin.Gui = GUICreate("", $iW, $iH, $iX, $iY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) $tWin.DC = _WinAPI_GetDC($tWin.Gui) Local $hBMP = _WinAPI_CreateCompatibleBitmap($tWin.DC, $iW, $iH) Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) _WinAPI_DeleteObject($hBMP) $tWin.BMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) $tWin.CDC = _WinAPI_CreateCompatibleDC($tWin.DC) $tWin.OBJ = _WinAPI_SelectObject($tWin.CDC, $tWin.BMP) $tWin.GFX = _GDIPlus_GraphicsCreateFromHDC($tWin.CDC) GUISetState(@SW_SHOWNOACTIVATE, $tWin.Gui) Return $tWin EndFunc ;==>_Win_Create Func _Win_Dispose(ByRef $tWin) If Not IsDllStruct($tWin) Then Return _GDIPlus_GraphicsDispose($tWin.GFX) _WinAPI_SelectObject($tWin.CDC, $tWin.OBJ) _WinAPI_DeleteObject($tWin.BMP) _WinAPI_DeleteDC($tWin.CDC) _WinAPI_ReleaseDC($tWin.Gui, $tWin.DC) GUIDelete($tWin.Gui) $tWin = 0 EndFunc ;==>_Win_Dispose Func _Win_Draw(ByRef $tWin) If Not IsDllStruct($tWin) Then Return _WinAPI_UpdateLayeredWindow($tWin.Gui, $tWin.DC, DllStructGetPtr($tWin, "X"), DllStructGetPtr($tWin, "W"), $tWin.CDC, DllStructGetPtr($tWin, "Src"), 0, DllStructGetPtr($tWin, "Blend"), 2) EndFunc ;==>_Win_Draw Func _Exit() _GDIPlus_BrushDispose($hBrush) _Win_Dispose($tWin) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit In this example I have one struct for all things I need to draw and call _WinAPI_UpdateLayeredWindow I can add, remove or change the order of the elements without changing the rest of the script. And the code is easy to read. -
Alternative to DllStructGetData()
eukalyptus replied to JScript's topic in AutoIt Technical Discussion
You can access arrays this way: $tStruct = DllStructCreate("uint X[10];") For $i = 1 To 10 $tStruct.X(($i)) = $i Next For $i = 1 To 10 $tStruct.X(($i)) *= 2 Next For $i = 1 To 10 ConsoleWrite("> " & $tStruct.X(($i)) & @CRLF) Next Here is a benchmarkscript i wrote some time ago: http://www.autoit.de/index.php?page=Thread&postID=358070#post358070 E