Hallo zusammen,
Wie kann ich den Aktuellen Pegel des Mikrofons ablesen?
Danke für eure Hilfe?
Hallo zusammen,
Wie kann ich den Aktuellen Pegel des Mikrofons ablesen?
Danke für eure Hilfe?
Wie kann ich den Aktuellen Pegel des Mikrofons ablesen?
Dazu kannst du den Bass-Wrapper für AutoIt nehmen, der bietet viele Audiofunktionen.
Danke für eure Hilfe?
Bitte?
Da sollte natürlich ein "!" hin @alpines Die BASS-UD Habe ich auch schon herunter geladen, aber ich finde unter den unzähligen Funktionen keine, mit der ich den Mic-Pegel auslesen kann hast du eventuell einen Fuktionsnamen, nach dem ich suchen kann?
Ich kenne mich damit nicht gut aus, am besten du googlest einfach nach ein paar Stichpunkten und suchst das so raus.
Vielleicht hilft dir das, hab gerade kein Mikro kann es also nicht testen: https://www.autoitscript.com/forum/topic/34…o-spectrascope/
Oder so:
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
;#AutoIt3Wrapper_UseX64=y
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $hGui = GUICreate("MicPeak", 320, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUICtrlCreateLabel("Left:", 10, 10, 50, 20, BitOR(0x0200, 0x0002))
Global $cPG_Left = GUICtrlCreateProgress(70, 10, 200, 20)
GUICtrlCreateLabel("Right:", 10, 40, 50, 20, BitOR(0x0200, 0x0002))
Global $cPG_Right = GUICtrlCreateProgress(70, 40, 200, 20)
GUISetState()
Global $tMicLevel = _MicLevel_StartUp()
Global $aPeak
While Sleep(10)
$aPeak = _MicLevel_GetPeak($tMicLevel)
GUICtrlSetData($cPG_Left, $aPeak[0] * 100 + 1) ;Workaround ab Vindows Vista, damit Progress sofort den eingestellten Wert anzeigt
GUICtrlSetData($cPG_Right, $aPeak[1] * 100 + 1)
GUICtrlSetData($cPG_Left, $aPeak[0] * 100)
GUICtrlSetData($cPG_Right, $aPeak[1] * 100)
WEnd
Func _Exit()
_MicLevel_ShutDown($tMicLevel)
Exit
EndFunc ;==>_Exit
Func _MicLevel_GetPeak($tMicLevel, $fFallOff = 0.84)
Local $aPeak[2]
If Not IsDllStruct($tMicLevel) Then Return SetError(1, 0, $aPeak)
$aPeak[0] = DllStructGetData($tMicLevel, "PeakL")
$aPeak[1] = DllStructGetData($tMicLevel, "PeakR")
DllStructSetData($tMicLevel, "PeakL", $aPeak[0] * $fFallOff)
DllStructSetData($tMicLevel, "PeakR", $aPeak[1] * $fFallOff)
$aPeak[0] /= 32768
$aPeak[1] /= 32768
If $aPeak[0] < 0.000030518 Then $aPeak[0] = 0.000030518
If $aPeak[1] < 0.000030518 Then $aPeak[1] = 0.000030518
$aPeak[0] = (20 * Log($aPeak[0]) / Log(10)) / 90.3089986991943 + 1
$aPeak[1] = (20 * Log($aPeak[1]) / Log(10)) / 90.3089986991943 + 1
Return $aPeak
EndFunc ;==>_MicLevel_GetPeak
Func _MicLevel_StartUp($iUpdatePeriod = 40, $iSamplesPerSec = 44100)
If $iUpdatePeriod < 10 Then
$iUpdatePeriod = 10
ElseIf $iUpdatePeriod > 2000 Then
$iUpdatePeriod = 2000
EndIf
Local $iSamples = Ceiling($iUpdatePeriod * $iSamplesPerSec / 1000)
If Mod($iSamples, 4) Then $iSamples += 4 - Mod($iSamples, 4)
Local $tMicLevel = DllStructCreate("float PeakL; float PeakR; ptr AddBuffer; uint HDRSize; ptr ASM; handle Device; byte WaveHDR1[48]; byte WaveHDR2[48]; short Buffer1[" & $iSamples * 2 & "]; short Buffer2[" & $iSamples * 2 & "];")
Local $iBlockAlign = Floor(2 * (16 / 8))
Local $iAvgBytesPerSec = $iSamplesPerSec * $iBlockAlign
Local $tWaveFormatEx = DllStructCreate("struct; align 2; word FormatTag; word Channels; uint SamplesPerSec; uint AvgBytesPerSec; word BlockAlign; word BitsPerSample; word Size; endstruct;")
$tWaveFormatEx.FormatTag = 1
$tWaveFormatEx.Channels = 2
$tWaveFormatEx.SamplesPerSec = $iSamplesPerSec
$tWaveFormatEx.AvgBytesPerSec = $iAvgBytesPerSec
$tWaveFormatEx.BlockAlign = $iBlockAlign
$tWaveFormatEx.BitsPerSample = 16
Local $hWINMM = _WinAPI_GetModuleHandle("Winmm.dll")
$tMicLevel.AddBuffer = _WinAPI_GetProcAddress($hWINMM, "waveInAddBuffer")
Local $bASM
Switch @AutoItX64
Case True
$bASM = "0x53565781FAC003000075634C89C34C89CAB800000080660F6ED8660F70DB00F30F7E0B448B520C488B3A660F6E070F28D3660F60C0660F72E0100F5BC00F55D00F5FC84883C7044183EA047FDD660FD60BC7420C00000000C74218020000004C8B43104883EC20FF53084883C4205F5E5BC3"
Case Else
$bASM = "0x5356578B7424108B4424148B5C24188B54241C3DC00300007553B800000080660F6ED8660F70DB00F30F7E0B8B4A088B3A660F6E070F28D3660F60C0660F72E0100F5BC00F55D00F5FC883C70483E9047FDF660FD60BC7420800000000C74210020000008B430C505256FF53085F5E5BC21400"
EndSwitch
Local $iSize = BinaryLen($bASM)
Local $aResult = DllCall("kernel32.dll", "ptr", "VirtualAlloc", "ptr", 0, "ulong_ptr", $iSize + 16, "dword", 0x00001000, "dword", 0x00000040)
If @error Or Not $aResult[0] Then Return SetError(1, 1, False)
$tMicLevel.ASM = $aResult[0]
Local $pASM = Number($aResult[0])
If Mod($pASM, 16) Then $pASM = $pASM + 16 - Mod($pASM, 16)
Local $tASM = DllStructCreate("byte[" & $iSize & "];", $pASM)
DllStructSetData($tASM, 1, $bASM)
DllCall("kernel32.dll", "bool", "VirtualProtect", "struct*", $pASM, "ulong_ptr", $iSize, "dword", 16, "dword*", 0)
$aResult = DllCall("Winmm.dll", "uint", "waveInOpen", "ptr*", 0, "uint", -1, "struct*", $tWaveFormatEx, "struct*", $tASM, "struct*", $tMicLevel, "uint", 0x30000)
If $aResult[0] Then Return SetError($aResult[0], 2, False)
$tMicLevel.Device = $aResult[1]
Local $tWaveHDR1 = DllStructCreate("struct; ptr Data; uint BufferLength; uint BytesRecorded; uint_ptr User; uint Flags; uint Loops; ptr Next; uint_ptr reserved; endstruct;", DllStructGetPtr($tMicLevel, "WaveHDR1"))
Local $tWaveHDR2 = DllStructCreate("struct; ptr Data; uint BufferLength; uint BytesRecorded; uint_ptr User; uint Flags; uint Loops; ptr Next; uint_ptr reserved; endstruct;", DllStructGetPtr($tMicLevel, "WaveHDR2"))
$tMicLevel.HDRSize = DllStructGetSize($tWaveHDR1)
$tWaveHDR1.Data = DllStructGetPtr($tMicLevel, "Buffer1")
$tWaveHDR1.BufferLength = $iSamples * 4
$tWaveHDR2.Data = DllStructGetPtr($tMicLevel, "Buffer2")
$tWaveHDR2.BufferLength = $iSamples * 4
$aResult = DllCall("Winmm.dll", "uint", "waveInPrepareHeader", "handle", $tMicLevel.Device, "struct*", $tWaveHDR1, "uint", $tMicLevel.HDRSize)
If $aResult[0] Then Return SetError($aResult[0], 3, False)
$aResult = DllCall("Winmm.dll", "uint", "waveInAddBuffer", "handle", $tMicLevel.Device, "struct*", $tWaveHDR1, "uint", $tMicLevel.HDRSize)
If $aResult[0] Then Return SetError($aResult[0], 4, False)
$aResult = DllCall("Winmm.dll", "uint", "waveInPrepareHeader", "handle", $tMicLevel.Device, "struct*", $tWaveHDR2, "uint", $tMicLevel.HDRSize)
If $aResult[0] Then Return SetError($aResult[0], 5, False)
$aResult = DllCall("Winmm.dll", "uint", "waveInAddBuffer", "handle", $tMicLevel.Device, "struct*", $tWaveHDR2, "uint", $tMicLevel.HDRSize)
If $aResult[0] Then Return SetError($aResult[0], 6, False)
$aResult = DllCall("Winmm.dll", "uint", "waveInStart", "handle", $tMicLevel.Device)
If $aResult[0] Then Return SetError($aResult[0], 7, False)
Return $tMicLevel
EndFunc ;==>_MicLevel_StartUp
Func _MicLevel_ShutDown(ByRef $tMicLevel)
If Not IsDllStruct($tMicLevel) Then Return SetError(1, 0, False)
Local $iError = 0
$iError += DllCall("Winmm.dll", "uint", "waveInStop", "handle", $tMicLevel.Device)[0]
Local $tWaveHDR1 = DllStructCreate("struct; ptr Data; uint BufferLength; uint BytesRecorded; uint_ptr User; uint Flags; uint Loops; ptr Next; uint_ptr reserved; endstruct;", DllStructGetPtr($tMicLevel, "WaveHDR1"))
Local $tWaveHDR2 = DllStructCreate("struct; ptr Data; uint BufferLength; uint BytesRecorded; uint_ptr User; uint Flags; uint Loops; ptr Next; uint_ptr reserved; endstruct;", DllStructGetPtr($tMicLevel, "WaveHDR2"))
$tWaveHDR1.Flags = 0
$tWaveHDR2.Flags = 0
$iError += DllCall("Winmm.dll", "uint", "waveInUnprepareHeader", "handle", $tMicLevel.Device, "struct*", $tWaveHDR1, "uint", $tMicLevel.HDRSize)[0]
$iError += DllCall("Winmm.dll", "uint", "waveInUnprepareHeader", "handle", $tMicLevel.Device, "struct*", $tWaveHDR2, "uint", $tMicLevel.HDRSize)[0]
$iError += DllCall("Winmm.dll", "uint", "waveInReset", "handle", $tMicLevel.Device)[0]
$iError += DllCall("Winmm.dll", "uint", "waveInClose", "handle", $tMicLevel.Device)[0]
DllCall("kernel32.dll", "bool", "VirtualFree", "ptr", $tMicLevel.ASM, "ulong_ptr", 0, "dword", 0x00008000)
$tMicLevel = 0
Return SetError($iError, 0, $iError = 0)
EndFunc ;==>_MicLevel_ShutDown
Alles anzeigen
Funktioniert wunderbar Danke @eukalyptus , @chip und @alpines