1. Dashboard
  2. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team
    4. Mitgliedersuche
  3. Forenregeln
  4. Forum
    1. Unerledigte Themen
  • Anmelden
  • Registrieren
  • Suche
Alles
  • Alles
  • Artikel
  • Seiten
  • Forum
  • Erweiterte Suche
  1. AutoIt.de - Das deutschsprachige Forum.
  2. Mitglieder
  3. Mars

Beiträge von Mars

  • Längste Collatz-Folge | Project Euler

    • Mars
    • 13. Mai 2015 um 11:33

    Mein Ansatz war die Folge rückwärts zu berechnen (da gibt es wenigstens nur 1 bis 2 mögliche Lösungen pro Schritt).

    Code
    1 -> 2 -> 4 -> 8 -> 16 -> 5 -> 10 -> 20 -> 40 -> 13 -> 26 -> 52 -> 17 -> 34 -> 11 -> 22 -> 7 -> 14 -> 28 -> 56 -> 112 -> 37 -> 74 -> 148 -> 49 -> 98 -> 196 -> 65 -> 130 -> 43 -> 86 -> 172 -> 344 -> 688 -> 229 -> 458 -> 916 -> 305 -> 610 -> 203 -> 406 -> 812 -> 1624 -> 541 -> 1082 -> 2164 -> 721 -> 1442 -> 2884 -> 961 -> 1922 -> 3844 -> 7688 -> 15376 -> 5125 -> 10250 -> 20500 -> 6833 -> 13666 -> 4555 -> 9110 -> 18220 -> 6073 -> 12146 -> 24292 -> 48584 -> 97168 -> 32389 -> 64778 -> 129556 -> 259112 -> 518224 -> 172741 -> 345482 -> 690964 -> 230321 -> 460642 -> 153547 -> 307094 -> 614188 -> 1228376

    Allerdings ist das nicht wirklich die längste Folge unter 1 Mio^^

    AutoIt
    Global $m = 1
    
    
    For $i = 0 To 99 Step 1
    	ConsoleWrite($m)
    	$m = (IsInt(F2($m)) And Not IsInt(F2($m) / 2) And F2($m) <> 1 And Not IsInt(F2($m) / 3)) ? F2($m) : F1($m)
    	If $m > 1e6 Then
    		ConsoleWrite(' -> ' & $m & @CRLF)
    		ExitLoop
    	EndIf
    	ConsoleWrite(' -> ')
    Next
    
    
    Func F1($n)
    	Return 2 * $n
    EndFunc
    
    
    Func F2($n)
    	Return ($n - 1) / 3
    EndFunc
    Alles anzeigen

    lg
    M

  • [Just 4 Fun] WAV Generator

    • Mars
    • 7. Mai 2015 um 11:48

    Apropos: Arraymukke geht hier ebenfalls ;)
    (Gegen das Knacken muss man noch etwas erfinden... aber das Prinzip funktioniert einwandfrei)

    2,5kHz|Gain=14|_Sin($x,StringSplit('73 00 68 69 71 00 69 68 66 00 66 69 73 00 71 69 68 00 68 69 71 00 73 00 69 00 66 00 66 00 00 00', ' ', 2)[Mod(Int($x/500),31)])

    Edit:
    Klassiker: Wir dämpfen zwischen den Noten einfach mit einem Abs(Sin(...)). (Die Wurzel ist damit die Dämpfung etwas "rechteckiger" wird.)
    _Sin($x,StringSplit('73 00 68 69 71 00 69 68 66 00 66 69 73 00 71 69 68 00 68 69 71 00 73 00 69 00 66 00 66 00 00 00', ' ', 2)[Mod(Int($x/500),31)])*Abs(Sin(0.00628318*$x))^0.5

    Edit2:
    Man kann es mit der Arraymusik natürlich auch überteiben... Weil der Text so lang ist musste ich die Box vergrößern. Dann Gibts noch einen Wrapper für StringSplit (via Local Static -> weniger Rechenaufwand). Das hier angeheftete ist aber nur zum Ausprobieren. Die Version aus dem Startpost bleibt die aktuelle.

    Spoiler anzeigen
    AutoIt
    ; +++++ Wissenswertes +++++
    
    
    ; Funktionen:
    ; $x - Position innerhalb der WAV. Die funktion die man ins Feld eingibt f($x) berechnet die Amplitute (signed 16Bit Wert) zum Zeitpunkt des Samples
    ;    | Bei z.B. 8000 kHz werden 8000 Werte pro Sekunde berechnet und der Lautsprecher entsprechend bewegt. Man kann ihm also 8000 Mal pro Sekunde
    ;    | eine neue Position zwischen -(2^15-1) und 2^15-1 zuweisen. Töne ergeben sich durch wiederholtes neupositionieren. Frequenzen haben NICHTS mit der
    ;    | Ampliture zu tun die die Funktion berechnet, sondern mit der Periodizität der Funktion.
    ; $z - Läuft von 0 (Beginn des Sounds) bis 1 (Ende des Sounds)
    ; $p - Kreiszahl PI (braucht man villeicht für irgendwas)
    
    
    ; Allgemein können alle buildIn AutoIt Funktionen benutzt werden, da Execute benutzt wird bitte ich darum keinen Unfug zu treiben. Man kann sich auch
    ; eigene Funktionen schreiben die benutzt werden können. z.B. _Sin($x, $Ton) gibt bei $Ton = 58 den Kammerton A ohne Abhängigkeit der Samplingrate.
    
    
    ; Capsize
    ; - Verhindert Knacken der Lautsprecher beim ein- und Ausschalten des Tons
    
    
    ; Gain (2^x)
    ; - Töne werden als Signed 16Bit Werte gespeichert. Ein Sinus z.B. geht nur von -1 bis 1.
    ; | Mit einem Gain von 15 geht er von 2^15-1 bis 2^15
    ; - Ist oft nutzlos, wenn Töne via Überlauf erzeugt werden, z.B.
    
    
    ; Farbe der Ladebalken:
    ; Hellblau	- Musik wird abgespielt
    ; Lila		- Musik wird generiert
    ; Orange	- Grafischer Krimskrams wird erzeugt
    
    
    ; AMP = Amplitude = Lautstärke
    ; - Die Anzeige gibt einen Überblick über die Lautstärke des Sounds
    ; - Da nur ein Bruchteil der Samples analysiert wird ist die Anzeige nicht besonders genau.
    ; - Angezeigt werden 2 Kurven. Mittelwert + Stdandardabweichung und Mittelwert - Standardabweichung
    ; - Die Anzeige ist Logarithmisch
    
    
    ; 06.Mai.15 - SoundEdit von Mars@AutoIt.de
    
    
    ; Sammlung von Sounds
    ;  kHZ | Gain | Func
    ; 18.0 |  08  | Mod(BitAnd(42,($x/2^10)),$ZZZ)*$x ; $ZZZ kann variiert werden um verschiedene Melodien zu erhalten
    ;
    ;~ (_Sin($x,_a('73 00 68 69 71 00 69 68 66 00 66 69 73 00 71 69 68 00 68 69 71 00 73 00 69 00 66 00 66 00 00 00',Mod(Int($x/500),31)))+
    ;~ _Sin($x,_a('73 00 68 69 71 00 69 68 66 00 66 69 73 00 71 69 68 00 68 69 71 00 73 00 69 00 66 00 66 00 00 00',Mod(Int($x/500),31))-5))*Abs(Sin(0.00628318*$x))^0.5
    
    
    ;~ (_Sin($x,a('73 00 68 69 71 00 69 68 66 00 66 69 73 00 71 69 68 00 68 69 71 00 73 00 69 00 66 00 66 00 00 00',Mod(Int($x/500),31)))+
    ;~ 1/4*_Sin($x,a('73 00 68 69 71 00 69 68 66 00 66 69 73 00 71 69 68 00 68 69 71 00 73 00 69 00 66 00 66 00 00 00',Mod(Int($x/500),31))-5))*Abs(Sin(0.00628318*$x))^0.5
    
    
    #cs Tetris: Wir gehen überall um 12 runter !
    ; 12 kHz
    ; Dämpfung 1/4 Takt: Abs(Sin(0.001309*$x))^0.5
    ; Dämpfung 1/2 Takt: Abs(Sin(0.0006545*$x))^0.5
    
    
    Obertöne:	00  C9  C9  00  00  A#8 A#8 00  00  F8  F8  00  00  C9  C9  00  00  G8  G8  00  00  A#8 A#8 00  00  G#8 G#8 00  00  F8  F8  00
      Dez       00  97  97  00  00  95  95  00  00  90  90  00  00  97  97  00  00  92  92  00  00  95  95  00  00  93  93  00  00  90  90  00
    _Sin($x,_a('00 97 97 00 00 95 95 00 00 90 90 00 00 97 97 00 00 92 92 00 00 95 95 00 00 93 93 00 00 90 90 00',Mod(Int($x/2400),32)))
    
    
    Mitteltöne:	00  C7  00  00  00  A#6 00  00  00  F6  00  00  00  C7  00  00  00  G6  00  00  00  A#6 00  C7  00  G#6 00  F6  00  F6  00  00
      Dez		00  73  00  00  00  71  00  00  00  66  00  00  00  73  00  00  00  68  00  00  00  71  00  73  00  69  00  66  00  66  00  00
    _Sin($x,_a('00 73 00 00 00 71 00 00 00 66 00 00 00 73 00 00 00 68 00 00 00 71 00 73 00 69 00 66 00 66 00 00',Mod(Int($x/2400),32)))
    
    
    Melodie:	73  00  68  69  71  00  69  68  66  00  66  69  73  00  71  69  68  00  68  69  71  00  73  00  69  00  66  00  66  00  00  00
      Dez		61  00  56  57  59  00  57  56  54  00  54  57  61  00  59  57  56  00  56  57  59  00  61  00  57  00  54  00  54  00  00  00
    _Sin($x,_a('61 00 56 57 59 00 57 56 54 00 54 57 61 00 59 57 56 00 56 57 59 00 61 00 57 00 54 00 54 00 00 00',Mod(Int($x/2400),32)))
    
    
    Untertöne:	C4  C4  00  00  A#3 A#3 00  00  F3  F3  00  00  C4  C4  00  00  G3  G3  00  00  A#3 A#3 C4  C4  G#3 G#3 F3  F3  F3  F3  00  00
      Dez		37  37  00  00  35  35  00  00  30  30  00  00  37  37  00  00  32  32  00  00  35  35  37  37  33  33  30  30  30  30  00  00
    _Sin($x,_a('37 37 00 00 35 35 00 00 30 30 00 00 37 37 00 00 32 32 00 00 35 35 37 37 33 33 30 30 30 30 00 00',Mod(Int($x/2400),32)))
    
    
    Tieftöne:	00      C3      00      A#2     00      F2      00      C3      00      G2      00      A#2     00      G#2     00      00
      Dez       00      25      00      23      00      18      00      25      00      20      00      23      00      21      00      00
      _SSin($x,_a('00 25 00 23 00 18 00 25 00 20 00 23 00 21 00 00',Mod(Int($x/4800),16)))*Abs(Sin(0.0006545*$x))^0.5
    #ce
    
    
    ;~ C6 = 73
    ;~ 00
    ;~ G5
    ;~ G#5
    ;~ A#5 = 71
    ;~ 00
    ;~ G#5 = 69
    ;~ G5 = 68
    ;~ F5 = 66
    ;~ 00
    ;~ F5
    ;~ G#5
    ;~ C6
    ;~ 00
    ;~ A#5
    ;~ G#5
    ;~ G5
    ;~ 00
    ;~ G5
    ;~ G#5
    ;~ A#5
    ;~ 00
    ;~ C6
    ;~ 00
    ;~ G#5
    ;~ 00
    ;~ F5
    ;~ 00
    ;~ F5
    
    
    #include <GDIPlus.au3>
    
    
    Opt('GUIOnEventMode', 1)
    
    
    Global $bExit = False
    Global $iW = 512, $iH = 330
    
    
    Global $iGFXh = 155
    Global $iLadebalkenH = 16
    
    
    Global $iPlayTimer = 0, $iPlayTimerMax = 0
    Global $hWav
    Global $iSamplingRate
    Global $iBkColGFX = 0xFFE0E0E0
    Global $iBkColGUI = 0xFFEEEEEE
    
    
    Global $hGUI = GUICreate('SoundEdit', $iW, $iH + $iGFXh + $iLadebalkenH)
    GUISetBkColor(BitAND($iBkColGUI, 0xFFFFFF), $hGUI)
    
    
    GUICtrlCreateEdit('Länge ( ms )', 10, 10, 110, 20, 2049)
    GUICtrlCreateEdit('Samplingrate ( Hz )', 10, 50, 110, 20, 2049)
    GUICtrlCreateEdit('Capsize ( % )', 10, 90, 110, 20, 2049)
    GUICtrlCreateEdit('Gain ( 2^x )', 10, 130, 110, 20, 2049)
    
    
    Global $hSli_Len = GUICtrlCreateSlider(120, 10, $iW - 210, 30), $iRead_Len
    Global $hSli_Sam = GUICtrlCreateSlider(120, 50, $iW -210, 30), $iRead_Sam
    Global $hSli_Cap = GUICtrlCreateSlider(120, 90, $iW - 210, 30), $iRead_Cap
    Global $hSli_Gai = GUICtrlCreateSlider(120, 130, $iW - 210, 30), $iRead_Gai
    
    
    Global $hLab_Len = GUICtrlCreateEdit('0', $iW - 90, 10, 80, 20, 2049)
    Global $hLab_Sam = GUICtrlCreateEdit('0', $iW - 90, 50, 80, 20, 2049)
    Global $hLab_Cap = GUICtrlCreateEdit('0', $iW - 90, 90, 80, 20, 2049)
    Global $hLab_Gai = GUICtrlCreateEdit('0', $iW - 90, 130, 80, 20, 2049)
    
    
    Global $hLab_Fun = GUICtrlCreateEdit("(0.2*_SSin($x,a('00 97 97 00 00 95 95 00 00 90 90 00 00 97 97 00 00 92 92 00 00 95 95 00 00 93 93 00 00 90 90 00',Mod(Int($x/2400),32)))+0.5*_SSin($x,b('00 73 00 00 00 71 00 00 00 66 00 00 00 73 00 00 00 68 00 00 00 71 00 73 00 69 00 66 00 66 00 00',Mod(Int($x/2400),32)))+1.25*_SSin($x,c('61 00 56 57 59 00 57 56 54 00 54 57 61 00 59 57 56 00 56 57 59 00 61 00 57 00 54 00 54 00 00 00',Mod(Int($x/2400),32)))+0.25*_SSin($x,c('',Mod(Int($x/2400),32))-12)+_SSin($x,d('37 37 00 00 35 35 00 00 30 30 00 00 37 37 00 00 32 32 00 00 35 35 37 37 33 33 30 30 30 30 00 00',Mod(Int($x/2400),32))))*Abs(Sin(0.001309*$x))^0.5+1.25*_SSin($x,e('00 25 00 23 00 18 00 25 00 20 00 23 00 21 00 00',Mod(Int($x/4800),16)))*Abs(Sin(0.0006545*$x))^0.5", 10, 170, $iW - 20, 105, 1)
    GUICtrlSetFont(-1, 7, 400, 0, 'Arial', 5)
    
    
    ;~ Global $hLab_Snd = GUICtrlCreateEdit('', 10, 230, $iW - 20, 52, 2049)
    ;~ GUICtrlSetFont(-1, 9, 400, 0, 'Arial', 5)
    
    
    Global $hBtn_SS = GUICtrlCreateButton('Start',10, 290, 100, 30)
    GUICtrlSetOnEvent(-1, '_EVENT_StartStop')
    
    
    GUICtrlSetLimit($hSli_Len, 195, 0)
    GUICtrlSetData($hSli_Len, 145)
    GUICtrlSetLimit($hSli_Sam, 95, 0)
    GUICtrlSetData($hSli_Sam, 23)
    GUICtrlSetLimit($hSli_Cap, 50, 0)
    GUICtrlSetData($hSli_Cap, 5)
    GUICtrlSetLimit($hSli_Gai, 15, 0)
    GUICtrlSetData($hSli_Gai, 12)
    
    
    _GDIPlus_Startup()
    Global $hGFX = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Global $hBMP = _GDIPlus_BitmapCreateFromGraphics($iW, $iGFXh + $iLadebalkenH, $hGFX)
    Global $hBUF = _GDIPlus_ImageGetGraphicsContext($hBMP)
    Global $hBRU_BkColGFX = _GDIPlus_BrushCreateSolid($iBkColGFX)
    Global $hBRU_BkColGUI = _GDIPlus_BrushCreateSolid($iBkColGUI)
    Global $hBRU_VAR = _GDIPlus_BrushCreateSolid(0xFF20FF20)
    Global $hBRU_WHITE = _GDIPlus_BrushCreateSolid(0x40FFFFFF)
    Global $hPEN_VAR = _GDIPlus_PenCreate(0xFF000000, 1)
    Global $hPEN_BLACK = _GDIPlus_PenCreate(0x80FFFFFF, 1)
    Global $hBRU_LINVAR = _GDIPlus_LineBrushCreate(0, $iGFXh, 0, $iGFXh+$iLadebalkenH, 0xFF000000, 0xFFE0E0E0)
    
    
    _GDIPlus_GraphicsClear($hBUF, $iBkColGFX)
    _GFX_Neuzeichnen()
    
    
    GUIRegisterMsg(0xF, 'WM_PAINT')
    OnAutoItExitRegister('_Freigeben')
    GUISetState(@SW_SHOW, $hGUI)
    GUISetOnEvent(-3, '_Exit', $hGUI)
    
    
    While Sleep(10) And Not $bExit
    
    
    	_GUI_Slider($hSli_Gai, $hLab_Gai, CalcCap, $iRead_Gai)
    	_GUI_Slider($hSli_Len, $hLab_Len, CalcLen, $iRead_Len)
    	_GUI_Slider($hSli_Sam, $hLab_Sam, CalcSam, $iRead_Sam)
    	_GUI_Slider($hSli_Cap, $hLab_Cap, CalcCap, $iRead_Cap)
    
    
    	If Not $iPlayTimer = 0 Then
    		If TimerDiff($iPlayTimer) <= $iPlayTimerMax Then
    			_GFX_Ladebalken(TimerDiff($iPlayTimer)/$iPlayTimerMax, 0xFF41AFEB)
    		Else
    			_Play_Stop()
    		EndIf
    	EndIf
    
    
    WEnd
    
    
    Func _Play_Stop()
    	_WAV_Stop()
    	GUICtrlSetData($hBtn_SS, 'Start')
    	$iPlayTimerMax = 0
    	$iPlayTimer = 0
    	_GFX_Ladebalken(0)
    EndFunc
    
    
    Func _EVENT_StartStop()
    	$iPlayTimerMax = CalcLen($iRead_Len)
    	If Not $iPlayTimer = 0 Then
    		_Play_Stop()
    	Else
    		GUICtrlSetData($hBtn_SS, 'Stop')
    		RenderSnd()
    		_WAV_Play($hWav)
    		$iPlayTimer = TimerInit()
    	EndIf
    EndFunc
    
    
    Func RenderSnd()
    
    
    	Local $iLen = Int(CalcLen($iRead_Len))
    	Local $sFunc = GUICtrlRead($hLab_Fun)
    	Local $iCapSize = Int(CalcCap($iRead_Cap))
    	Local $iGain = 2^Int(CalcCap($iRead_Gai))
    	$iGain -= ($iGain = 2^15)*1
    
    
    	; Sollte (noch) global sein
    	$iSamplingRate = Int(CalcSam($iRead_Sam))
    	$hWav = _WAV_New($iLen)
    
    
    	Local $p = 3.1415926536
    	Local $l = $iLen/1000
    	Local $z
    
    
    	For $x = 1 To $hWav[2] Step 1
    		$z = $x/$l/$iSamplingRate
    		$hWav[0].WAVDATA(($x)) = Execute($sFunc) * $iGain
    		If IsInt($x/2000) Then _GFX_Ladebalken($x/$hWav[2], 0xFFB03EEB)
    	Next
    
    
    	_Wav_SmoothEdge($hWav, $iCapSize)
    	_GFX_Amp($hWav)
    	_GFX_FFT($hWav)
    	_GFX_Ladebalken(0)
    	WM_PAINT()
    
    
    EndFunc
    
    
    Func CalcCap($i)
    	Return $i
    EndFunc
    
    
    Func CalcLen($i)
    	Return Int(($i + 5)^1.75/10)*10
    EndFunc
    
    
    Func CalcSam($i)
    	Return Int($i * 500) + 500
    EndFunc
    
    
    Func _GFX_FFT(ByRef $hWav, $bEmpty = False) ; Boah, ich hab keinen Nerv hierfür
    	Local $W = $iW - 20 ; Wäre in AutoIt wahrscheinlich auch zu langsam. ASM Time...
    	Local $H = $iGFXh/2 - 20
    
    
    	_GDIPlus_GraphicsFillRect($hBUF, 0, $H+20, $W + 20, $H + 20, $hBRU_BkColGFX)
    	_GDIPlus_GraphicsDrawString($hBUF, 'FFT', 15, $H + 15 + 20)
    	_GDIPlus_PenSetColor($hPEN_VAR, 0xFF000000)
    	_GDIPlus_GraphicsDrawRect($hBUF, 8, $H + 28, $W + 4, $H + 4, $hPEN_VAR)
    
    
    	If $bEmpty Then Return
    
    
    EndFunc
    
    
    Func _GFX_Amp(ByRef $hWav, $bEmpty = False) ; Lautstärke -> Log(Abs Abweichung von der Ruhelage)
    	Local $W = $iW - 20, $H = $iGFXh/2 - 20
    
    
    	_GDIPlus_GraphicsFillRect($hBUF, 0, 0, $W + 20, $H + 20, $hBRU_BkColGFX)
    	_GDIPlus_GraphicsDrawString($hBUF, 'Amp', 15, 15)
    	_GDIPlus_PenSetColor($hPEN_VAR, 0xFF000000)
    	_GDIPlus_GraphicsDrawRect($hBUF, 8, 8, $W + 4, $H + 4, $hPEN_VAR)
    	If $bEmpty Then Return
    
    
    	; An jedem Punkt wird der Mittelwert der näheren Umgebung, sowie die Standardabweichung berechnet.
    	; Anschließend wird eine Kurve für m+s und eine fr m-s gezeichnet.
    	Local $iSteps = (Int(Log($hWav[2]) * 6) + 10), $iWidth = Int(($hWav[2]/$iSteps)^0.6), $iPos, $iMid, $iStdAbw, $aPoints1[$iSteps+1][2]=[[$iSteps]], $aPoints2[$iSteps+1][2]=[[$iSteps]]
    	$iWidth += IsInt($iWidth/2) ? 0 : 1 ; Muss gerade sein, da |x|x|x|m+-s|x|x|x
    
    
    ;~ 	ConsoleWrite('AMP: Steps: ' & $iSteps & ' iWidth: ' & $iWidth & ' Samples: ' & $hWav[2] & ' Cover: ' & $iSteps*$iWidth/$hWav[2]*100 & ' % ' & @CRLF)
    
    
    	For $i = 0 To $iSteps - 1 Step 1 ; Deckt nur einen Bruchteil der Daten ab und versucht ein möglichst gutes Bild zu geben.
    		_GFX_Ladebalken($i/($iSteps-1), 0xFFEB9A3E)
    		$iPos = Int(($i + 1) / $iSteps * $hWav[2])
    		$iMid = 0
    		$iStdAbw = 0
    		For $x = $iPos - $iWidth/2 To $iPos + $iWidth/2 Step 1
    			$iMid += Abs($hWav[0].WAVDATA(($x)))
    		Next
    		$iMid /= $iWidth
    		For $x = $iPos - $iWidth/2 To $iPos + $iWidth/2 Step 1
    			$iStdAbw += (Abs($hWav[0].WAVDATA(($x))) - $iMid)^2
    		Next
    		$iStdAbw = ($iStdAbw/$iWidth)^0.5
    		$aPoints1[$i+1][0] = 10 + $i/($iSteps-1) * $W
    		$aPoints1[$i+1][1] = 10 + $H - ((1+$iMid-$iStdAbw) <= 0 ? 0 : (Log(1+$iMid-$iStdAbw)/Log(32768))) * $H
    		$aPoints2[$i+1][0] = 10 + $i/($iSteps-1) * $W
    		$aPoints2[$i+1][1] = 10 + $H - ((1+$iMid+$iStdAbw) <= 0 ? 0 : (Log(1+$iMid+$iStdAbw)/Log(32768))) * $H
    	Next
    
    
    	_GDIPlus_GraphicsSetSmoothingMode($hBUF, 2)
    	_GDIPlus_PenSetColor($hPEN_VAR, 0xFFEE8020)
    	_GDIPlus_GraphicsDrawCurve2($hBUF, $aPoints1, 0, $hPEN_VAR)
    	_GDIPlus_PenSetColor($hPEN_VAR, 0xFFEE2080)
    	_GDIPlus_GraphicsDrawCurve2($hBUF, $aPoints2, 0, $hPEN_VAR)
    	_GDIPlus_GraphicsSetSmoothingMode($hBUF, 0)
    	_GFX_Ladebalken(0)
    
    
    EndFunc
    
    
    Func _GUI_Slider($hSli, $hLab, $xCalcFunc, ByRef $iRead)
    	If GUICtrlRead($hSli) <> $iRead Then
    		$iRead = GUICtrlRead($hSli)
    		GUICtrlSetData($hLab, $xCalcFunc($iRead))
    	EndIf
    EndFunc
    
    
    Func _GFX_Neuzeichnen()
    	Local $xTmp
    	_GFX_Ladebalken(0)
    	_GFX_Amp($xTmp, True)
    	_GFX_FFT($xTmp, True)
    EndFunc
    
    
    Func _WAV_Play(ByRef $hWav)
    	DllCall('winmm.dll', 'int', 'PlaySoundA', 'ptr', $hWav[1], 'int', 0, 'int', 5)
    EndFunc
    
    
    Func _WAV_Stop()
    	DllCall('winmm.dll', 'int', 'PlaySoundA', 'ptr', 0, 'int', 0, 'int', 0)
    EndFunc
    
    
    Func _WAV_New($iLen = 1000) ; Länge in Millisekunden
    	Local $hWav[5] = [DllStructCreate('char RIFF [4];uint FileSize;char WAVE [4];char fmt [4];uint fmt_len;word Format;word Channels;uint Samplerate;uint Bytes;word Block;word BitPerSample;char DATA [4];uint Len;short WAVDATA[' & Round($iLen / 1000, 3) * $iSamplingRate & ']')]
    	With $hWav[0]
    		.RIFF = 'RIFF'
    		.FileSize = 2 * Round($iLen / 1000, 3) * $iSamplingRate + 44 - 8
    		.WAVE = 'WAVE'
    		.fmt = 'fmt '
    		.fmt_len = 16
    		.Format = 1 ; PCM
    		.Channels = 1
    		.Samplerate = $iSamplingRate
    		.Bytes = $iSamplingRate * 2
    		.Block = 2
    		.BitPerSample = 16
    		.DATA = 'data'
    		.Len = 2 * Round($iLen / 1000, 3) * $iSamplingRate
    	EndWith
    	$hWav[1] = DllStructGetPtr($hWav[0])
    	$hWav[2] = Round($iLen / 1000, 3) * $iSamplingRate
    	$hWav[3] = DllStructGetPtr($hWav[0], 'WAVDATA')
    	$hWav[4] = 0
    	Return $hWav ; 0 -> DllStruct, 1 -> PTR, 2 -> Anzahl Samples, 3 -> PTR Wavdata, 4 -> RenderPos Wavdata
    EndFunc
    
    
    Func _Sin($x, $nNote) ; _Sin($x, 58) = Kammerton A
    	Return Sin($x/$iSamplingRate*2*3.14159*Freq($nNote))
    EndFunc
    
    
    Func _SSin($x, $nNote)
    	Return 3/4*Sin($x/$iSamplingRate*2*3.14159*Freq($nNote)) + 1/4*Sin(2*$x/$iSamplingRate*2*3.14159*Freq($nNote))
    EndFunc
    
    
    Func Freq($nNote)
    	Return 55*2^(($nNote-22)/12)
    EndFunc
    
    
    Func _Wav_SmoothEdge(ByRef $hWav, $iCapSize)
    	For $x = 1 To $iCapSize*$iSamplingRate/100 Step 1
    		If IsInt($x/1000) Then _GFX_Ladebalken($x/($iCapSize*$iSamplingRate/100), 0xFFB03EEB)
    		$hWav[0].WAVDATA(($x)) = $hWav[0].WAVDATA(($x)) * ExpAnstieg($x - 1, $iCapSize*$iSamplingRate/100, 0.00005)
    		$hWav[0].WAVDATA(($hWav[2] - $x + 1)) = $hWav[0].WAVDATA(($hWav[2] - $x + 1)) * ExpAnstieg($x - 1, $iCapSize*$iSamplingRate/100, 0.00005)
    	Next
    EndFunc
    
    
    Func ExpAnstieg($iPos, $iW, $nDelta)
    	Local $c = Log(1 / $nDelta - 1)
    	Return 1 / (1 + (2.718282) ^ (-$iPos / (($iW - 1) / 2 / $c) + $c))
    EndFunc
    
    
    Func _GFX_Ladebalken($iProzent, $iCol = 0)
    	If $iProzent > 0 Then
    		_GDIPlus_LineBrushSetColors($hBRU_LINVAR, '0xFF' & Hex(Int(BitAND(BitShift($iCol,16), 0xFF) + 16),2) & Hex(Int(BitAND(BitShift($iCol,8), 0xFF) + 16),2) & Hex(Int(BitAND($iCol, 0xFF) + 16),2), '0xFF' & Hex(Int(BitAND(BitShift($iCol,16), 0xFF) - 16),2) & Hex(Int(BitAND(BitShift($iCol,8), 0xFF) - 16),2) & Hex(Int(BitAND($iCol, 0xFF) - 16),2))
    		_GDIPlus_GraphicsFillRect($hBUF, 0, $iGFXh, $iW, $iLadebalkenH, $hBRU_BkColGUI)
    		_GDIPlus_GraphicsFillRect($hBUF, 0, $iGFXh , $iW * $iProzent, $iLadebalkenH, $hBRU_LINVAR)
    		_GDIPlus_GraphicsDrawRect($hBUF, 0, $iGFXh, $iW * $iProzent, $iLadebalkenH - 1, $hPEN_BLACK)
    		_GDIPlus_GraphicsFillRect($hBUF, 0, $iGFXh, $iW * $iProzent, $iLadebalkenH/2, $hBRU_WHITE)
    		_GDIPlus_GraphicsDrawImageRectRect($hGFX, $hBMP, 0, $iGFXh, $iW, $iLadebalkenH, 0, $iH + $iGFXh, $iW, $iLadebalkenH)
    	Else
    		_GDIPlus_GraphicsFillRect($hBUF, 0, $iGFXh, $iW, $iLadebalkenH, $hBRU_BkColGUI)
    		_GDIPlus_GraphicsDrawImageRectRect($hGFX, $hBMP, 0, $iGFXh, $iW, $iLadebalkenH, 0, $iH + $iGFXh, $iW, $iLadebalkenH)
    	EndIf
    EndFunc
    
    
    Func _Freigeben()
    	_GDIPlus_BrushDispose($hBRU_BkColGUI)
    	_GDIPlus_PenDispose($hPEN_BLACK)
    	_GDIPlus_BrushDispose($hBRU_LINVAR)
    	_GDIPlus_PenDispose($hPEN_VAR)
    	_GDIPlus_BrushDispose($hBRU_WHITE)
    	_GDIPlus_BrushDispose($hBRU_BkColGFX)
    	_GDIPlus_BrushDispose($hBRU_VAR)
    	_GDIPlus_GraphicsDispose($hBUF)
    	_GDIPlus_BitmapDispose($hBMP)
    	_GDIPlus_GraphicsDispose($hGFX)
    	_GDIPlus_Shutdown()
    EndFunc
    
    
    Func WM_PAINT()
    	_GDIPlus_GraphicsDrawImage($hGFX, $hBMP, 0, $iH)
    EndFunc
    
    
    Func _Exit()
    	$bExit = True
    EndFunc
    
    
    Func a($sString, $i = 0)
    	Local Static $Array = StringSplit($sString, ' ', 2)
    	Return $Array[$i]
    EndFunc
    
    
    Func b($sString, $i = 0)
    	Local Static $Array = StringSplit($sString, ' ', 2)
    	Return $Array[$i]
    EndFunc
    
    
    Func c($sString, $i = 0)
    	Local Static $Array = StringSplit($sString, ' ', 2)
    	Return $Array[$i]
    EndFunc
    
    
    Func d($sString, $i = 0)
    	Local Static $Array = StringSplit($sString, ' ', 2)
    	Return $Array[$i]
    EndFunc
    
    
    Func e($sString, $i = 0)
    	Local Static $Array = StringSplit($sString, ' ', 2)
    	Return $Array[$i]
    EndFunc
    Alles anzeigen
  • [Just 4 Fun] WAV Generator

    • Mars
    • 6. Mai 2015 um 17:49

    Für die Möglichkeit beliebig lange zu spielen habe ich eine Frage, denn bevor ich die Mechanik dazu baue will ich wissen ob das klappen kann.
    Kann man eine z.B. 1s lange WAV nutzen und als loop ($SND_LOOP) abspielen und hinter dem abgespielten den Inhalt verändern ?
    Dann könnte man eine kleine Wav nehmen und die in Echtzeit nachfüllen. (müsste mit AutoIt bei moderaten Samplingraten machbar sein).

  • [Just 4 Fun] WAV Generator

    • Mars
    • 6. Mai 2015 um 16:20

    Moin,
    Vor einiger Zeit habe ich eine lustige Seite zum Tönebasteln entdeckt: ByteBeat.
    Diese Angelegenheit fand ich sehr schön, also habe ich ein kleines Skript gebastelt welches ähnliche Spielereien ermöglicht.
    Es wird keine Javascriptsyntax unterstützt (wer hätte das gedacht), dafür aber alles was der AutoIt Interpreter zulässt :)

    Würde mich freuen wenn einige Leute Spaß daran finden, und ggf. sogar ein kleines Lied komponieren können :thumbup:

    AutoIt
    ; +++++ Wissenswertes +++++
    
    
    ; Funktionen:
    ; $x - Position innerhalb der WAV. Die funktion die man ins Feld eingibt f($x) berechnet die Amplitute (signed 16Bit Wert) zum Zeitpunkt des Samples
    ;    | Bei z.B. 8000 kHz werden 8000 Werte pro Sekunde berechnet und der Lautsprecher entsprechend bewegt. Man kann ihm also 8000 Mal pro Sekunde
    ;    | eine neue Position zwischen -(2^15-1) und 2^15-1 zuweisen. Töne ergeben sich durch wiederholtes neupositionieren. Frequenzen haben NICHTS mit der
    ;    | Ampliture zu tun die die Funktion berechnet, sondern mit der Periodizität der Funktion.
    ; $z - Läuft von 0 (Beginn des Sounds) bis 1 (Ende des Sounds)
    ; $p - Kreiszahl PI (braucht man villeicht für irgendwas)
    
    
    ; Allgemein können alle buildIn AutoIt Funktionen benutzt werden, da Execute benutzt wird bitte ich darum keinen Unfug zu treiben. Man kann sich auch
    ; eigene Funktionen schreiben die benutzt werden können. z.B. _Sin($x, $Ton) gibt bei $Ton = 58 den Kammerton A ohne Abhängigkeit der Samplingrate.
    
    
    ; Capsize
    ; - Verhindert Knacken der Lautsprecher beim ein- und Ausschalten des Tons
    
    
    ; Gain (2^x)
    ; - Töne werden als Signed 16Bit Werte gespeichert. Ein Sinus z.B. geht nur von -1 bis 1.
    ; | Mit einem Gain von 15 geht er von 2^15-1 bis 2^15
    ; - Ist oft nutzlos, wenn Töne via Überlauf erzeugt werden, z.B.
    
    
    ; Farbe der Ladebalken:
    ; Hellblau	- Musik wird abgespielt
    ; Lila		- Musik wird generiert
    ; Orange	- Grafischer Krimskrams wird erzeugt
    
    
    ; AMP = Amplitude = Lautstärke
    ; - Die Anzeige gibt einen Überblick über die Lautstärke des Sounds
    ; - Da nur ein Bruchteil der Samples analysiert wird ist die Anzeige nicht besonders genau.
    ; - Angezeigt werden 2 Kurven. Mittelwert + Stdandardabweichung und Mittelwert - Standardabweichung
    ; - Die Anzeige ist Logarithmisch
    
    
    ; 06.Mai.15
    ; SoundEdit von Mars@AutoIt.de
    
    
    
    
    #include <GDIPlus.au3>
    
    
    Opt('GUIOnEventMode', 1)
    
    
    Global $bExit = False
    Global $iW = 512, $iH = 330
    
    
    Global $iGFXh = 155
    Global $iLadebalkenH = 16
    
    
    Global $iPlayTimer = 0, $iPlayTimerMax = 0
    Global $hWav
    Global $iSamplingRate
    Global $iBkColGFX = 0xFFE0E0E0
    Global $iBkColGUI = 0xFFEEEEEE
    
    
    Global $hGUI = GUICreate('SoundEdit', $iW, $iH + $iGFXh + $iLadebalkenH)
    GUISetBkColor(BitAND($iBkColGUI, 0xFFFFFF), $hGUI)
    
    
    GUICtrlCreateEdit('Länge ( ms )', 10, 10, 110, 20, 2049)
    GUICtrlCreateEdit('Samplingrate ( Hz )', 10, 50, 110, 20, 2049)
    GUICtrlCreateEdit('Capsize ( % )', 10, 90, 110, 20, 2049)
    GUICtrlCreateEdit('Gain ( 2^x )', 10, 130, 110, 20, 2049)
    
    
    Global $hSli_Len = GUICtrlCreateSlider(120, 10, $iW - 210, 30), $iRead_Len
    Global $hSli_Sam = GUICtrlCreateSlider(120, 50, $iW -210, 30), $iRead_Sam
    Global $hSli_Cap = GUICtrlCreateSlider(120, 90, $iW - 210, 30), $iRead_Cap
    Global $hSli_Gai = GUICtrlCreateSlider(120, 130, $iW - 210, 30), $iRead_Gai
    
    
    Global $hLab_Len = GUICtrlCreateEdit('0', $iW - 90, 10, 80, 20, 2049)
    Global $hLab_Sam = GUICtrlCreateEdit('0', $iW - 90, 50, 80, 20, 2049)
    Global $hLab_Cap = GUICtrlCreateEdit('0', $iW - 90, 90, 80, 20, 2049)
    Global $hLab_Gai = GUICtrlCreateEdit('0', $iW - 90, 130, 80, 20, 2049)
    
    
    Global $hLab_Fun = GUICtrlCreateEdit('Mod(BitAnd(42,($x/2^10)),11)*$x', 10, 170, $iW - 20, 52, 1)
    GUICtrlSetFont(-1, 9, 400, 0, 'Arial', 5)
    
    
    Global $hLab_Snd = GUICtrlCreateEdit('', 10, 230, $iW - 20, 52, 2049)
    GUICtrlSetFont(-1, 9, 400, 0, 'Arial', 5)
    
    
    Global $hBtn_SS = GUICtrlCreateButton('Start',10, 290, 100, 30)
    GUICtrlSetOnEvent(-1, '_EVENT_StartStop')
    
    
    GUICtrlSetLimit($hSli_Len, 195, 0)
    GUICtrlSetData($hSli_Len, 50)
    GUICtrlSetLimit($hSli_Sam, 95, 0)
    GUICtrlSetData($hSli_Sam, 35)
    GUICtrlSetLimit($hSli_Cap, 50, 0)
    GUICtrlSetData($hSli_Cap, 5)
    GUICtrlSetLimit($hSli_Gai, 15, 0)
    GUICtrlSetData($hSli_Gai, 8)
    
    
    _GDIPlus_Startup()
    Global $hGFX = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Global $hBMP = _GDIPlus_BitmapCreateFromGraphics($iW, $iGFXh + $iLadebalkenH, $hGFX)
    Global $hBUF = _GDIPlus_ImageGetGraphicsContext($hBMP)
    Global $hBRU_BkColGFX = _GDIPlus_BrushCreateSolid($iBkColGFX)
    Global $hBRU_BkColGUI = _GDIPlus_BrushCreateSolid($iBkColGUI)
    Global $hBRU_VAR = _GDIPlus_BrushCreateSolid(0xFF20FF20)
    Global $hBRU_WHITE = _GDIPlus_BrushCreateSolid(0x40FFFFFF)
    Global $hPEN_VAR = _GDIPlus_PenCreate(0xFF000000, 1)
    Global $hPEN_BLACK = _GDIPlus_PenCreate(0x80FFFFFF, 1)
    Global $hBRU_LINVAR = _GDIPlus_LineBrushCreate(0, $iGFXh, 0, $iGFXh+$iLadebalkenH, 0xFF000000, 0xFFE0E0E0)
    
    
    _GDIPlus_GraphicsClear($hBUF, $iBkColGFX)
    _GFX_Neuzeichnen()
    
    
    GUIRegisterMsg(0xF, 'WM_PAINT')
    OnAutoItExitRegister('_Freigeben')
    GUISetState(@SW_SHOW, $hGUI)
    GUISetOnEvent(-3, '_Exit', $hGUI)
    
    
    While Sleep(10) And Not $bExit
    
    
    	_GUI_Slider($hSli_Gai, $hLab_Gai, CalcCap, $iRead_Gai)
    	_GUI_Slider($hSli_Len, $hLab_Len, CalcLen, $iRead_Len)
    	_GUI_Slider($hSli_Sam, $hLab_Sam, CalcSam, $iRead_Sam)
    	_GUI_Slider($hSli_Cap, $hLab_Cap, CalcCap, $iRead_Cap)
    
    
    	If Not $iPlayTimer = 0 Then
    		If TimerDiff($iPlayTimer) <= $iPlayTimerMax Then
    			_GFX_Ladebalken(TimerDiff($iPlayTimer)/$iPlayTimerMax, 0xFF41AFEB)
    		Else
    			_Play_Stop()
    		EndIf
    	EndIf
    
    
    WEnd
    
    
    Func _Play_Stop()
    	_WAV_Stop()
    	GUICtrlSetData($hBtn_SS, 'Start')
    	$iPlayTimerMax = 0
    	$iPlayTimer = 0
    	_GFX_Ladebalken(0)
    EndFunc
    
    
    Func _EVENT_StartStop()
    	$iPlayTimerMax = CalcLen($iRead_Len)
    	If Not $iPlayTimer = 0 Then
    		_Play_Stop()
    	Else
    		GUICtrlSetData($hBtn_SS, 'Stop')
    		RenderSnd()
    		_WAV_Play($hWav)
    		$iPlayTimer = TimerInit()
    	EndIf
    EndFunc
    
    
    Func RenderSnd()
    
    
    	Local $iLen = Int(CalcLen($iRead_Len))
    	Local $sFunc = GUICtrlRead($hLab_Fun)
    	Local $iCapSize = Int(CalcCap($iRead_Cap))
    	Local $iGain = 2^Int(CalcCap($iRead_Gai))
    	$iGain -= ($iGain = 2^15)*1
    
    
    	; Sollte (noch) global sein
    	$iSamplingRate = Int(CalcSam($iRead_Sam))
    	$hWav = _WAV_New($iLen)
    
    
    	Local $p = 3.1415926536
    	Local $l = $iLen/1000
    	Local $z
    
    
    	For $x = 1 To $hWav[2] Step 1
    		$z = $x/$l/$iSamplingRate
    		$hWav[0].WAVDATA(($x)) = Execute($sFunc) * $iGain
    		If IsInt($x/2000) Then _GFX_Ladebalken($x/$hWav[2], 0xFFB03EEB)
    	Next
    
    
    	_Wav_SmoothEdge($hWav, $iCapSize)
    	_GFX_Amp($hWav)
    	_GFX_FFT($hWav)
    	_GFX_Ladebalken(0)
    	WM_PAINT()
    
    
    EndFunc
    
    
    Func CalcCap($i)
    	Return $i
    EndFunc
    
    
    Func CalcLen($i)
    	Return Int(($i + 5)^1.75/10)*10
    EndFunc
    
    
    Func CalcSam($i)
    	Return Int($i * 500) + 500
    EndFunc
    
    
    Func _GFX_FFT(ByRef $hWav, $bEmpty = False) ; Boah, ich hab keinen Nerv hierfür
    	Local $W = $iW - 20 ; Wäre in AutoIt wahrscheinlich auch zu langsam. ASM Time...
    	Local $H = $iGFXh/2 - 20
    
    
    	_GDIPlus_GraphicsFillRect($hBUF, 0, $H+20, $W + 20, $H + 20, $hBRU_BkColGFX)
    	_GDIPlus_GraphicsDrawString($hBUF, 'FFT', 15, $H + 15 + 20)
    	_GDIPlus_PenSetColor($hPEN_VAR, 0xFF000000)
    	_GDIPlus_GraphicsDrawRect($hBUF, 8, $H + 28, $W + 4, $H + 4, $hPEN_VAR)
    
    
    	If $bEmpty Then Return
    
    
    EndFunc
    
    
    Func _GFX_Amp(ByRef $hWav, $bEmpty = False) ; Lautstärke -> Log(Abs Abweichung von der Ruhelage)
    	Local $W = $iW - 20, $H = $iGFXh/2 - 20
    
    
    	_GDIPlus_GraphicsFillRect($hBUF, 0, 0, $W + 20, $H + 20, $hBRU_BkColGFX)
    	_GDIPlus_GraphicsDrawString($hBUF, 'Amp', 15, 15)
    	_GDIPlus_PenSetColor($hPEN_VAR, 0xFF000000)
    	_GDIPlus_GraphicsDrawRect($hBUF, 8, 8, $W + 4, $H + 4, $hPEN_VAR)
    	If $bEmpty Then Return
    
    
    	; An jedem Punkt wird der Mittelwert der näheren Umgebung, sowie die Standardabweichung berechnet.
    	; Anschließend wird eine Kurve für m+s und eine fr m-s gezeichnet.
    	Local $iSteps = (Int(Log($hWav[2]) * 6) + 10), $iWidth = Int(($hWav[2]/$iSteps)^0.6), $iPos, $iMid, $iStdAbw, $aPoints1[$iSteps+1][2]=[[$iSteps]], $aPoints2[$iSteps+1][2]=[[$iSteps]]
    	$iWidth += IsInt($iWidth/2) ? 0 : 1 ; Muss gerade sein, da |x|x|x|m+-s|x|x|x
    
    
    ;~ 	ConsoleWrite('AMP: Steps: ' & $iSteps & ' iWidth: ' & $iWidth & ' Samples: ' & $hWav[2] & ' Cover: ' & $iSteps*$iWidth/$hWav[2]*100 & ' % ' & @CRLF)
    
    
    	For $i = 0 To $iSteps - 1 Step 1 ; Deckt nur einen Bruchteil der Daten ab und versucht ein möglichst gutes Bild zu geben.
    		_GFX_Ladebalken($i/($iSteps-1), 0xFFEB9A3E)
    		$iPos = Int(($i + 1/$iSteps) / $iSteps * $hWav[2])
    		$iMid = 0
    		$iStdAbw = 0
    		For $x = $iPos - $iWidth/2 To $iPos + $iWidth/2 Step 1
    			$iMid += Abs($hWav[0].WAVDATA(($x)))
    		Next
    		$iMid /= $iWidth
    		For $x = $iPos - $iWidth/2 To $iPos + $iWidth/2 Step 1
    			$iStdAbw += (Abs($hWav[0].WAVDATA(($x))) - $iMid)^2
    		Next
    		$iStdAbw = ($iStdAbw/$iWidth)^0.5
    		$aPoints1[$i+1][0] = 10 + $i/($iSteps-1) * $W
    		$aPoints1[$i+1][1] = 10 + $H - ((1+$iMid-$iStdAbw) <= 0 ? 0 : (Log(1+$iMid-$iStdAbw)/Log(32768))) * $H
    		$aPoints2[$i+1][0] = 10 + $i/($iSteps-1) * $W
    		$aPoints2[$i+1][1] = 10 + $H - ((1+$iMid+$iStdAbw) <= 0 ? 0 : (Log(1+$iMid+$iStdAbw)/Log(32768))) * $H
    	Next
    
    
    	_GDIPlus_GraphicsSetSmoothingMode($hBUF, 2)
    	_GDIPlus_PenSetColor($hPEN_VAR, 0xFFEE8020)
    	_GDIPlus_GraphicsDrawCurve2($hBUF, $aPoints1, 0, $hPEN_VAR)
    	_GDIPlus_PenSetColor($hPEN_VAR, 0xFFEE2080)
    	_GDIPlus_GraphicsDrawCurve2($hBUF, $aPoints2, 0, $hPEN_VAR)
    	_GDIPlus_GraphicsSetSmoothingMode($hBUF, 0)
    	_GFX_Ladebalken(0)
    
    
    EndFunc
    
    
    Func _GUI_Slider($hSli, $hLab, $xCalcFunc, ByRef $iRead)
    	If GUICtrlRead($hSli) <> $iRead Then
    		$iRead = GUICtrlRead($hSli)
    		GUICtrlSetData($hLab, $xCalcFunc($iRead))
    	EndIf
    EndFunc
    
    
    Func _GFX_Neuzeichnen()
    	Local $xTmp
    	_GFX_Ladebalken(0)
    	_GFX_Amp($xTmp, True)
    	_GFX_FFT($xTmp, True)
    EndFunc
    
    
    Func _WAV_Play(ByRef $hWav)
    	DllCall('winmm.dll', 'int', 'PlaySoundA', 'ptr', $hWav[1], 'int', 0, 'int', 5)
    EndFunc
    
    
    Func _WAV_Stop()
    	DllCall('winmm.dll', 'int', 'PlaySoundA', 'ptr', 0, 'int', 0, 'int', 0)
    EndFunc
    
    
    Func _WAV_New($iLen = 1000) ; Länge in Millisekunden
    	Local $hWav[5] = [DllStructCreate('char RIFF [4];uint FileSize;char WAVE [4];char fmt [4];uint fmt_len;word Format;word Channels;uint Samplerate;uint Bytes;word Block;word BitPerSample;char DATA [4];uint Len;short WAVDATA[' & Round($iLen / 1000, 3) * $iSamplingRate & ']')]
    	With $hWav[0]
    		.RIFF = 'RIFF'
    		.FileSize = 2 * Round($iLen / 1000, 3) * $iSamplingRate + 44 - 8
    		.WAVE = 'WAVE'
    		.fmt = 'fmt '
    		.fmt_len = 16
    		.Format = 1 ; PCM
    		.Channels = 1
    		.Samplerate = $iSamplingRate
    		.Bytes = $iSamplingRate * 2
    		.Block = 2
    		.BitPerSample = 16
    		.DATA = 'data'
    		.Len = 2 * Round($iLen / 1000, 3) * $iSamplingRate
    	EndWith
    	$hWav[1] = DllStructGetPtr($hWav[0])
    	$hWav[2] = Round($iLen / 1000, 3) * $iSamplingRate
    	$hWav[3] = DllStructGetPtr($hWav[0], 'WAVDATA')
    	$hWav[4] = 0
    	Return $hWav ; 0 -> DllStruct, 1 -> PTR, 2 -> Anzahl Samples, 3 -> PTR Wavdata, 4 -> RenderPos Wavdata
    EndFunc
    
    
    Func _Sin($x, $nNote) ; _Sin($x, 58) = Kammerton A
    	Return Sin($x/$iSamplingRate*2*3.14159*Freq($nNote))
    EndFunc
    
    
    Func Freq($nNote)
    	Return 55*2^(($nNote-22)/12)
    EndFunc
    
    
    Func _Wav_SmoothEdge(ByRef $hWav, $iCapSize)
    	For $x = 1 To $iCapSize*$iSamplingRate/100 Step 1
    		If IsInt($x/1000) Then _GFX_Ladebalken($x/($iCapSize*$iSamplingRate/100), 0xFFB03EEB)
    		$hWav[0].WAVDATA(($x)) = $hWav[0].WAVDATA(($x)) * ExpAnstieg($x - 1, $iCapSize*$iSamplingRate/100, 0.00005)
    		$hWav[0].WAVDATA(($hWav[2] - $x + 1)) = $hWav[0].WAVDATA(($hWav[2] - $x + 1)) * ExpAnstieg($x - 1, $iCapSize*$iSamplingRate/100, 0.00005)
    	Next
    EndFunc
    
    
    Func ExpAnstieg($iPos, $iW, $nDelta)
    	Local $c = Log(1 / $nDelta - 1)
    	Return 1 / (1 + (2.718282) ^ (-$iPos / (($iW - 1) / 2 / $c) + $c))
    EndFunc
    
    
    Func _GFX_Ladebalken($iProzent, $iCol = 0)
    	If $iProzent > 0 Then
    		_GDIPlus_LineBrushSetColors($hBRU_LINVAR, '0xFF' & Hex(Int(BitAND(BitShift($iCol,16), 0xFF) + 16),2) & Hex(Int(BitAND(BitShift($iCol,8), 0xFF) + 16),2) & Hex(Int(BitAND($iCol, 0xFF) + 16),2), '0xFF' & Hex(Int(BitAND(BitShift($iCol,16), 0xFF) - 16),2) & Hex(Int(BitAND(BitShift($iCol,8), 0xFF) - 16),2) & Hex(Int(BitAND($iCol, 0xFF) - 16),2))
    		_GDIPlus_GraphicsFillRect($hBUF, 0, $iGFXh, $iW, $iLadebalkenH, $hBRU_BkColGUI)
    		_GDIPlus_GraphicsFillRect($hBUF, 0, $iGFXh , $iW * $iProzent, $iLadebalkenH, $hBRU_LINVAR)
    		_GDIPlus_GraphicsDrawRect($hBUF, 0, $iGFXh, $iW * $iProzent, $iLadebalkenH - 1, $hPEN_BLACK)
    		_GDIPlus_GraphicsFillRect($hBUF, 0, $iGFXh, $iW * $iProzent, $iLadebalkenH/2, $hBRU_WHITE)
    		_GDIPlus_GraphicsDrawImageRectRect($hGFX, $hBMP, 0, $iGFXh, $iW, $iLadebalkenH, 0, $iH + $iGFXh, $iW, $iLadebalkenH)
    	Else
    		_GDIPlus_GraphicsFillRect($hBUF, 0, $iGFXh, $iW, $iLadebalkenH, $hBRU_BkColGUI)
    		_GDIPlus_GraphicsDrawImageRectRect($hGFX, $hBMP, 0, $iGFXh, $iW, $iLadebalkenH, 0, $iH + $iGFXh, $iW, $iLadebalkenH)
    	EndIf
    EndFunc
    
    
    Func _Freigeben()
    	_GDIPlus_BrushDispose($hBRU_BkColGUI)
    	_GDIPlus_PenDispose($hPEN_BLACK)
    	_GDIPlus_BrushDispose($hBRU_LINVAR)
    	_GDIPlus_PenDispose($hPEN_VAR)
    	_GDIPlus_BrushDispose($hBRU_WHITE)
    	_GDIPlus_BrushDispose($hBRU_BkColGFX)
    	_GDIPlus_BrushDispose($hBRU_VAR)
    	_GDIPlus_GraphicsDispose($hBUF)
    	_GDIPlus_BitmapDispose($hBMP)
    	_GDIPlus_GraphicsDispose($hGFX)
    	_GDIPlus_Shutdown()
    EndFunc
    
    
    Func WM_PAINT()
    	_GDIPlus_GraphicsDrawImage($hGFX, $hBMP, 0, $iH)
    EndFunc
    
    
    Func _Exit()
    	$bExit = True
    EndFunc
    Alles anzeigen


    Hab den Editor jetzt intern etwas aufgeräumt und den Gain als neue Einstellung hinzugefügt. (In Bezug auf die Version die ich mal in der SB gepostet habe)

    lg
    M

  • Rationale Approximation

    • Mars
    • 19. April 2015 um 20:14

    Thema ist damit gelöst.

    [autoit][/autoit][autoit][/autoit][autoit]

    Global $e = 2.71828182846
    Global $pi = 3.14159265359
    Global $ap = 1.20205690316

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Local $1 = FareyApprox($e, 255)
    Local $2 = FareyApprox($pi, 255)
    Local $3 = FareyApprox($ap, 255)

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    ConsoleWrite('e : ' & $1[0] & '/' & $1[1] & ' Err: ' & $1[0]/$1[1] - $e & @CRLF)
    ConsoleWrite('pi : ' & $2[0] & '/' & $2[1] & ' Err: ' & $2[0]/$2[1] - $pi & @CRLF)
    ConsoleWrite('ap : ' & $3[0] & '/' & $3[1] & ' Err: ' & $3[0]/$3[1] - $ap & @CRLF)

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func FareyApprox($x, $N)
    If $x > 1 Then
    Local $t = FareyApprox(1 / $x, $N)
    Return Array($t[1], $t[0])
    EndIf
    Local $a = 0, $b = 1, $c = 1, $d = 1, $m
    While ($b <= $N And $d <= $N)
    $m = ($a + $c) / ($b + $d)
    If $x = $m Then
    Return $b + $d <= $N ? Array($a + $c, $b + $d) : $d > $b ? Array($c, $d) : Array($a, $b)
    ElseIf $x > $m Then
    $a += $c
    $b += $d
    Else
    $c += $a
    $d += $b
    EndIf
    WEnd
    Return $b > $N ? Array($c, $d) : Array($a, $b)
    EndFunc

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func Array($x1, $x2) ; Keiner weiß warum es das nicht nativ in AutoIt gibt... ein Mysterium :(
    Local $aRet[2] = [$x1, $x2]
    Return $aRet
    EndFunc

    [/autoit]
  • Forum Problemsammlung

    • Mars
    • 19. April 2015 um 18:31

    Der Plan wäre also eine Sammlung von allem kürzlichen (also wichtiges was erst nach dem Update ins Forum kam) -> Umzug auf 3.1 -> Integrieren der "verlorenen" Sachen -> Problem solved.
    Wird auf jedenfall ein Knochenjob, aber es wird wahrscheinlich einfacher als den Unfug hier jedes Mal wieder aufzuräumen.

  • Forum Problemsammlung

    • Mars
    • 19. April 2015 um 16:10
    Zitat von Andy

    zum "ganz alten" Forum

    ^ +1

  • Rationale Approximation

    • Mars
    • 19. April 2015 um 15:56

    Moin,
    Ich suche eine effizientere Methode als Brute Force. Mein Skript funktioniert zwar, aber für große Zahlen ist BF zu langsam...

    Edit: Der Code wurde zerschossen. Da er aber sowieso überholt ist versuche ich nicht ihn zu rekonstruieren. Die Lösung ist in Post 4.

    lg
    M

  • Forum Problemsammlung

    • Mars
    • 19. April 2015 um 12:08

    Das mit den verlorenen Dateianhängen ist nicht nur deshalb ärgerlich, weil man die Kopie auf dem eigenen Rechner erst suchen muss, sondern auch weil man unzählige Threads hat in denen man etwas hochgeladen hat. Ich habe das auch schon bemerkt, habe aber keine Lust bei 100+ Threads neue Anhänge hochzuladen.

  • Variable als INI behandeln?

    • Mars
    • 18. April 2015 um 22:59

    Nur als Info:
    Hab vor geraumer Zeit eine ArrayToStringExUDF geschrieben. Die sollte 1D und 2D Arrays mit beliebigem Inhalt in Text und umgekehrt verwandeln können. Und zwar OHNE Split Zeichen und damit MIT vollem Asc Umfang. (Da es keinen Seperator gibt können im Array beliebige Zeichen auftreten ohne das es Probleme gibt).

    Spoiler anzeigen
    [autoit]


    #include-once
    ;~ #include 'StringPop.au3'

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; Anmerkung zur UDF =============================================================================================================
    ; Nicht Implementiert: Map, DllStruct, Object
    ; - Map: wird nachgereicht, sobald die nächste Stable Maps unterstützt und ich genug Zeit und Lust habe
    ; - DllStruct: Problemkind, da es keine Möglichkeit gibt anhand einer Structvariable auf die eigentliche Struktur zu schließen (z.B. 'int abc[2]')
    ; - Object: Da Objekte grundsätzlich "Alles" sein können ist es unmöglich sie als Ganzes (vorallem Zeitunabhängig) in einem String zu speichern.
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #INDEX# =======================================================================================================================
    ; Title .........: ArrayToStringEx
    ; AutoIt Version : 3.3.12.0
    ; Date ..........: 21.08.2014
    ; Language ......: Deutsch
    ; Description ...: Funktion um 1D oder 2D Arrays in Strings umzuwandeln incl. Umkehrfunktion
    ; Author(s) .....: Mars
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #CURRENT# =====================================================================================================================
    ; _ArrayToStringEx
    ; _StringToArrayEx
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY# ===========================================================================================================
    ; __ArrayToString1D
    ; __Double
    ; __StringToArray1D
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global Const $___HexLen_UBound = 6 ; Maximal mögliche Arrayelemente = 2^24
    Global Const $___HexLen_ArraySubscripts = 2 ; Maximal 64 Stück
    Global Const $___HexLen_Empty = 0 ; Wird nicht verwendet
    Global Const $___HexLen_uInt8 = 2 ; Nur interne Benutzung
    Global Const $___HexLen_uInt16 = 4 ; Nur interne Benutzung
    Global Const $___HexLen_Int32 = 8
    Global Const $___HexLen_Int64 = 16
    Global Const $___HexLen_Double = 16
    Global Const $___HexLen_Ptr = 16 ; Mit 64 Bit sind in jedem Fall x86 und x64 Systeme abgesichert
    Global Const $___HexLen_Bool = 2 ; Eigentlich nur 1 Bit, wir nehmen aber 1 Byte !
    Global Const $___HexLen_Keyword = 2 ; Wird nicht verwendet
    Global Const $___MaxLen_String = 8 ; 2^32 Zeichen
    Global Const $___MaxLen_Binary = 8 ; 2^32 Zeichen
    Global Const $___MaxLen_FuncName = 2 ; 256 Zeichen
    Global Const $___MaxLen_ArrayString = $___MaxLen_String
    Global Const $___MaxLen_MapString = $___MaxLen_String
    Global Const $___MaxLen_DllStructString = $___MaxLen_String

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global Const $___HexLen_ID = 2
    Global Const $___ID_Empty = '00'
    Global Const $___ID_uInt8 = '01' ; Nur interne Benutzung
    Global Const $___ID_uInt16 = '02' ; Nur interne Benutzung
    Global Const $___ID_Int32 = '03'
    Global Const $___ID_Int64 = '04'
    Global Const $___ID_Double = '05'
    Global Const $___ID_String = '06'
    Global Const $___ID_Binary = '07'
    Global Const $___ID_Ptr = '08'
    Global Const $___ID_Bool = '09'
    Global Const $___ID_Array = '0A'
    Global Const $___ID_Function = '0B'
    Global Const $___ID_Map = '0C'
    Global Const $___ID_DllStruct = '0D'
    Global Const $___ID_Keyword = '0E'

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Author ........: Mars
    ; Description ...: Wandelt ein 1D oder 2D Array in einen String um
    ; ===============================================================================================================================
    Func _ArrayToStringEx($aArray) ; Für 1D und 2D Arrays
    If Not IsArray($aArray) Then Return
    Local $iDim = UBound($aArray, 0)
    If $iDim = 1 Then
    Return BinaryToString('0x' & Hex($iDim, $___HexLen_ArraySubscripts) & StringTrimLeft(StringToBinary(__ArrayToString1D($aArray)), 2))
    Else ; 2D
    Local $aSub[2] = [UBound($aArray, 1), UBound($aArray, 2)], $sTmp = ''
    Local $sRet = Hex($iDim, $___HexLen_ArraySubscripts) & Hex($aSub[0], $___HexLen_UBound) & Hex($aSub[1], $___HexLen_UBound)
    For $i = 0 To $aSub[0] - 1 Step 1
    $sTmp = StringTrimLeft(StringToBinary(__ArrayToString1D($aArray, $i)), 2)
    $sRet &= Hex(StringLen($sTmp), $___MaxLen_ArrayString) & $sTmp
    Next
    Return BinaryToString('0x' & $sRet)
    EndIf
    EndFunc ;==>_ArrayToStringEx

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Author ........: Mars
    ; Description ...: Wandelt einen String in ein 1D oder 2D Array um
    ; ===============================================================================================================================
    Func _StringToArrayEx($sString)
    If $sString = '' Then Return
    __ValidString($sString)
    Local $iDim = StringPopInt($sString, $___HexLen_ArraySubscripts)
    If $iDim = 1 Then
    Return __StringToArray1D($sString)
    Else ; 2D
    Local $aSub[2] = [StringPopInt($sString, $___HexLen_UBound), StringPopInt($sString, $___HexLen_UBound)]
    Local $aRet[$aSub[0]][$aSub[1]], $iLen
    For $i = 0 To $aSub[0] - 1 Step 1
    $iLen = StringPopInt($sString, $___MaxLen_ArrayString)
    Local $a = __StringToArray1D(StringPop($sString, $iLen))
    For $o = 0 To $aSub[1] - 1 Step 1
    $aRet[$i][$o] = $a[$o]
    Next
    Next
    Return $aRet
    EndIf
    EndFunc ;==>_StringToArrayEx

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region - Internal

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY# ===========================================================================================================
    ; Author ........: Mars
    ; Description ...: Hilfsfunktion für _ArrayToStringEx
    ; ===============================================================================================================================
    Func __ArrayToString1D($aArray, $iIndex = 0)
    If Not IsArray($aArray) Then Return
    Local $iUBound
    If UBound($aArray, 0) = 2 Then ; 2D Array
    $iUBound = UBound($aArray, 2)
    Local $aLinear[$iUBound]
    For $i = 0 To $iUBound - 1 Step 1
    $aLinear[$i] = $aArray[$iIndex][$i]
    Next
    $aArray = $aLinear
    Else
    $iUBound = UBound($aArray)
    EndIf
    Local $sTmp = '', $sRet = Hex($iUBound, $___HexLen_UBound)
    For $i = 0 To $iUBound - 1 Step 1
    Switch VarGetType($aArray[$i])
    Case 'Int32'
    If $aArray[$i] >= 0 And $aArray[$i] < 256 Then
    $sRet &= $___ID_uInt8 & Hex($aArray[$i], $___HexLen_uInt8)
    ElseIf $aArray[$i] >= 0 And $aArray[$i] < 65536 Then
    $sRet &= $___ID_uInt16 & Hex($aArray[$i], $___HexLen_uInt16)
    Else
    $sRet &= $___ID_Int32 & Hex($aArray[$i], $___HexLen_Int32)
    EndIf
    Case 'Int64'
    $sRet &= $___ID_Int64 & Hex($aArray[$i], $___HexLen_Int64)
    Case 'Double'
    $sRet &= $___ID_Double & Hex($aArray[$i], $___HexLen_Double)
    Case 'String'
    $sRet &= ($aArray[$i] = '' ? $___ID_Empty : $___ID_String & Hex(StringLen($aArray[$i]), $___MaxLen_String) & StringTrimLeft(StringToBinary($aArray[$i]), 2))
    Case 'Binary'
    $sRet &= $___ID_Binary & Hex(BinaryLen($aArray[$i]), $___MaxLen_Binary) & StringTrimLeft($aArray[$i], 2)
    Case 'Ptr'
    $sRet &= $___ID_Ptr & Hex($aArray[$i], $___HexLen_Ptr)
    Case 'Bool'
    $sRet &= $___ID_Bool & Hex($aArray[$i], $___HexLen_Bool)
    Case 'Array'
    $sTmp = _ArrayToStringEx($aArray[$i])
    $sRet &= $___ID_Array & Hex(Int(StringLen($sTmp)), $___MaxLen_ArrayString) & StringTrimLeft(StringToBinary($sTmp), 2)
    $sTmp = ''
    Case 'Function'
    $sRet &= $___ID_Function & Hex(StringLen(FuncName($aArray[$i])), $___MaxLen_FuncName) & StringTrimLeft(StringToBinary(FuncName($aArray[$i])), 2)
    Case 'Map' ; ########## Nicht Implementiert ##########
    Case 'DLLStruct' ; ########## Nicht Implementiert ##########
    Case 'Keyword'
    $sRet &= $___ID_Keyword & ($aArray[$i] = Default ? '01' : '00')
    Case Else
    ConsoleWrite('! Error: Unbekannter Variablentyp: ' & VarGetType($aArray[$i]) & @CRLF)
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Next
    Return BinaryToString('0x' & $sRet)
    EndFunc ;==>__ArrayToString1D

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY# ===========================================================================================================
    ; Author ........: Mars
    ; Description ...: Hilfsfunktion für _StringToArrayEx
    ; ===============================================================================================================================
    Func __StringToArray1D($sString)
    If $sString = '' Then Return
    __ValidString($sString)
    Local $iUBound = StringPopInt($sString, $___HexLen_UBound)
    Local $aRet[$iUBound], $sTmp = ''
    For $i = 0 To $iUBound - 1 Step 1
    $sTmp = StringPop($sString, $___HexLen_ID)
    Switch $sTmp
    Case $___ID_Empty
    ; Hier muss nichts gemacht werden
    Case $___ID_uInt8
    $aRet[$i] = StringPopInt($sString, $___HexLen_uInt8)
    Case $___ID_uInt16
    $aRet[$i] = StringPopInt($sString, $___HexLen_uInt16)
    Case $___ID_Int32
    $aRet[$i] = StringPopInt($sString, $___HexLen_Int32)
    Case $___ID_Int64
    $aRet[$i] = StringPopInt($sString, $___HexLen_Int64)
    Case $___ID_Double
    $aRet[$i] = __Double(StringPop($sString, $___HexLen_Double))
    Case $___ID_String
    $aRet[$i] = BinaryToString('0x' & StringPop($sString, 2 * StringPopInt($sString, $___MaxLen_String)))
    Case $___ID_Binary
    $aRet[$i] = Binary('0x' & StringPop($sString, 2 * StringPopInt($sString, $___MaxLen_Binary)))
    Case $___ID_Ptr
    $aRet[$i] = Ptr('0x' & StringPop($sString, $___HexLen_Ptr))
    Case $___ID_Bool
    $aRet[$i] = StringPopInt($sString, $___HexLen_Bool) = 1
    Case $___ID_Array
    $sTmp = _StringToArrayEx(StringPop($sString, 2 * StringPopInt($sString, $___MaxLen_ArrayString)))
    $aRet[$i] = $sTmp
    $sTmp = ''
    Case $___ID_Function
    $aRet[$i] = Execute(BinaryToString('0x' & StringPop($sString, 2 * StringPopInt($sString, $___MaxLen_FuncName))))
    Case $___ID_Map ; ########## Nicht Implementiert ##########
    Case $___ID_DllStruct ; ########## Nicht Implementiert ##########
    Case $___ID_Keyword
    $aRet[$i] = (StringPopInt($sString, 2) = 1 ? Default : Null)
    Case Else
    ConsoleWrite('! Error: Unbekannter Variablentyp: ID = ' & $sTmp & @CRLF)
    EndSwitch
    Next
    Return $aRet
    EndFunc ;==>__StringToArray1D

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY# ===========================================================================================================
    ; Author ........: Mars
    ; Description ...: Hilfsfunktion für _StringToArrayEx und __StringToArray1D
    ; ===============================================================================================================================
    Func __ValidString(ByRef $sString)
    If Not StringIsXDigit($sString) Then
    If IsBinary($sString) Then
    $sString = StringTrimLeft($sString, 2)
    Else
    $sString = StringTrimLeft(StringToBinary($sString), 2)
    EndIf
    EndIf
    EndFunc ;==>__ValidString

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #INTERNAL_USE_ONLY# ===========================================================================================================
    ; Author ........: Mars
    ; Description ...: Cast Hex64-String -> Double | _Double('400921F9F01B866E') = 3.14159
    ; ===============================================================================================================================
    Func __Double($sHex64)
    Local $vInt64 = DllStructCreate('INT64'), $nRet
    DllStructSetData($vInt64, 1, '0x' & $sHex64)
    Local $vDouble = DllStructCreate('Double', DllStructGetPtr($vInt64))
    $nRet = DllStructGetData($vDouble, 1)
    Return $nRet
    EndFunc ;==>__Double

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #EndRegion - Internal
    ;EndRegion - Internal

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region - StringPop

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #INDEX# =======================================================================================================================
    ; Title .........: StringPop
    ; AutoIt Version : 3.3.12.0
    ; Date ..........: 18.07.2014
    ; Language ......: Deutsch
    ; Description ...: Funktion um das Ende (links oder rechts) eines Strings abzuschneiden und zurückzugeben
    ; Author(s) .....: Mars
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #CURRENT# =====================================================================================================================
    ; StringPop
    ; StringPopInt
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Author ........: Mars
    ; Example .......: $s = '01234' | $sRet = __StringPopInt($s, 3) -> $s = '34' | $sRet = '012'
    ; ===============================================================================================================================
    Func StringPop(ByRef $sString, $iCount = 1)
    If $iCount > 0 Then
    Local $sLeft = StringLeft($sString, $iCount)
    $sString = StringTrimLeft($sString, $iCount)
    Return $sLeft
    Else
    Local $sRight = StringRight($sString, -$iCount)
    $sString = StringTrimRight($sString, -$iCount)
    Return $sRight
    EndIf
    EndFunc ;==>StringPop

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Author ........: Mars
    ; Example .......: $s = '01234' | $iRet = __StringPopInt($s, 2) -> $s = '234' | $iRet = Int(0x01) = 1
    ; ===============================================================================================================================
    Func StringPopInt(ByRef $sString, $iCount = 1)
    Return Int('0x' & StringPop($sString, $iCount))
    EndFunc ;==>StringPopInt

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #EndRegion - StringPop
    ;EndRegion - StringPop

    [/autoit]
  • Deepweb ?

    • Mars
    • 9. April 2015 um 18:16

    Die Story stimmt so eh nicht, zu viele Zufälle. Da hat wohl jemand Hosten 3 geschaut. -> Creepypasta (Wortneuschöpfung der letzten Jahre).
    Das meiste was zu den 90% zählt die nicht von Suchmaschinen gefunden werden sind kleine versplitterte Datensammlungen. Das erinnert mich immer an das Uninetz wo jeder via DC++ irgendwelchen Mist freigeben kann und im Ausgleich Zugriff auf alle Daten aller anderen Nutzer hat. Da ist man zwar nicht anonym, aber dennoch wird (fast) alles was man sich vorstellen kann freigegeben.

  • Rundumschlag GDI+

    • Mars
    • 7. April 2015 um 02:46

    Du bezeichnest den Einfachpuffer als Doppelpuffer.
    Ein Doppelpuffer besteht aus 2 unsichtbaren Bitmappuffern die jeweils ein eigenes GFX (unabhängig vom GFX des GUI) haben. Ein Anwendungsbeispiel ist z.B. eine Zeichenfunktion die sehr viel Zeit in Anspruch nimmt. Tritt ein WM_PAINT während dieses Vorgangs auf, so wird der bisher nicht komplett aufgebaute Puffer in die GUI gebeamt -> Unvollständiges Ergebnis. Ein Doppelpuffer behält immer ein bereits fertiges Bild in der Hinterhand, ist der langwierige Zeichenvorgang abgeschlossen, so werden die Pufferadressen von Backbuffer 1 und Backbuffer 2 getauscht (klassiker -> kein Zeitverlust), sodass ein ggf Auftretendes WM_PAINT IMMER ein vollständig aufgebautes Bild zur Verfügung hat.

    Edit:
    Das klingt jetzt eventuell zu negativ. Das soll konstruktive Kritik sein ;)

    M

  • Revision 2015

    • Mars
    • 6. April 2015 um 17:00

    Das Botimage bekommt man aus AutoIt auch nicht wieder raus, egal was man anstellt.
    Das mit den Lappen ist aber sehr witzig :P (bin selbst auch ein Lappen)

    Edit1:
    Schaut mal bei Google nach "Bytebeat". Da findet man z.B. sowas: http://greggman.com/downloads/exam…l5bytebeat.html
    Vorteil der Sache ist: Der Interpreter ist wahrscheinlich ein Einzeiler (oder wenigstens in einer sehr kleinen Funktion verpackbar). Hab mich leider mit Tönen noch nie wirklich auseinandergesetzt, daher weiß ich zwar die man den Interpreter theoretisch bauen muss (-> im Prinzip wird einfach eine Wavedatei via Formel und fortlaufendem t generiert), aber ich habe keine Ahnung wie man das in Echtzeit abspielt. (eine Wave schreiben und die abspielen kann ich schon^^). Wenn wir da einen Interpreter basteln könnten wäre das schonmal ein großer Schritt.

    Edit2: (gefunden im Internetz, keine Eigenkreation)
    ((t<<3)*[8/9,1,9/8,6/5,4/3,3/2,0][[0xd2d2c8,0xce4088,0xca32c8,0x8e4009][t>>14&3]>>(0x3dbe4688>>((t>>10&15)>9?18:t>>10&15)*3&7)*3&7])

    Edit3: (meins... nur Rechteckspannung)
    ((t%3200<800?1:0)*(t%128<32?128:0)+((t+1600)%3200<400?1:0)*(t%128<32?256:0)+(t%1600<200?1:0)*(t%(4+int(t/1600%4))<3?36:0)+((t+800)%3200<200?1:0)*(t%(32+int(t/800%16))<8?80:0))/1.2

    Edit4: (ambiente)
    (sin(t/((int(t/99971%101)))&(int(t/36767%19183)))+sin((t+52453)/((int((t+53507)/97829%233)))&(int((t+52453)/33809%14653)))+sin((t+52453)/((int((t+59779)/96289%127)))&(int((t+64613)/36013%12263))))/3

    M

  • [GDI+] Uhr

    • Mars
    • 4. April 2015 um 14:43

    Genau diese Verkleinerung ist durch Abs(@DesktopWidth/2 - $aPos[0]) < $iW/2) gegeben.
    Wenn du den Codeausschnitt gegen den von mir geposteten austauschst wird die Uhr nur angezeigt wenn die Maus direkt davor ist. Will man den Ausschnitt verändern muss man am /2 herumspielen und z.B. ein /1.5 daraus machen -> Größerer Ausschnitt, /2.5 -> kleinerer Ausschnitt.

    lg
    M

  • [GDI+] Uhr

    • Mars
    • 3. April 2015 um 23:29

    Ist im Prinzip ganz einfach. Die ? und : sind eine zusammengefasste If Abfrage mit Zuweisung. $a = (Ausdruck) ? True : False.
    Was meinst du mit Mausbereich einschränken ? In y Richtung ? (sodass nur in einem bestimmten Bereich des Bildschirms z.B. in der Mitte die Uhr auftaucht ?)

    Edit:
    Der Codeausschnitt ist genau der Richtige. Ist auch sehr einfach zu verstehen. Ganz vorne steht die Bedingung für das Ausfahren der Uhr ($aPos[1] = 0 -> Maus ganz oben). Da kann man selbstverständlich eine Einfache Abstandsabfrage zur Bildschirmmitte (in y Richtung) einbauen ohne an der Uhr selbst irgendwas verändern zu müssen.

    [autoit]

    $iOffset = ($aPos[1] = 0 And Abs(@DesktopWidth/2 - $aPos[0]) < $iW/2) ? $iOffset / 1.5 : ($iOffset + 1) * 1.5 > $iH ? $iH : ($iOffset + 1) * 1.5

    [/autoit]

    lg
    M

  • [GDI+] Uhr

    • Mars
    • 2. April 2015 um 01:29

    Moin,
    Habe eine kleine Uhr gebastelt. Sie wird auf dem Hauptbildschirm angezeigt, sobald der Mauszeiger eine y Koordinate von 0 hat (als ganz oben). Konnte leider nicht testen ob sie korrekt von 23:59:59 auf 00:00:00 umschaltet (hab immer den Zeitpunkt verpennt). Die CPU Last ist im Leerlauf extrem gering (weil nicht gezeichnet wird) und beim Anzeigen auch human (bei mir ca. 2%). 100% GDI+, keine GDI/ASM Zauberei :)

    Kritik und Verbesserungsvorschläge sind gerne gesehen :)

    Edit (02.04.2015):
    - Es wird WS_ES_TOOLWINDOW benutzt (wollte ich ursürünglich tun, habe es aber vergessen. Danke für die Erinnerung)
    - Farbeinstellungen erweitert und insgesamt besser kommentiert.
    - Kleine Zusammenfassungen sodass der Code kürzer ist.

    Spoiler anzeigen
    AutoIt: Uhr.au3
    ; Kleine Uhr von Mars@AutoIt.de
    
    
    #include <GDIPlus.au3>
    
    
    ; ####################### Einstellungen #######################
    
    
    ; Größe der Uhr. Die Uhr skaliert automatisch mit der gewählten Schriftgröße
    Global Const $iFontSize = 100
    
    
    ; Mögliche Ziffernfarben (bei nur einer Farbe wird die Uhr immer diese Farbe behalten)
    Global Const $aFontColor[] = [0xFF20CC20, 0xFFCC2020, 0xFF2020CC, 0xFFFF8000, 0xFF00FF80, 0xFF8000FF, 0xFFFF0080, 0xFF0080FF, 0xFF80FF00]
    
    
    ; Soll die Uhr bei jedem Aufruf eine neue Farbe erhalten ? (Die neue Farbe wird zufällig gewählt und kann der alten Farbe entsprechen)
    Global Const $bNewColors = True
    
    
    ; Fenstertransparenz (255 = völlständig sichtbar, 0 = vollständig transparent)
    Global Const $iTrans = 225
    
    
    ; #############################################################
    
    
    ; Starten
    Opt('GUIOnEventMode', 1)
    _GDIPlus_Startup()
    
    
    ; Globale Konstanten & Variablen
    Global Const $iW = Round($iFontSize * 5.9, 0)
    Global Const $iH = Round($iFontSize * 1.5, 0)
    Global Const $iXOffset = @DesktopWidth / 2 - $iW / 2
    Global Const $iDCircle = $iFontSize / 10
    Global $iOffset = $iH
    Global $hGUI = GUICreate('Uhr', $iW, $iH, $iXOffset, -$iH, 0x80000000, 0x80) ; WS_POPUP und WP_EX_TOOLWINDOW
    Global $hGFX = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    Global $hBMP = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGFX)
    Global $hBUF = _GDIPlus_ImageGetGraphicsContext($hBMP)
    Global $hFAM = _GDIPlus_FontFamilyCreate('Arial')
    Global $hFON = _GDIPlus_FontCreate($hFAM, $iFontSize)
    Global $hBRU = _GDIPlus_BrushCreateSolid($aFontColor[Random(0, UBound($aFontColor) - 1, 1)])
    Global $hFOR = _GDIPlus_StringFormatCreate()
    Global $hBRU_B = _GDIPlus_BrushCreateSolid(0xFF000000)
    Global $hBRU_T = _GDIPlus_BrushCreateSolid(0xFF000000)
    Global $hBRU_W = _GDIPlus_BrushCreateSolid(0x25FFFFFF)
    _GDIPlus_StringFormatSetAlign($hFOR, 1)
    _GDIPlus_GraphicsSetTextRenderingHint($hBUF, 4)
    
    
    ; Unmengen Unfug für das GUI
    GUISetBkColor(0, $hGUI)
    WinSetOnTop($hGUI, '', 1)
    WinSetTrans($hGUI, '', $iTrans)
    GUISetOnEvent(-3, '_Exit', $hGUI)
    OnAutoItExitRegister('Release')
    GUIRegisterMsg(0xF, 'WM_PAINT')
    GUISetState(@SW_SHOW, $hGUI)
    
    
    While Sleep(10) ; Uberragend komplexer Main-Loop
    	Pos()
    WEnd
    
    
    Func Pos() ; Checkt die Position der Maus und zeigt ggf die Uhr an
    	Local $aPos = MouseGetPos()
    	Local Static $bMove, $iOffsetOld
    	$iOffsetOld = $iOffset
    	$iOffset = $aPos[1] = 0 ? $iOffset / 1.5 : ($iOffset + 1) * 1.5 > $iH ? $iH : ($iOffset + 1) * 1.5
    	If $iOffset < 1 Then $iOffset = 0
    	If $iOffsetOld <> $iOffset Then WinMove($hGUI, '', $iXOffset, -$iOffset)
    	If $iOffsetOld <> $iOffset Or $iOffset = 0 Then Uhr($iOffset = $iH / 1.5) ; Neuzeichnen beim ersten Frame den die Uhr innerhalb des Bildschirms ist.
    EndFunc
    
    
    Func Uhr($bNeuZeichnen = False)
    	Local Static $hDraw = False, $mDraw = False, $bFirstRun = True
    	Local $h = @HOUR, $m = @MIN, $s = @SEC, $ms = @MSEC, $iTime
    	If $bNewColors And $bNeuZeichnen Then ; Neue Farbe
    		$bFirstRun = True
    		DllCall($__g_hGDIPDll, 'int', 'GdipDeleteBrush', 'handle', $hBRU)
    		$hBRU = DllCall($__g_hGDIPDll, 'int', 'GdipCreateSolidFill', 'int', $aFontColor[Random(0, UBound($aFontColor) - 1, 1)], 'handle*', 0)[2]
    	EndIf
    	If $bFirstRun Then ; Zu Beginn die 4 Kreise zeichnen (mit smoothing).
    		DllCall($__g_hGDIPDll, 'int', 'GdipGraphicsClear', 'handle', $hBUF, 'dword', 0xFF000000)
    		DllCall($__g_hGDIPDll, 'int', 'GdipSetSmoothingMode', 'handle', $hBUF, 'int', $GDIP_SMOOTHINGMODE_ANTIALIAS8X8)
    		DllCall($__g_hGDIPDll, 'int', 'GdipFillEllipse', 'handle', $hBUF, 'handle', $hBRU, 'float', $iW / 3 - $iDCircle / 2, 'float', $iH / 3 - $iDCircle / 2, 'float', $iDCircle, 'float', $iDCircle)
    		DllCall($__g_hGDIPDll, 'int', 'GdipFillEllipse', 'handle', $hBUF, 'handle', $hBRU, 'float', $iW / 3 - $iDCircle / 2, 'float', $iH / 3 * 2 - $iDCircle / 2, 'float', $iDCircle, 'float', $iDCircle)
    		DllCall($__g_hGDIPDll, 'int', 'GdipFillEllipse', 'handle', $hBUF, 'handle', $hBRU, 'float', $iW / 3 * 2 - $iDCircle / 2, 'float', $iH / 3 - $iDCircle / 2, 'float', $iDCircle, 'float', $iDCircle)
    		DllCall($__g_hGDIPDll, 'int', 'GdipFillEllipse', 'handle', $hBUF, 'handle', $hBRU, 'float', $iW / 3 * 2 - $iDCircle / 2, 'float', $iH / 3 * 2 - $iDCircle / 2, 'float', $iDCircle, 'float', $iDCircle)
    		DllCall($__g_hGDIPDll, 'int', 'GdipSetSmoothingMode', 'handle', $hBUF, 'int', $GDIP_SMOOTHINGMODE_DEFAULT)
    		$hDraw = True
    		$mDraw = True
    		$bFirstRun = False
    	EndIf
    	$hDraw = Feld($hDraw, $bNeuZeichnen, ($m = 59 And $s = 59) ? $h + $ms / 1000 : Int($h), 0.95, 0.05) ; Zeichnet das Stundenfeld
    	$mDraw = Feld($mDraw, $bNeuZeichnen, $s = 59 ? $m + $ms / 1000 : Int($m), 2.95, 2.075, 1.75) ; Zeichnet das Minutenfeld
    	Feld(0, 1, $s + $ms / 1000, 4.97, 4.05) ; Zeichnet das Sekundenfeld
    	DllCall($__g_hGDIPDll, 'int', 'GdipDrawImageI', 'handle', $hGFX, 'handle', $hBMP, 'int', 0, 'int', 0)
    EndFunc
    
    
    Func Feld($xDraw, $bNeuZeichnen, $iTime, $iMulti1, $iMulti2, $iMulti3 = 1.8) ; Zeichnet ein Feld mit einer Ziffer darin
    	If Not IsInt($iTime) Then $xDraw = True
    	If $xDraw Or $bNeuZeichnen Then
    		DllCall($__g_hGDIPDll, 'int', 'GdipFillRectangleI', 'handle', $hBUF, 'handle', $hBRU_B, 'int', $iFontSize * $iMulti2, 'int', 0, 'int', $iFontSize * $iMulti3, 'int', $iH) ; Nur die betreffende Stelle clearen
    		Ziffer($iTime, $iFontSize * $iMulti1, 0)
    		Ziffer($iTime + 1, $iFontSize * $iMulti1, -$iFontSize * 1.5)
    		DllCall($__g_hGDIPDll, 'int', 'GdipFillRectangleI', 'handle', $hBUF, 'handle', $hBRU_T, 'int', $iFontSize * $iMulti2, 'int', 0, 'int', $iFontSize * $iMulti3, 'int', $iH * 0.05) ; Oben und unten Schwarzer Balken.
    		DllCall($__g_hGDIPDll, 'int', 'GdipFillRectangleI', 'handle', $hBUF, 'handle', $hBRU_T, 'int', $iFontSize * $iMulti2, 'int', $iH * 0.95, 'int', $iFontSize * $iMulti3, 'int', $iH * 0.05 + 1)
    		DllCall($__g_hGDIPDll, 'int', 'GdipFillRectangleI', 'handle', $hBUF, 'handle', $hBRU_W, 'int', $iFontSize * $iMulti2, 'int', 0, 'int', $iFontSize * $iMulti3, 'int', $iH * 0.5) ; Oben Hell
    		Return IsInt($iTime) ? False : True
    	EndIf
    EndFunc
    
    
    Func Ziffer($n, $x, $y, $l = 1) ; Zeichnet eine Zimmer im Puffer an x, y. ($l = 1 -> Ziffer geht bis 60, sonst bis 24)
    	$n = $l ? $n < 60 ? $n : $n - 60 : $n < 24 ? $n : $n - 24
    	DllCall($__g_hGDIPDll, 'int', 'GdipDrawString', 'handle', $hBUF, 'wstr', StringFormat('%02i', Int($n)), 'int', -1, 'handle', $hFON, 'struct*', _GDIPlus_RectFCreate($x, $y + $iFontSize * 1.5 * ($n - Int($n)) ^ 5 - 0.5), 'handle', $hFOR, 'handle', $hBRU)
    EndFunc
    
    
    Func WM_PAINT()
    	DllCall($__g_hGDIPDll, 'int', 'GdipDrawImageI', 'handle', $hGFX, 'handle', $hBMP, 'int', 0, 'int', 0)
    EndFunc
    
    
    Func Release()
    	_GDIPlus_BrushDispose($hBRU_W)
    	_GDIPlus_BrushDispose($hBRU_T)
    	_GDIPlus_BrushDispose($hBRU_B)
    	_GDIPlus_StringFormatDispose($hFOR)
    	_GDIPlus_BrushDispose($hBRU)
    	_GDIPlus_FontDispose($hFON)
    	_GDIPlus_FontFamilyDispose($hFAM)
    	_GDIPlus_GraphicsDispose($hBUF)
    	_GDIPlus_BitmapDispose($hBMP)
    	_GDIPlus_GraphicsDispose($hGFX)
    	_GDIPlus_Shutdown()
    EndFunc
    
    
    Func _Exit()
    	Exit
    EndFunc
    Alles anzeigen


    lg
    M

  • Osterformel, gesucht wird Urheber

    • Mars
    • 1. April 2015 um 03:57

    Ich will jetzt kein Spielverderber sein, aber vermutlich kennt der Fragesteller einige Osterformeln, die Urheber und die dazugehörigen Wikipediaseiten. Wie im Startpost zu lesen ist kennt er auch die Gaußsche Formel, daher ist es nicht naheliegend, das dein Post weiterhilft ;)

    Leider kenne ich den Urheber der Formel von oben auch nicht...

    M

  • [close] AI Fight #1 - Snake

    • Mars
    • 19. März 2015 um 18:13

    Ich glaub da müssen noch einige Tausend Runden gefochten werden.
    Meine KI hab ich fast genauso geschrieben wie sie jetzt ist: vollkommen verwirrend, unleserlich und im Kern sehr einfach. Ich kann mir irgendwie gerade nicht vorstellen dass sie die anderen beiden so fies abziehen konnte^^

    Edit: Ooops. Dachte die Source wäre irgendwo veröffentlicht worden^^
    Da dem nicht so ist verrät dieser Post das meine KI eine grauenhafte Formatierung besitzt :D

    Edit2: Hab mir die Logs mal angesehen. Die beiden anderen laufen andauernd gegen Wände. Kein Wunder das die verlieren...
    Das lässt sich doch leicht ausbügeln -> mehr Elan beim Arbeiten bitte :P

  • der Schluss

    • Mars
    • 18. März 2015 um 18:35

    Meine Glaskugel verrät mir, dass du Speicher reservierst den zu nicht wieder freigibst, oder GDI(+) Handles verschwinden lässt.
    Schau mal ob der RAM-Verbrauch des Skripts langsam aber sicher ansteigt. Wenn das der Fall ist musst du prüfen ob der Screenshot wieder gelöscht wird, die Vergleichsfunktion ordentlich arbeitet, Alle GDI(+) Handles wieder geschlossen werden, Filehandles wieder geschlossen werden (falls vorhanden).

  • Kollisionsabfrage - Geeignete Methode

    • Mars
    • 17. März 2015 um 14:59

    Eine ganz einfache Methode (wenn auch weniger Effizient, da Rechenaufwändiger als die Baum-Methode) für 2D wäre eine einfache Bitmap.
    1. Man weist jedem Objekt eine ausreichend große Primzahl zu (sodass später eine Primfaktorzerlegung nur kombinationen aus 2 Primzahlen zulässt)*
    2. Man Füllt die komplette Bitmap mit dem Wert 1 (Multiplikationsneutral)
    3. Man "zeichnet" die Objekte mit der Primzahl als Farbe auf die Bitmap. Dabei Multipliziert man für die einzelnen Pixel die Farbe mit dem Hintergrund.
    4. Man führt bei Werten die Größer sind als die kleinste Primzahl^2 eine Primfaktorzerlegung durch. Die beiden sich ergebenden Primzahlen sind die Nummern der kollidierten Objekte.

    Klingt auf den Ersten Blick extrem umständlich. Die Zeichenmethode lässt sich via ASM ziemlich flott gestalten (am besten alle Objekte in einem Rutsch), die Primzahlen sowie die möglichen Zerlegungen kann man beim Skriptstart puffern und somit ohne Rechenaufwand abrufen. Wenn man alles richtig macht hat man eine Lineare Laufzeit (in Bezug auf die Anzahl Objekte), eine pixelgenaue Kollision und einen Rechenaufwand beim Start von O(n^2).
    Sollte man aber lieber nur zum Üben machen, die komplett mathematische Methode ist wesentlich besser ;)

    *Der Punkt hier ist ggf falsch. Habe das selbst immer so gehandhabt, kann aber auch gut sein dass man bei 2 anfangen darf bei den Primzahlen. Kollisionen mit mehr als 2 Objekten müssten auch gehen.

Spenden

Jeder Euro hilft uns, Euch zu helfen.

Download

AutoIt Tutorial
AutoIt Buch
Onlinehilfe
AutoIt Entwickler
  1. Datenschutzerklärung
  2. Impressum
  3. Shoutbox-Archiv
Community-Software: WoltLab Suite™