; Authors: Eukalyptus, BrettF, Prog@ndy and Authenticity for their work on sections of this code and UDF's. ; Modified: November 8, 2019 by ripdad in order to view LIVE input streams. ; AutoIt Version Tested: 3.3.14.2 (I did not test with any other version) #AutoIt3Wrapper_UseX64=n #include 'Bass.au3' #include 'BassExt.au3' #include 'GDIPlus.au3' ;========================================================================= Opt('MustDeclareVars', 1) Local $id_GUI = GUICreate(' LIVE Multiband FFT Visual Spectrum', 1018, 290, 0, 0, Default, 8) If @OSBuild < 7600 Then WinSetTrans($id_GUI, '', 0xFF); workaround for XP machines GUISetFont(8, Default, Default, 'MS Sans Serif') GUISetBkColor(0x505050) Local $id_LBL = GUICtrlCreateLabel('', 0, 236, 1024, 16) Local $id_LGO = GUICtrlCreateLabel(' Multiband Fast Fourier Transform (FFT) ', 550, 260, 340, 20) GUICtrlSetColor($id_LBL, 0xEEEEEE) GUICtrlSetColor($id_LGO, 0xEEEEEE) GUICtrlSetColor($id_LGO, 0xAAAAAA) GUICtrlSetFont($id_LGO, 12, Default, Default, 'Verdana') Local $id_INP = GUICtrlCreateInput(60, 120, 258, 42, 20) Local $id_UPD = GUICtrlCreateUpdown($id_INP) GUICtrlSetLimit($id_UPD, 250, 10) Local $id_DLY = GUICtrlCreateLabel(' Delay (ms)', 164, 262, 60, 16) GUICtrlSetColor($id_DLY, 0xEEEEEE) Local $id_INF = GUICtrlCreateInput(75, 240, 258, 42, 20) Local $id_FAL = GUICtrlCreateUpdown($id_INF) GUICtrlSetLimit($id_FAL, 100, 50) Local $id_FLL = GUICtrlCreateLabel(' Log (db)', 285, 262, 47, 16) GUICtrlSetColor($id_FLL, 0xEEEEEE) Local $id_BND = GUICtrlCreateCombo('', 350, 258, 45, 100) GUICtrlSetData($id_BND, '16|32|64|128|256|512', '128') Local $id_LBD = GUICtrlCreateLabel(' Bands', 398, 262, 40, 16) GUICtrlSetColor($id_LBD, 0xEEEEEE) ;========================================================================= _GDIPlus_Startup() ;FFT Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($id_GUI) Local $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics(1024, 235, $hGraphics) Local $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer) Local $hBrushFFT = _BrushCreateFFT(0, 0, 1024, 235, 1024, 235, $hGraphics) Local $aFFT = _BASS_EXT_CreateFFT(128, 0, 0, 1024, 235, 1, 75, True) Local $hBmpBk = _BMPCreateBackGround(1024, 235, $hGraphics) ;Level Local $hImage, $hBrush = _GDIPlus_BrushCreateSolid() Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($id_GUI) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(100, 23, $hGraphic) Local $ContextA = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;========================================================================= _BASS_Startup(@ScriptDir & '\Bass.dll') If @error Then Exit MsgBox(16, 'BASS Function Error', 'EC1') _BASS_EXT_Startup(@ScriptDir & '\BassExt.dll') If @error Then Exit MsgBox(16, 'BASS_EXT Function Error', 'EC2') _BASS_RecordInit(-1) If @error Then Exit MsgBox(16, 'BASS Function Error', 'EC3') _BASS_SetConfig($BASS_CONFIG_UPDATEPERIOD, 100) _BASS_SetConfig($BASS_CONFIG_REC_BUFFER, 1024) Local $hStream = _BASS_RecordStart(44100, 2, 0) If @error Then Exit MsgBox(16, 'BASS Function Error', 'EC4') ;========================================================================= Local $nBands = 128, $nLog = 75, $nMsec = 60, $nSwitch = 0 _SetBands() ;========================================================================= GUISetState(@SW_SHOW, $id_GUI) ControlFocus(' LIVE Multiband FFT', '', $id_UPD) GUIRegisterMsg(0x000F, 'WM_PAINT') GUICtrlSetOnEvent($id_UPD, '_SetDelay') GUICtrlSetOnEvent($id_BND, '_SetBands') GUICtrlSetOnEvent($id_FAL, '_SetLog') GUISetOnEvent(-3, '_EXIT') Opt('GUIOnEventMode', 1) Local $iTimer = TimerInit() ;========================================================================= While 1 If TimerDiff($iTimer) > $nMsec Then $iTimer = TimerInit() Sleep(20) _DrawFFT() Sleep(20) EndIf _DrawInputLevels() Sleep(20) WEnd Func _SetDelay() $nMsec = Number(GUICtrlRead($id_INP)) ControlFocus(' LIVE Multiband FFT', '', $id_UPD) EndFunc Func _SetLog() $nLog = Number(GUICtrlRead($id_INF)) $aFFT = _BASS_EXT_CreateFFT($nBands, 0, 0, 1024, 235, 1, $nLog, True) ControlFocus(' LIVE Multiband FFT', '', $id_UPD) EndFunc Func _SetBands() Local $nBands = Number(GUICtrlRead($id_BND)) Switch $nBands Case 16 GUICtrlSetData($id_LBL, ' 5hz 10hz 15hz 25hz 40hz 70hz 120hz 200hz 350hz 600hz 1khz 2khz 3 - 4khz 5 - 7khz 8 - 12khz 13 - 17khz') Case 32 GUICtrlSetData($id_LBL, ' 5hz 10hz 15hz 20hz 25hz 35hz 40hz 45hz 50hz 60hz 70hz 95hz 120hz 150hz 200hz 270hz 350hz 460hz 600hz 750hz 1khz 1.3khz 1.7khz 2khz 3khz 4khz 5khz 7khz 9khz 12khz 15khz 18khz') Case 64 GUICtrlSetData($id_LBL, ' 10hz 25hz 40hz 55hz 70hz 90hz 115hz 140hz 250hz 430hz 700hz 1khz 1.5khz 2khz 3khz 4khz 6khz 8khz 12khz 17khz') Case 128 GUICtrlSetData($id_LBL, ' 30hz 50hz 100hz 150hz 200hz 250hz 300hz 350hz 600hz 1khz 1.5khz 2khz 3khz 4khz 6khz 8khz 12khz 17khz') Case 256 GUICtrlSetData($id_LBL, ' 50hz 115hz 200hz 300hz 400hz 500hz 600hz 700hz 800hz 1khz 2khz 3khz 4khz 6khz 8khz 12khz 17khz') Case 512 GUICtrlSetData($id_LBL, ' 100hz 250hz 400hz 600hz 800hz 1khz 1.2khz 1.4khz 1.6khz 1.8khz 2khz 3khz 4khz 6khz 8khz 12khz 17khz') Case Else $nBands = 128 GUICtrlSetData($id_LBL, ' 30hz 50hz 100hz 150hz 200hz 250hz 300hz 350hz 600hz 1khz 1.5khz 2khz 3khz 4khz 6khz 8khz 12khz 17khz') EndSwitch $aFFT = _BASS_EXT_CreateFFT($nBands, 0, 0, 1024, 235, 1, $nLog, True) ControlFocus(' LIVE Multiband FFT', '', $id_UPD) EndFunc ;============================================================================= ; Function: _DrawInputLevels() ; Description: Try to get a decent overall frequency response for the display. ; Reaction: The level bars will flash RED if LIVE input levels are too high. ;============================================================================= Func _DrawInputLevels() Local $iLong = _BASS_ChannelGetLevel($hStream) Local $nLevelL = Round(_LoWord($iLong) / 32768 * 100) Local $nLevelR = Round(_HiWord($iLong) / 32768 * 100) Local $Color = 0xFF008DD4 ; If $nLevelL > 99 Or $nLevelR > 99 Then If $nSwitch < 1 Then $Color = 0xFFFF0000 $nSwitch = 1 EndIf ElseIf $nSwitch > 0 Then $Color = 0xFF008DD4 $nSwitch = 0 EndIf ; _GDIPlus_GraphicsClear($ContextA, 0xFF202020); Clear Contents _GDIPlus_BrushSetSolidColor($hBrush, $Color); Level Color (green or red) _GDIPlus_GraphicsFillRect($ContextA, 1, 1, $nLevelL, 9, $hBrush); Left Channel Level _GDIPlus_GraphicsFillRect($ContextA, 1, 12, $nLevelR, 9, $hBrush); Right Channel Level _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 8, 257, 100, 23); Draw graphics EndFunc Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam) _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0) Return 'GUI_RUNDEFMSG' EndFunc Func _DrawFFT() _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpBk, 0, 0) _BASS_EXT_ChannelGetFFT($hStream, $aFFT, 6) If Not @error Then DllCall($__g_hGDIPDll, "int", "GdipFillPolygonI", "handle", $hGfxBuffer, "handle", $hBrushFFT, "ptr", $aFFT[0], "int", $aFFT[1], "int", "FillModeAlternate") _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0) EndFunc Func _BrushCreateFFT($iX, $iY, $iW, $iH, $iWidth, $iHeight, $hGraphics) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics) Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsClear($hContext, 0xFF000000) Local $hBrush[5] $hBrush[0] = _GDIPlus_BrushCreateSolid(0xFFFF0000) $hBrush[1] = _GDIPlus_LineBrushCreate(0, 0, 0, 20, 0xFFFF0000, 0xFFFFAA00, 1) $hBrush[2] = _GDIPlus_LineBrushCreate(0, 20, 0, 40, 0xFFFFAA00, 0xFF00AAFF, 1) $hBrush[3] = _GDIPlus_BrushCreateSolid(0xFF00AAFF) $hBrush[4] = _GDIPlus_LineBrushCreate(0, 0, 0, 4, 0x00000000, 0xAA000000, 0) _GDIPlus_GraphicsFillRect($hContext, $iX, $iY, $iW, 20, $hBrush[0]) _GDIPlus_GraphicsFillRect($hContext, $iX, $iY + 20, $iW, 20, $hBrush[1]) _GDIPlus_GraphicsFillRect($hContext, $iX, $iY + 40, $iW, 20, $hBrush[2]) _GDIPlus_GraphicsFillRect($hContext, $iX, $iY + 60, $iW, $iH - 60, $hBrush[3]) _GDIPlus_GraphicsFillRect($hContext, $iX, $iY, $iW, $iH, $hBrush[4]) For $i = 0 To 4 _GDIPlus_BrushDispose($hBrush[$i]) Next _GDIPlus_GraphicsDispose($hContext) Local $aRet = DllCall($__g_hGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hBitmap, "int", 0, "int*", 0) _GDIPlus_BitmapDispose($hBitmap) Return $aRet[3] EndFunc Func _BMPCreateBackGround($iW, $iH, $hGraphics) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics) Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsClear($hContext, 0xFF202020); <-- background color _GDIPlus_GraphicsDispose($hContext) Return $hBitmap EndFunc Func _Exit() _BASS_RecordFree(); <-- free record inputs (_BASS_Free is not used because there are no outputs in this script) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrushFFT) _GDIPlus_BitmapDispose($hBmpBk) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_BitmapDispose($hBmpBuffer) _GDIPlus_GraphicsDispose($hGfxBuffer) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() DllClose('BassExt.dll') DllClose('Bass.dll') Exit EndFunc