Jump to content

BASS Function Library (Sound and Music Functions)


BrettF
 Share

Recommended Posts

Hi, I need help to "Record output of VST Pluggin" on this post :

I want to record the output channels after VST effect and save this to file.

It this possible to record output windows channels ?

Can anybody help me, please !!!

Edited by TheDaverMan
Link to comment
Share on other sites

Can someone explain what the constant $BASS_DEVICE_MONO does?

I thought It would play for example all channels of a file through all speakers, but it seems not.

If I use _BASS_Init($BASS_DEVICE_MONO) It is still in stereo (regular two pc speakers), just that on of them is on the blink, and looking for a quick fix.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

looking for a quick fix.

In windows click start and type "mmsys.cpl" and start it (enter), on the recording tab right-click the blank area to bring up the context menu, there chose "show disabled devices", Stereo Mix should now be available on the list, right-click it to enable it, that gives mono sound by mixing the channels.

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

Cheers werty, but does not comply, still stereo :(

I'd already tried a lot of this kind of stuff, seems mono is not worthy.

I've had a good look around, and windows 7 simply does not support mono (headphone virtualization works in some cases for headsets I seen mentioned).

Still tinkering with Bass udf.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Well, that sucks, but if you are comfortable with it, you could simply cut the wires and put them together so one speaker receives both signals, do it hardware instead of software.

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

haha, that's something I would have done at one time, even if it would distort the sound.

I have new speakers now.

Still, would be handy if Bass UDF was capable of achieving what I was after.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • 4 weeks later...

#include <BASS.au3>
#include <BASSEXT.au3>
#AutoIt3Wrapper_UseX64=n

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

Opt("GUIOnEventMode", 1)

$iThrs = 70

GUICreate("", 120, 135)
GUISetOnEvent(-3, "_EXIT")
$cProg_L = GUICtrlCreateProgress(10, 10, 100, 20, 0x01)
$cProg_R = GUICtrlCreateProgress(10, 40, 100, 20, 0x01)
$cSlider = GUICtrlCreateSlider(10, 70, 100, 25)
GUICtrlSetOnEvent(-1, "_SetThreshold")
GUICtrlSetData(-1, $iThrs)
$cLabel = GUICtrlCreateLabel("", 10, 105, 100, 20)
GUICtrlSetBkColor(-1, 0x00FF00)
GUISetState()

_BASS_Startup()
_BASS_EXT_Startup()

_BASS_Init(0, -1, 44100, 0, "")
_BASS_RecordInit(-1)

$hRecord = _BASS_RecordStart(44100, 2, 0, $BASS_EXT_RecordProc)
$aLevelDSP = _BASS_EXT_ChannelSetLevelDsp($hRecord)

While 1
    $iLong = _BASS_EXT_ChannelGetLevel($aLevelDSP, 0.3, 1)
    $fLevel_Left = _BASS_LoWord($iLong) / 32768
    $fLevel_Right = _BASS_HiWord($iLong) / 32768
    $fdB_Left = _BASS_EXT_Level2dB($fLevel_Left)
    $fdB_Right = _BASS_EXT_Level2dB($fLevel_Right)

    GUICtrlSetData($cProg_L, $fdB_Left * 100)
    GUICtrlSetData($cProg_R, $fdB_Right * 100)

    _CheckThreshold((($fdB_Left * 100) + ($fdB_Right * 100)) / 2)

    Sleep(20)
WEnd




Func _Function()
    Local Static $iTimer = 0
    If $iTimer = 0 Or TimerDiff($iTimer) > 1000 Then ; Min 1 Second
        $iTimer = TimerInit()
        ConsoleWrite("! Over" & @CRLF)
    EndIf
EndFunc   ;==>_Function




Func _CheckThreshold($fLevel)
    Local Static $iOver = 0
    If $fLevel > $iThrs Then
        If $iOver = 0 Then
            GUICtrlSetBkColor($cLabel, 0xFF0000)
            $iOver = 1
            _Function()
        EndIf
    Else
        If $iOver <> 0 Then
            GUICtrlSetBkColor($cLabel, 0x00FF00)
            $iOver = 0
        EndIf
    EndIf
EndFunc   ;==>_CheckThreshold




Func _SetThreshold()
    $iThrs = GUICtrlRead($cSlider)
EndFunc   ;==>_SetThreshold



Func _EXIT()
    _BASS_EXT_ChannelRemoveLevelDsp($aLevelDSP)
    _BASS_RecordFree()
    _BASS_Free()
    Exit
EndFunc   ;==>_EXIT

Have a look at the examples in the helpfile: _BASS_EXT_ChannelGetLevel and _BASS_RecordGetInput

E

 

Link to comment
Share on other sites

  • 3 months later...

Hi all,

I've searched through this topic, and I did not found any example on how to record microphone into wav file on my HDD.
It is hard for a newcommer to understand such complex project such as this.

Would anyone be kind enough to provide an example how to record microphone into WAV?

Link to comment
Share on other sites

  • 1 month later...

I've butchered eucalyptus' AudioMeter2 demo down to where it's only the FFT visualization.  I am concerned that I may not be releasing every resource that was opened -- if that's even the proper term for it. I've studied other scripts in this thread in hopes of understanding the relationship between the BASS functions that are started up versus the ones closed at exit but I'm just not getting it.  Can someone with an understanding of this browse the following script and tell me if it's clean?

#AutoIt3Wrapper_UseX64=n
#include "Bass.au3"
#include "BassExt.au3"
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

;~ Opt("GUIOnEventMode", 1)
;~ Opt("MustDeclareVars", 1)

;file dialog for testing only. Actual audio file will be specified in the script.
Global $sFile = FileOpenDialog("Open...", "", "playable formats (*.MP3;*.MP2;*.MP1;*.OGG;*.WAV;*.AIFF;*.AIF)")
If @error Or Not FileExists($sFile) Then Exit

Global $iWidth = 410
Global $iHeight = 170

Global $hGui, $hGraphics, $hGfxBuffer, $hBmpBuffer, $hBmpBk, $hBrushFFT
Global $aFFT, $aPeak
Global $iTimer
Global $hStream

$hGui = GUICreate("BASS_EXT AudioMeter", $iWidth, $iHeight, -1,-1, BitOR($WS_SYSMENU,$WS_POPUP))
GUISetBkColor(0x000000)

_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
$hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)


$hBrushFFT = _BrushCreateFFT(0, 0, 410, 170, $iWidth, $iHeight, $hGraphics)
$aFFT = _BASS_EXT_CreateFFT(82, 0, 0, 410, 170, 1, 70, True)

$hBmpBk = _BMPCreateBackGround($iWidth, $iHeight, $hGraphics)


_BASS_Startup(@ScriptDir & "\bass.dll")
;__Debug(@error, "load bass.dll")

_BASS_EXT_Startup(@ScriptDir & "\bassExt.dll")
;__Debug(@error, "load bassext.dll")

_BASS_Init(0, -1, 44100, 0, "")
;__Debug(@error, "initialize bass")

_BASS_SetConfig($BASS_CONFIG_UPDATEPERIOD, 100)
;__Debug(@error, "set update period")

_BASS_SetConfig($BASS_CONFIG_BUFFER, 250)
;__Debug(@error, "set buffer size")

GUIRegisterMsg(0x000F, "WM_PAINT")
GUISetState()

$hStream = _BASS_StreamCreateFile(False, $sFile, 0, 0, 0)
;__Debug(@error, "create stream from file: " & $sFile)

$aPeak = _BASS_EXT_ChannelSetMaxPeakDsp($hStream)
;__Debug(@error, "set dsp callback to check for the highest peak")

_BASS_ChannelPlay($hStream, True)
;__Debug(@error, "start stream")

$iTimer = TimerInit()
While _BASS_ChannelIsActive($hStream)
    If TimerDiff($iTimer) > 25 Then
        $iTimer = TimerInit()
        _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpBk, 0, 0)
        _DrawFFT()
        _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
        ;ConsoleWrite(TimerDiff($iTimer) & @CRLF)
    EndIf
WEnd

_Exit()



Func _DrawFFT()
    Local $iTimer = TimerInit()
    _BASS_EXT_ChannelGetFFT($hStream, $aFFT, 6)
    If Not @error Then DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "handle", $hGfxBuffer, "handle", $hBrushFFT, "ptr", $aFFT[0], "int", $aFFT[1], "int", "FillModeAlternate")
EndFunc   ;==>_DrawFFT


Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_PAINT

Func _BMPCreateBackGround($iW, $iH, $hGraphics)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    Local $hBrushBK = _GDIPlus_BrushCreateSolid(0xEE000000)
    Local $hBrushTXT = _GDIPlus_BrushCreateSolid(0xFF99AAFF)
    Local $hPen = _GDIPlus_PenCreate(0xFF222222, 1)

    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrushBK)
    _GDIPlus_BrushDispose($hBrushTXT)
    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
EndFunc   ;==>_BMPCreateBackGround

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($ghGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hBitmap, "int", 0, "int*", 0)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $aRet[3]
EndFunc   ;==>_BrushCreateFFT


Func _Exit()
    _BASS_EXT_ChannelRemoveMaxPeakDsp($aPeak)
    ;___Debug(@error, "remove peak dsp")

    _BASS_ChannelStop($hStream)
    ;___Debug(@error, "stop stream")

    _BASS_StreamFree($hStream)
    ;___Debug(@error, "free stream")

    _BASS_Free()
    ;___Debug(@error, "free bass")

    _GDIPlus_BrushDispose($hBrushFFT)
    _GDIPlus_BitmapDispose($hBmpBk)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

;~ Func ___DeBug($iError, $sAction)
;~  Switch $iError
;~      Case -1
;~          ConsoleWrite(@CRLF & "-" & $sAction & @CRLF)
;~      Case -2
;~          ConsoleWrite(@CRLF & ">" & $sAction & @CRLF)
;~      Case 0
;~          ConsoleWrite(@CRLF & "+" & $sAction & " - OK" & @CRLF)
;~      Case Else
;~          ConsoleWrite(@CRLF & "!" & $sAction & " - FAILED, @error: " & $iError & @CRLF)
;~          _Exit()
;~  EndSwitch
;~ EndFunc   ;==>___DeBug

Func _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2, $iWrapMode = 0)
    Local $tPointF1, $pPointF1
    Local $tPointF2, $pPointF2
    Local $aResult

    $tPointF1 = DllStructCreate("float;float")
    $pPointF1 = DllStructGetPtr($tPointF1)
    $tPointF2 = DllStructCreate("float;float")
    $pPointF2 = DllStructGetPtr($tPointF2)

    DllStructSetData($tPointF1, 1, $nX1)
    DllStructSetData($tPointF1, 2, $nY1)
    DllStructSetData($tPointF2, 1, $nX2)
    DllStructSetData($tPointF2, 2, $nY2)

    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iARGBClr1, "uint", $iARGBClr2, "int", $iWrapMode, "int*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    ;$GDIP_STATUS = $aResult[0]
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_LineBrushCreate


;~ Func _Exit()
;~ Exit
;~ EndFunc
Link to comment
Share on other sites

Where did these functions come from? Because I can't find them in the BASSExt.au3 file, and I don't know which one of the dozens of script snippets in this thread you got them from.

_BASS_EXT_ChannelSetMaxPeakDsp
_BASS_EXT_ChannelRemoveMaxPeakDsp

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

 

Where did these functions come from? Because I can't find them in the BASSExt.au3 file, and I don't know which one of the dozens of script snippets in this thread you got them from.

_BASS_EXT_ChannelSetMaxPeakDsp
_BASS_EXT_ChannelRemoveMaxPeakDsp

 

It was in a previous version

Func _BASS_EXT_ChannelRemoveMaxPeakDsp ( $aPeak, $handle=0 )
    If Not IsArray ( $aPeak ) Then Return SetError ( 1, 0, 0 )
    $aPeak[0] = 0
    Local $hHandle = $handle
    If Not $hHandle Then $hHandle = $aPeak[2]
    Local $aRet = _BASS_ChannelRemoveDSP ( $hHandle, $aPeak[1] )
    Switch @error
        Case True
            Return SetError ( 1, 1, 0 )
        Case Else
            Return SetError ( 0, 0, $aRet )
    EndSwitch
EndFunc ;==> _BASS_EXT_ChannelRemoveMaxPeakDsp ()

Func _BASS_EXT_ChannelSetMaxPeakDsp ( $handle, $priority=10 )
    Local $tStruct = DllStructCreate ( 'double;double;double;double' )
    Local $hDsp = _BASS_ChannelSetDSP ( $handle, $BASS_EXT_DspPeakProc, DllStructGetPtr ( $tStruct ), $priority )
    Switch @error
        Case True
            Return SetError ( 1, 0, 0 )
        Case Else
            Local $aReturn[3]
            $aReturn[0] = $tStruct
            $aReturn[1] = $hDsp
            $aReturn[2] = $handle
            Return SetError ( 0, 0, $aReturn )
    EndSwitch
EndFunc ;==> _BASS_EXT_ChannelSetMaxPeakDsp ()

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

 

Where did these functions come from? Because I can't find them in the BASSExt.au3 file, and I don't know which one of the dozens of script snippets in this thread you got them from.

_BASS_EXT_ChannelSetMaxPeakDsp
_BASS_EXT_ChannelRemoveMaxPeakDsp

 

Thank you for replying, BrewManNH!  The script I posted is a highly trimmed down version of the following original script posted by eucalyptus in the German Autoit forum.   I need someone who understands this advanced coding to check my script for errors in terms of resources opened but not closed or other instances of over- or -under trimming.  While my script "works", I'm afraid to use if it might leave memory leaks or other potential corruption. (I know it won't "blow up" the machine, but other programs like Skype, etc. will subsequently be using audio resources.)

;thx to Authenticity for GDIp.au3
#AutoIt3Wrapper_UseX64=n
#include "Bass.au3"
#include "BassExt.au3"
#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

Global $sFile = FileOpenDialog("Open...", "", "playable formats (*.MP3;*.MP2;*.MP1;*.OGG;*.WAV;*.AIFF;*.AIF)")
If @error Or Not FileExists($sFile) Then Exit

Global $iWidth = 550
Global $iHeight = 400

Global $hGui, $hGraphics, $hGfxBuffer, $hBmpBuffer, $hBmpBk, $hBmpMeter, $hBmpLed, $hBmpPhase, $hBmpPhaseMeter, $hBmpWave, $hBrushFFT, $hPenPhase, $hPenWaveL, $hPenWaveR
Global $aFFT, $aPeak, $aPhaseCorr, $aPhase, $aWave
Global $iTimer
Global $hStream

$hGui = GUICreate("BASS_EXT AudioMeter", $iWidth, $iHeight)
GUISetOnEvent(-3, "_EXIT")
GUISetBkColor(0x000000)

_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
$hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)

$hBmpMeter = _BMPCreateMeter(360, $hGraphics)
$hBmpLed = _BMPCreateLED($hGraphics, 14, 0xFF000000, 0xFFFF1111)

$hBmpPhaseMeter = _BMPCreatePhaseMeter(200, $hGraphics)
$hBmpPhase = _BMPCreatePhase(200, 190, $hGraphics)
$hPenPhase = _GDIPlus_PenCreate(0xFFFFAA00, 1)

$hBmpWave = _BMPCreateWave(200, 200, $hGraphics)
$hPenWaveL = _GDIPlus_PenCreate(0xFF00FF00, 1)
$hPenWaveR = _GDIPlus_PenCreate(0xFFFF0000, 1)

$hBrushFFT = _BrushCreateFFT(130, 220, 410, 170, $iWidth, $iHeight, $hGraphics)
$aFFT = _BASS_EXT_CreateFFT(82, 130, 220, 410, 170, 1, 70, True)

$hBmpBk = _BMPCreateBackGround($iWidth, $iHeight, $hGraphics)


_BASS_Startup(@ScriptDir & "\bass.dll")
___Debug(@error, "load bass.dll")

_BASS_EXT_Startup(@ScriptDir & "\bassExt.dll")
___Debug(@error, "load bassext.dll")

_BASS_Init(0, -1, 44100, 0, "")
___Debug(@error, "initialize bass")

_BASS_SetConfig($BASS_CONFIG_UPDATEPERIOD, 100)
___Debug(@error, "set update period")

_BASS_SetConfig($BASS_CONFIG_BUFFER, 250)
___Debug(@error, "set buffer size")

GUIRegisterMsg(0x000F, "WM_PAINT")
GUISetState()

$hStream = _BASS_StreamCreateFile(False, $sFile, 0, 0, 0)
___Debug(@error, "create stream from file: " & $sFile)

$aPeak = _BASS_EXT_ChannelSetMaxPeakDsp($hStream)
___Debug(@error, "set dsp callback to check for the highest peak")

_BASS_ChannelPlay($hStream, True)
___Debug(@error, "start stream")

$iTimer = TimerInit()
While _BASS_ChannelIsActive($hStream)
    If TimerDiff($iTimer) > 25 Then
        $iTimer = TimerInit()
        _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpBk, 0, 0)
        _DrawMeter()
        _DrawPhase()
        _DrawWave()
        _DrawFFT()
        _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
        ;ConsoleWrite(TimerDiff($iTimer) & @CRLF)
    EndIf
WEnd

_Exit()


Func _DrawMeter()
    Local $iLong, $nLevelL, $nLevelR, $iLevel
    Local Static $nPeakL, $nPeakR, $nPeakL_Hold, $nPeakR_Hold, $iPeakL_Cnt, $iPeakR_Cnt
    Local Static $nRmsL, $nRmsR, $nRmsL_Hold, $nRmsR_Hold, $iRmsL_Cnt, $iRmsR_Cnt, $iPeakLedL_Cnt = 60, $iPeakLedR_Cnt = 60
    If _BASS_ChannelIsActive($hStream) = $BASS_ACTIVE_PLAYING Then
        $iLong = _BASS_ChannelGetLevel($hStream)
        $nLevelL = _BASS_EXT_Level2dB(_LoWord($iLong) / 32768, 60)
        $nLevelR = _BASS_EXT_Level2dB(_HiWord($iLong) / 32768, 60)
        If $nLevelL > $nPeakL Then $nPeakL = $nLevelL
        If $nLevelL > $nPeakL_Hold Then
            $nPeakL_Hold = $nLevelL
            $iPeakL_Cnt = 0
        EndIf
        If $nLevelR > $nPeakR Then $nPeakR = $nLevelR
        If $nLevelR > $nPeakR_Hold Then
            $nPeakR_Hold = $nLevelR
            $iPeakR_Cnt = 0
        EndIf

        $iLong = _BASS_EXT_ChannelGetRMSLevel($hStream)
        $nLevelL = _BASS_EXT_Level2dB(_LoWord($iLong) / 32768, 60)
        $nLevelR = _BASS_EXT_Level2dB(_HiWord($iLong) / 32768, 60)
        If $nLevelL > $nRmsL Then $nRmsL = $nLevelL
        If $nLevelL > $nRmsL_Hold Then
            $nRmsL_Hold = $nLevelL
            $iRmsL_Cnt = 0
        EndIf
        If $nLevelR > $nRmsR Then $nRmsR = $nLevelR
        If $nLevelR > $nRmsR_Hold Then
            $nRmsR_Hold = $nLevelR
            $iRmsR_Cnt = 0
        EndIf

    EndIf

    $iLevel = Round(360 - $nPeakL * 360)
    $iLevel -= Mod($iLevel, 4)
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpMeter, 0, $iLevel, 15, 360 - $iLevel, 10, 30 + $iLevel, 15, 360 - $iLevel)
    $iLevel = Round(360 - $nPeakL_Hold * 360)
    $iLevel -= Mod($iLevel, 4)
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpMeter, 0, $iLevel, 15, 4, 10, 30 + $iLevel, 15, 4)

    $iLevel = Round(360 - $nPeakR * 360)
    $iLevel -= Mod($iLevel, 4)
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpMeter, 0, $iLevel, 15, 360 - $iLevel, 80, 30 + $iLevel, 15, 360 - $iLevel)
    $iLevel = Round(360 - $nPeakR_Hold * 360)
    $iLevel -= Mod($iLevel, 4)
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpMeter, 0, $iLevel, 15, 4, 80, 30 + $iLevel, 15, 4)


    $iLevel = Round(360 - $nRmsL * 360)
    $iLevel -= Mod($iLevel, 4)
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpMeter, 0, $iLevel, 20, 360 - $iLevel, 30, 30 + $iLevel, 20, 360 - $iLevel)
    $iLevel = Round(360 - $nRmsL_Hold * 360)
    $iLevel -= Mod($iLevel, 4)
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpMeter, 0, $iLevel, 20, 4, 30, 30 + $iLevel, 20, 4)

    $iLevel = Round(360 - $nRmsR * 360)
    $iLevel -= Mod($iLevel, 4)
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpMeter, 0, $iLevel, 20, 360 - $iLevel, 100, 30 + $iLevel, 20, 360 - $iLevel)
    $iLevel = Round(360 - $nRmsR_Hold * 360)
    $iLevel -= Mod($iLevel, 4)
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpMeter, 0, $iLevel, 20, 4, 100, 30 + $iLevel, 20, 4)


    $nLevelL = _BASS_EXT_ChannelGetMaxPeak($aPeak, 0, True)
    $nLevelR = _BASS_EXT_ChannelGetMaxPeak($aPeak, 1, True)
    If $nLevelL > 0.99 Then $iPeakLedL_Cnt = 0
    If $nLevelR > 0.99 Then $iPeakLedR_Cnt = 0

    If $iPeakLedL_Cnt < 60 Then _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpLed, 10, 10)
    If $iPeakLedR_Cnt < 60 Then _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpLed, 80, 10)

    $iPeakL_Cnt += 1
    If $iPeakL_Cnt > 80 Then $nPeakL_Hold -= 0.005
    $iPeakR_Cnt += 1
    If $iPeakR_Cnt > 80 Then $nPeakR_Hold -= 0.005
    $nPeakL -= 0.01
    $nPeakR -= 0.01

    $iRmsL_Cnt += 1
    If $iRmsL_Cnt > 60 Then $nRmsL_Hold -= 0.005
    $iRmsR_Cnt += 1
    If $iRmsR_Cnt > 60 Then $nRmsR_Hold -= 0.005
    $nRmsL -= 0.01
    $nRmsR -= 0.01

    $iPeakLedL_Cnt += 1
    $iPeakLedR_Cnt += 1
EndFunc   ;==>_DrawMeter


Func _DrawWave()
    $aWave = _BASS_EXT_ChannelGetWaveformEx($hStream, 256, 340, 70, 200, 60, 340, 150, 200, 60)
    If Not @error Then
        DllCall($ghGDIPDll, "int", "GdipDrawCurveI", "handle", $hGfxBuffer, "handle", $hPenWaveL, "ptr", $aWave[0], "int", $aWave[2])
        DllCall($ghGDIPDll, "int", "GdipDrawCurveI", "handle", $hGfxBuffer, "handle", $hPenWaveR, "ptr", $aWave[1], "int", $aWave[2])
    EndIf
EndFunc   ;==>_DrawWave


Func _DrawPhase()
    $aPhaseCorr = _BASS_EXT_ChannelGetPhaseData($hStream, 128)
    Local Static $nPhase
    $nPhase += ($aPhaseCorr[0][1] - $nPhase) / 12
    Local $iPhase = 100 * $nPhase + 100
    $iPhase -= Mod($iPhase, 4)
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpPhaseMeter, $iPhase, 0, 4, 10, $iPhase + 130, 200, 4, 10)

    $aPhase = _BASS_EXT_ChannelGetPhaseDataEx($hStream, 512, 230, 107, 100, 100)
    If Not @error Then DllCall($ghGDIPDll, "int", "GdipDrawCurveI", "handle", $hGfxBuffer, "handle", $hPenPhase, "ptr", $aPhase[0], "int", $aPhase[1])
EndFunc   ;==>_DrawPhase


Func _DrawFFT()
    Local $iTimer = TimerInit()
    _BASS_EXT_ChannelGetFFT($hStream, $aFFT, 6)
    If Not @error Then DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "handle", $hGfxBuffer, "handle", $hBrushFFT, "ptr", $aFFT[0], "int", $aFFT[1], "int", "FillModeAlternate")
EndFunc   ;==>_DrawFFT





Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_PAINT

Func _BMPCreateBackGround($iW, $iH, $hGraphics)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    Local $hBrushBK = _GDIPlus_BrushCreateSolid(0xEE000000)
    Local $hBrushTXT = _GDIPlus_BrushCreateSolid(0xFF99AAFF)
    Local $hPen = _GDIPlus_PenCreate(0xFF222222, 1)
    _GDIPlus_GraphicsDrawImage($hContext, $hBmpLed, 10, 10)
    _GDIPlus_GraphicsDrawImageRectRect($hContext, $hBmpMeter, 0, 0, 15, 360, 10, 30, 15, 360)
    _GDIPlus_GraphicsDrawImageRectRect($hContext, $hBmpMeter, 0, 0, 20, 360, 30, 30, 20, 360)
    _GDIPlus_GraphicsDrawImage($hContext, $hBmpLed, 80, 10)
    _GDIPlus_GraphicsDrawImageRectRect($hContext, $hBmpMeter, 0, 0, 15, 360, 80, 30, 15, 360)
    _GDIPlus_GraphicsDrawImageRectRect($hContext, $hBmpMeter, 0, 0, 20, 360, 100, 30, 20, 360)
    _GDIPlus_GraphicsDrawImageRectRect($hContext, $hBmpPhaseMeter, 0, 0, 200, 10, 130, 200, 200, 10)
    DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "handle", $hContext, "handle", $hBrushFFT, "ptr", $aFFT[0], "int", $aFFT[1], "int", "FillModeAlternate")
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $iW, $iH, $hBrushBK)
    _GDIPlus_GraphicsDrawImage($hContext, $hBmpPhase, 130, 10)
    _GDIPlus_GraphicsDrawImage($hContext, $hBmpWave, 340, 10)
    _DrawText($hContext, "PEAK", 26, 13, 6, $hBrushTXT)
    _DrawText($hContext, "PEAK", 96, 13, 6, $hBrushTXT)
    Local $sString
    Local $nY
    For $i = 0 To 59 Step 3
        $nY = _BASS_EXT_Level2dB(_BASS_EXT_dB2Level(-$i), 60)
        $sString = "-" & $i
        If $i = 0 Then $sString = "0 dB"
        _DrawText($hContext, $sString, 65, 390 - (360 * $nY), 7, $hBrushTXT, True)
    Next
    _GDIPlus_GraphicsDrawRect($hContext, 129, 9, 201, 201, $hPen)
    _GDIPlus_GraphicsDrawRect($hContext, 129, 199, 201, 11, $hPen)
    _GDIPlus_GraphicsDrawRect($hContext, 339, 9, 201, 201, $hPen)
    _GDIPlus_GraphicsDrawRect($hContext, 129, 219, 411, 171, $hPen)
    _GDIPlus_GraphicsDrawRect($hContext, 9, 9, 111, 381, $hPen)
    _GDIPlus_GraphicsDrawRect($hContext, 9, 29, 16, 361, $hPen)
    _GDIPlus_GraphicsDrawRect($hContext, 29, 29, 21, 361, $hPen)
    _GDIPlus_GraphicsDrawRect($hContext, 79, 29, 16, 361, $hPen)
    _GDIPlus_GraphicsDrawRect($hContext, 99, 29, 21, 361, $hPen)

    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrushBK)
    _GDIPlus_BrushDispose($hBrushTXT)
    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
EndFunc   ;==>_BMPCreateBackGround

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($ghGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hBitmap, "int", 0, "int*", 0)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $aRet[3]
EndFunc   ;==>_BrushCreateFFT

Func _BMPCreateWave($iW, $iH, $hGraphics)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    Local $hPenL = _GDIPlus_PenCreate(0xFF003300)
    Local $hPenR = _GDIPlus_PenCreate(0xFF330000)
    Local $hBrushL = _GDIPlus_BrushCreateSolid(0xFF00FF00)
    Local $hBrushR = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    _GDIPlus_GraphicsDrawLine($hContext, 0, 60, $iW, 60, $hPenL)
    _GDIPlus_GraphicsDrawLine($hContext, 0, 140, $iW, 140, $hPenR)
    _DrawText($hContext, "left", 5, 62, 7, $hBrushL, False)
    _DrawText($hContext, "right", 5, 142, 7, $hBrushR, False)
    _GDIPlus_PenDispose($hPenL)
    _GDIPlus_PenDispose($hPenR)
    _GDIPlus_BrushDispose($hBrushL)
    _GDIPlus_BrushDispose($hBrushR)
    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
EndFunc   ;==>_BMPCreateWave

Func _BMPCreatePhaseMeter($iW, $hGraphics)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, 12, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    Local $hBrush[5]
    $hBrush[0] = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    $hBrush[1] = _GDIPlus_LineBrushCreate(80, 0, 100, 0, 0xFFFF0000, 0xFFFFFF00, 1)
    $hBrush[2] = _GDIPlus_LineBrushCreate(100, 0, 120, 0, 0xFFFFFF00, 0xFF00FF00, 1)
    $hBrush[3] = _GDIPlus_BrushCreateSolid(0xFF00FF00)
    $hBrush[4] = _GDIPlus_LineBrushCreate(0, 0, 4, 0, 0x00000000, 0xAA000000, 0)
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, 80, 12, $hBrush[0])
    _GDIPlus_GraphicsFillRect($hContext, 80, 0, 20, 12, $hBrush[1])
    _GDIPlus_GraphicsFillRect($hContext, 100, 0, 20, 12, $hBrush[2])
    _GDIPlus_GraphicsFillRect($hContext, 120, 0, 100, 12, $hBrush[3])
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, 200, 12, $hBrush[4])
    For $i = 0 To 4
        _GDIPlus_BrushDispose($hBrush[$i])
    Next
    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
EndFunc   ;==>_BMPCreatePhaseMeter

Func _BMPCreatePhase($iW, $iH, $hGraphics)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    Local $hPen = _GDIPlus_PenCreate(0xFF332200)
    Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFAA00)
    Local $nPi = ATan(1) * 4
    Local $nDegToRad = $nPi / 180
    Local $iLX, $iLY
    For $i = 0 To 135 Step 45
        $iLX = Round(Cos($i * $nDegToRad) * $iW * 0.35)
        $iLY = Round(Sin($i * $nDegToRad) * $iW * 0.35)
        _GDIPlus_GraphicsDrawLine($hContext, $iW / 2 - $iLX, $iH / 2 - $iLY, $iW / 2 + $iLX, $iH / 2 + $iLY, $hPen)
        Switch $i
            Case 45
                _DrawText($hContext, "L", $iW / 2 - $iLX * 1.2, $iH / 2 - $iLY * 1.3, 7, $hBrush, True)
            Case 90
                _DrawText($hContext, "M", $iW / 2 - $iLX * 1.2, $iH / 2 - $iLY * 1.27, 7, $hBrush, True)
            Case 135
                _DrawText($hContext, "R", $iW / 2 - $iLX * 1.2, $iH / 2 - $iLY * 1.3, 7, $hBrush, True)
        EndSwitch
    Next
    For $i = -1 To 1
        _DrawText($hContext, $i, 101 + 90 * $i, 178, 7, $hBrush, True)
    Next
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
EndFunc   ;==>_BMPCreatePhase

Func _BMPCreateLED($hGraphics, $iSize, $iOffColor, $iOnColor)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iSize, $iSize, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
    Local $hPen = _GDIPlus_PenCreate()
    Local $hPath = _GDIPlus_CreatePath()
    _GDIPlus_AddPathEllipse($hPath, 0, 0, $iSize, $iSize)
    Local $hBrushGrad = _GDIPlus_CreatePathGradientFromPath($hPath)
    _GDIPlus_SetLineGammaCorrection($hBrushGrad, True)
    _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrushGrad, $iOffColor)
    _GDIPlus_SetPathGradientCenterColor($hBrushGrad, $iOnColor)
    _GDIPlus_FillPath($hContext, $hBrushGrad, $hPath)
    _GDIPlus_ClosePathFigure($hPath)
    _GDIPlus_GraphicsDrawEllipse($hContext, 0, 0, $iSize, $iSize, $hPen)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrushGrad)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
EndFunc   ;==>_BMPCreateLED

Func _BMPCreateMeter($iH, $hGraphics)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(30, $iH, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    Local $hBrush[6], $iT = Ceiling($iH / 12)
    $hBrush[0] = _GDIPlus_BrushCreateSolid(0xFFFF0000)
    $hBrush[1] = _GDIPlus_LineBrushCreate(0, $iT, 0, $iT * 2, 0xFFFF0000, 0xFFFFFF00, 1)
    $hBrush[2] = _GDIPlus_LineBrushCreate(0, $iT * 2, 0, $iT * 3, 0xFFFFFF00, 0xFF00FF00, 1)
    $hBrush[3] = _GDIPlus_BrushCreateSolid(0xFF00FF00)
    $hBrush[4] = _GDIPlus_LineBrushCreate(0, 0, 0, 4, 0x00000000, 0xAA000000, 0)
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, 30, $iT, $hBrush[0])
    _GDIPlus_GraphicsFillRect($hContext, 0, $iT, 30, $iT, $hBrush[1])
    _GDIPlus_GraphicsFillRect($hContext, 0, $iT * 2, 30, $iT, $hBrush[2])
    _GDIPlus_GraphicsFillRect($hContext, 0, $iT * 3, 30, $iT * 9, $hBrush[3])
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, 30, $iT * 12, $hBrush[4])
    For $i = 0 To 4
        _GDIPlus_BrushDispose($hBrush[$i])
    Next
    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
EndFunc   ;==>_BMPCreateMeter

Func _DrawText($hGraphics, $sText, $iX, $iY, $iSize, $hBrush, $bCenter = False)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iSize, 0)
    Local $tLayout = _GDIPlus_RectFCreate($iX, $iY, 0, 0)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sText, $hFont, $tLayout, $hFormat)
    If $bCenter Then
        Local $iXPos = DllStructGetData($aInfo[0], 1)
        DllStructSetData($aInfo[0], 1, $iXPos - DllStructGetData($aInfo[0], 3) / 2)
    EndIf
    _GDIPlus_GraphicsDrawStringEx($hGraphics, $sText, $hFont, $aInfo[0], $hFormat, $hBrush)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
EndFunc   ;==>_DrawText

Func _Exit()
    _BASS_EXT_ChannelRemoveMaxPeakDsp($aPeak)
    ___Debug(@error, "remove peak dsp")

    _BASS_ChannelStop($hStream)
    ___Debug(@error, "stop stream")

    _BASS_StreamFree($hStream)
    ___Debug(@error, "free stream")

    _BASS_Free()
    ___Debug(@error, "free bass")

    _GDIPlus_BitmapDispose($hBmpMeter)
    _GDIPlus_BitmapDispose($hBmpLed)
    _GDIPlus_BitmapDispose($hBmpPhaseMeter)
    _GDIPlus_BitmapDispose($hBmpPhase)
    _GDIPlus_PenDispose($hPenPhase)
    _GDIPlus_BitmapDispose($hBmpWave)
    _GDIPlus_PenDispose($hPenWaveL)
    _GDIPlus_PenDispose($hPenWaveR)
    _GDIPlus_BrushDispose($hBrushFFT)
    _GDIPlus_BitmapDispose($hBmpBk)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Func ___DeBug($iError, $sAction)
    Switch $iError
        Case -1
            ConsoleWrite(@CRLF & "-" & $sAction & @CRLF)
        Case -2
            ConsoleWrite(@CRLF & ">" & $sAction & @CRLF)
        Case 0
            ConsoleWrite(@CRLF & "+" & $sAction & " - OK" & @CRLF)
        Case Else
            ConsoleWrite(@CRLF & "!" & $sAction & " - FAILED, @error: " & $iError & @CRLF)
            _Exit()
    EndSwitch
EndFunc   ;==>___DeBug

Func _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2, $iWrapMode = 0)
    Local $tPointF1, $pPointF1
    Local $tPointF2, $pPointF2
    Local $aResult

    $tPointF1 = DllStructCreate("float;float")
    $pPointF1 = DllStructGetPtr($tPointF1)
    $tPointF2 = DllStructCreate("float;float")
    $pPointF2 = DllStructGetPtr($tPointF2)

    DllStructSetData($tPointF1, 1, $nX1)
    DllStructSetData($tPointF1, 2, $nY1)
    DllStructSetData($tPointF2, 1, $nX2)
    DllStructSetData($tPointF2, 2, $nY2)

    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iARGBClr1, "uint", $iARGBClr2, "int", $iWrapMode, "int*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    ;$GDIP_STATUS = $aResult[0]
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_LineBrushCreate

Func _GDIPlus_CreatePath($brushMode = 0)
    Local $hPath
    $hPath = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", $brushMode, "handle*", 0)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($hPath[0], 0, $hPath[2])
EndFunc   ;==>_GDIPlus_CreatePath

Func _GDIPlus_AddPathEllipse($hPath, $iX, $iY, $iWidth, $iHeight)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipAddPathEllipse", "handle", $hPath, "float", $iX, "float", $iY, "float", $iWidth, "float", $iHeight)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_AddPathEllipse

Func _GDIPlus_CreatePathGradientFromPath($hPath)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePathGradientFromPath", "handle", $hPath, "int*", 0)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($aResult[0], 0, $aResult[2])
EndFunc   ;==>_GDIPlus_CreatePathGradientFromPath

Func _GDIPlus_SetLineGammaCorrection($hBrush, $useGammaCorrection = True)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipSetLineGammaCorrection", "handle", $hBrush, "int", $useGammaCorrection)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_SetLineGammaCorrection

Func _GDIPlus_SetPathGradientCenterColor($hBrush, $iARGB)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientCenterColor", "handle", $hBrush, "int", $iARGB)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_SetPathGradientCenterColor

Func _GDIPlus_FillPath($hGraphic, $hBrushGrad, $hPath)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipFillPath", "handle", $hGraphic, "handle", $hBrushGrad, "handle", $hPath)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_FillPath

Func _GDIPlus_SetPathGradientSurroundColorsWithCount($hBrush, $aArgb)
    Local $iI, $iCount, $aResult, $res, $x, $pArgb
    If IsArray($aArgb) Then
        $iCount = UBound($aArgb)
        Local $tArgb = DllStructCreate("int[" & $iCount & "]")
        Local $pArgb = DllStructGetPtr($tArgb)
        For $iI = 0 To $iCount - 1
            DllStructSetData($tArgb, 1, $aArgb[$iI], $iI + 1)
        Next
    Else
        $iCount = 1
        Local $tArgb = DllStructCreate("int")
        Local $pArgb = DllStructGetPtr($tArgb)
        DllStructSetData($tArgb, 1, $aArgb, 1)
    EndIf
    $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientSurroundColorsWithCount", "handle", $hBrush, "int", $pArgb, "int*", $iCount)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($aResult[0], $aResult[3], $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_SetPathGradientSurroundColorsWithCount

Func _GDIPlus_ClosePathFigure($hPath)
    Local $aResult = DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "handle", $hPath)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_ClosePathFigure

Func _GDIPlus_PathDispose($hPath)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeletePath", "handle", $hPath)
    If @error Then Return SetError(1, @error, 0)
    Return SetError($aResult[0], 0, $aResult[0] = 0)
EndFunc   ;==>_GDIPlus_PathDispose
Link to comment
Share on other sites

The only thing that I can see right off the bat is that you're using _BASS_StreamFree just before using _BASS_Free, there shouldn't be any need to use _StreamFree if you're using _Free. Not that it will cause any issues, but a point to remember.

On my computer, this script uses about 35MB up to the point of asking for which file to play, which means none of the other functions have even started yet, and then when playing adds an addition 8MB. I don't see any changes in memory usage as the song is playing, so it doesn't appear that there's any abnormal memory usage going on.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@timmy2:

This looks ok:

#AutoIt3Wrapper_UseX64=n
#include "Bass.au3"
#include "BassExt.au3"
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

;file dialog for testing only. Actual audio file will be specified in the script.
Global $sFile = FileOpenDialog("Open...", "", "playable formats (*.MP3;*.MP2;*.MP1;*.OGG;*.WAV;*.AIFF;*.AIF)")
If @error Or Not FileExists($sFile) Then Exit

Global $iWidth = 410
Global $iHeight = 170

Global $hGui, $hGraphics, $hGfxBuffer, $hBmpBuffer, $hBmpBk, $hBrushFFT
Global $aFFT, $aPeak
Global $iTimer
Global $hStream

$hGui = GUICreate("BASS_EXT AudioMeter", $iWidth, $iHeight, -1,-1, BitOR($WS_SYSMENU,$WS_POPUP))
GUISetBkColor(0x000000)

_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
$hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)


$hBrushFFT = _BrushCreateFFT(0, 0, 410, 170, $iWidth, $iHeight, $hGraphics)
$aFFT = _BASS_EXT_CreateFFT(410 / 5, 0, 0, 410, 170, 1, 70, True)

$hBmpBk = _BMPCreateBackGround($iWidth, $iHeight, $hGraphics)


_BASS_Startup(@ScriptDir & "\bass.dll")
;__Debug(@error, "load bass.dll")

_BASS_EXT_Startup(@ScriptDir & "\bassExt.dll")
;__Debug(@error, "load bassext.dll")

_BASS_Init(0, -1, 44100, 0, "")
;__Debug(@error, "initialize bass")

_BASS_SetConfig($BASS_CONFIG_UPDATEPERIOD, 100)
;__Debug(@error, "set update period")

_BASS_SetConfig($BASS_CONFIG_BUFFER, 250)
;__Debug(@error, "set buffer size")

GUIRegisterMsg(0x000F, "WM_PAINT")
GUISetState()

$hStream = _BASS_StreamCreateFile(False, $sFile, 0, 0, 0)
;__Debug(@error, "create stream from file: " & $sFile)

$aPeak = _BASS_EXT_ChannelSetMaxPeakDsp($hStream)
;__Debug(@error, "set dsp callback to check for the highest peak")

_BASS_ChannelPlay($hStream, True)
;__Debug(@error, "start stream")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While _BASS_ChannelIsActive($hStream)
    _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpBk, 0, 0)

    _BASS_EXT_ChannelGetFFT($hStream, $aFFT, 6)
    If Not @error Then DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "handle", $hGfxBuffer, "handle", $hBrushFFT, "ptr", $aFFT[0], "int", $aFFT[1], "int", "FillModeAlternate")

    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Sleep(30)
WEnd

Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_PAINT

Func _BMPCreateBackGround($iW, $iH, $hGraphics)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    Local $hBrushBK = _GDIPlus_BrushCreateSolid(0xEE000000)
    Local $hBrushTXT = _GDIPlus_BrushCreateSolid(0xFF99AAFF)
    Local $hPen = _GDIPlus_PenCreate(0xFF222222, 1)

    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrushBK)
    _GDIPlus_BrushDispose($hBrushTXT)
    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
EndFunc   ;==>_BMPCreateBackGround

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($ghGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hBitmap, "int", 0, "int*", 0)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $aRet[3]
EndFunc   ;==>_BrushCreateFFT

Func _Exit()
    _BASS_EXT_ChannelRemoveMaxPeakDsp($aPeak)
    ;___Debug(@error, "remove peak dsp")

    _BASS_ChannelStop($hStream)
    ;___Debug(@error, "stop stream")

    _BASS_StreamFree($hStream)
    ;___Debug(@error, "free stream")

    _BASS_Free()
    ;___Debug(@error, "free bass")

    _GDIPlus_BrushDispose($hBrushFFT)
    _GDIPlus_BitmapDispose($hBmpBk)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc   ;==>_Exit

;~ Func ___DeBug($iError, $sAction)
;~  Switch $iError
;~      Case -1
;~          ConsoleWrite(@CRLF & "-" & $sAction & @CRLF)
;~      Case -2
;~          ConsoleWrite(@CRLF & ">" & $sAction & @CRLF)
;~      Case 0
;~          ConsoleWrite(@CRLF & "+" & $sAction & " - OK" & @CRLF)
;~      Case Else
;~          ConsoleWrite(@CRLF & "!" & $sAction & " - FAILED, @error: " & $iError & @CRLF)
;~          _Exit()
;~  EndSwitch
;~ EndFunc   ;==>___DeBug

Func _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2, $iWrapMode = 0)
    Local $tPointF1, $pPointF1
    Local $tPointF2, $pPointF2
    Local $aResult

    $tPointF1 = DllStructCreate("float;float")
    $pPointF1 = DllStructGetPtr($tPointF1)
    $tPointF2 = DllStructCreate("float;float")
    $pPointF2 = DllStructGetPtr($tPointF2)

    DllStructSetData($tPointF1, 1, $nX1)
    DllStructSetData($tPointF1, 2, $nY1)
    DllStructSetData($tPointF2, 1, $nX2)
    DllStructSetData($tPointF2, 2, $nY2)

    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iARGBClr1, "uint", $iARGBClr2, "int", $iWrapMode, "int*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    ;$GDIP_STATUS = $aResult[0]
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_LineBrushCreate

Br,

UEZ

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

Selection of finest graphical examples at Codepen.io

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

Link to comment
Share on other sites

The only thing that I can see right off the bat is that you're using _BASS_StreamFree just before using _BASS_Free, there shouldn't be any need to use _StreamFree if you're using _Free. Not that it will cause any issues, but a point to remember.

On my computer, this script uses about 35MB up to the point of asking for which file to play, which means none of the other functions have even started yet, and then when playing adds an addition 8MB. I don't see any changes in memory usage as the song is playing, so it doesn't appear that there's any abnormal memory usage going on.

 

Thank for your help, BrewManNH.  You mention looking at memory usage. I was about to submit a new post asking what tools folks might here use to check on whether their scripts have cleanly exited without leaving behind any debris. For example, I was wondering if Process Explorer would be useful and if so, what would one look for?  Have you ever seen anything written about this?

Link to comment
Share on other sites

@timmy2:

This looks ok:

#AutoIt3Wrapper_UseX64=n
#include "Bass.au3"
#include "BassExt.au3"
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

;file dialog for testing only. Actual audio file will be specified in the script.
Global $sFile = FileOpenDialog("Open...", "", "playable formats (*.MP3;*.MP2;*.MP1;*.OGG;*.WAV;*.AIFF;*.AIF)")
If @error Or Not FileExists($sFile) Then Exit

Global $iWidth = 410
Global $iHeight = 170

Global $hGui, $hGraphics, $hGfxBuffer, $hBmpBuffer, $hBmpBk, $hBrushFFT
Global $aFFT, $aPeak
Global $iTimer
Global $hStream

$hGui = GUICreate("BASS_EXT AudioMeter", $iWidth, $iHeight, -1,-1, BitOR($WS_SYSMENU,$WS_POPUP))
GUISetBkColor(0x000000)

_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
$hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
$hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfxBuffer, 2)


$hBrushFFT = _BrushCreateFFT(0, 0, 410, 170, $iWidth, $iHeight, $hGraphics)
$aFFT = _BASS_EXT_CreateFFT(410 / 5, 0, 0, 410, 170, 1, 70, True)

$hBmpBk = _BMPCreateBackGround($iWidth, $iHeight, $hGraphics)


_BASS_Startup(@ScriptDir & "\bass.dll")
;__Debug(@error, "load bass.dll")

_BASS_EXT_Startup(@ScriptDir & "\bassExt.dll")
;__Debug(@error, "load bassext.dll")

_BASS_Init(0, -1, 44100, 0, "")
;__Debug(@error, "initialize bass")

_BASS_SetConfig($BASS_CONFIG_UPDATEPERIOD, 100)
;__Debug(@error, "set update period")

_BASS_SetConfig($BASS_CONFIG_BUFFER, 250)
;__Debug(@error, "set buffer size")

GUIRegisterMsg(0x000F, "WM_PAINT")
GUISetState()

$hStream = _BASS_StreamCreateFile(False, $sFile, 0, 0, 0)
;__Debug(@error, "create stream from file: " & $sFile)

$aPeak = _BASS_EXT_ChannelSetMaxPeakDsp($hStream)
;__Debug(@error, "set dsp callback to check for the highest peak")

_BASS_ChannelPlay($hStream, True)
;__Debug(@error, "start stream")

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While _BASS_ChannelIsActive($hStream)
    _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpBk, 0, 0)

    _BASS_EXT_ChannelGetFFT($hStream, $aFFT, 6)
    If Not @error Then DllCall($ghGDIPDll, "int", "GdipFillPolygonI", "handle", $hGfxBuffer, "handle", $hBrushFFT, "ptr", $aFFT[0], "int", $aFFT[1], "int", "FillModeAlternate")

    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Sleep(30)
WEnd

Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_PAINT

Func _BMPCreateBackGround($iW, $iH, $hGraphics)
    Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hContext, 2)
    _GDIPlus_GraphicsClear($hContext, 0xFF000000)
    Local $hBrushBK = _GDIPlus_BrushCreateSolid(0xEE000000)
    Local $hBrushTXT = _GDIPlus_BrushCreateSolid(0xFF99AAFF)
    Local $hPen = _GDIPlus_PenCreate(0xFF222222, 1)

    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BrushDispose($hBrushBK)
    _GDIPlus_BrushDispose($hBrushTXT)
    _GDIPlus_GraphicsDispose($hContext)
    Return $hBitmap
EndFunc   ;==>_BMPCreateBackGround

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($ghGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hBitmap, "int", 0, "int*", 0)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $aRet[3]
EndFunc   ;==>_BrushCreateFFT

Func _Exit()
    _BASS_EXT_ChannelRemoveMaxPeakDsp($aPeak)
    ;___Debug(@error, "remove peak dsp")

    _BASS_ChannelStop($hStream)
    ;___Debug(@error, "stop stream")

    _BASS_StreamFree($hStream)
    ;___Debug(@error, "free stream")

    _BASS_Free()
    ;___Debug(@error, "free bass")

    _GDIPlus_BrushDispose($hBrushFFT)
    _GDIPlus_BitmapDispose($hBmpBk)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete()
    Exit
EndFunc   ;==>_Exit

;~ Func ___DeBug($iError, $sAction)
;~  Switch $iError
;~      Case -1
;~          ConsoleWrite(@CRLF & "-" & $sAction & @CRLF)
;~      Case -2
;~          ConsoleWrite(@CRLF & ">" & $sAction & @CRLF)
;~      Case 0
;~          ConsoleWrite(@CRLF & "+" & $sAction & " - OK" & @CRLF)
;~      Case Else
;~          ConsoleWrite(@CRLF & "!" & $sAction & " - FAILED, @error: " & $iError & @CRLF)
;~          _Exit()
;~  EndSwitch
;~ EndFunc   ;==>___DeBug

Func _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2, $iWrapMode = 0)
    Local $tPointF1, $pPointF1
    Local $tPointF2, $pPointF2
    Local $aResult

    $tPointF1 = DllStructCreate("float;float")
    $pPointF1 = DllStructGetPtr($tPointF1)
    $tPointF2 = DllStructCreate("float;float")
    $pPointF2 = DllStructGetPtr($tPointF2)

    DllStructSetData($tPointF1, 1, $nX1)
    DllStructSetData($tPointF1, 2, $nY1)
    DllStructSetData($tPointF2, 1, $nX2)
    DllStructSetData($tPointF2, 2, $nY2)

    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iARGBClr1, "uint", $iARGBClr2, "int", $iWrapMode, "int*", 0)

    If @error Then Return SetError(@error, @extended, 0)
    ;$GDIP_STATUS = $aResult[0]
    Return $aResult[6]
EndFunc   ;==>_GDIPlus_LineBrushCreate

Br,

UEZ

 

Thank you, UEZ, especially for cleaning it up a little. Greatly appreciated.

Link to comment
Share on other sites

using latest Bass-UDF and lastest AutoIt Beta (v3.3.9.22):

#AutoIt3Wrapper_Autoit3Dir=c:\Program Files (x86)\AutoIt3\Beta
#AutoIt3Wrapper_UseX64=n

#include "Bass.au3"
#include "BassExt.au3"
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)

Global $sFile = FileOpenDialog("Open...", "..\audiofiles", "playable formats (*.MP3;*.MP2;*.MP1;*.OGG;*.WAV;*.AIFF;*.AIF)")
If @error Or Not FileExists($sFile) Then Exit


Global $iWidth = 522
Global $iHeight = 170

Global $hGui = GUICreate("FFT", $iWidth, $iHeight, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP))
GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT")
_GDIPlus_Startup()
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
Global $hBmp_Buffer = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
Global $hGfx_Buffer = _GDIPlus_ImageGetGraphicsContext($hBmp_Buffer)
_GDIPlus_GraphicsSetSmoothingMode($hGfx_Buffer, 2)

Global $hBrush = _CreateFFTBrush(5, 5, $iWidth - 10, $iHeight - 10)

GUIRegisterMsg($WM_PAINT, "WM_PAINT")
GUISetState()

_BASS_Startup()
_BASS_EXT_Startup()
_BASS_Init(0, -1, 44100, 0, "")

Global $hStream = _BASS_StreamCreateFile(False, $sFile, 0, 0, $BASS_SAMPLE_FLOAT)
Global $aFFT = _BASS_EXT_CreateFFT(128, 5, 5, $iWidth - 10, $iHeight - 10, 1, True)

_BASS_ChannelPlay($hStream, True)



Global $iTimer = TimerInit()
While _BASS_ChannelIsActive($hStream)
    If TimerDiff($iTimer) > 20 Then
        $iTimer = TimerInit()
        _GDIPlus_GraphicsClear($hGfx_Buffer, 0xFF110022)

        _BASS_EXT_ChannelGetFFT($hStream, $aFFT, 2)
        If Not @error Then DllCall($ghGDIPDll, "int", "GdipFillPolygon", "handle", $hGfx_Buffer, "handle", $hBrush, "ptr", $aFFT[0], "int", $aFFT[1], "int", "FillModeAlternate")

        _GDIPlus_GraphicsDrawImage($hGraphics, $hBmp_Buffer, 0, 0)
    EndIf
WEnd
_Exit()



Func _CreateFFTBrush($iX, $iY, $iWidth, $iHeight)
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    Local $hBrush_FFT = _GDIPlus_LineBrushCreate(0, 0, 0, $iHeight, 0, 0, 3)
    Local $aColors[5][2] = [[4]]
    $aColors[1][0] = 0xFFFF0000
    $aColors[1][1] = 0
    $aColors[2][0] = 0xFFFFAA00
    $aColors[2][1] = 0.25
    $aColors[3][0] = 0xFF00AAFF
    $aColors[3][1] = 0.5
    $aColors[4][0] = 0xFF00AAFF
    $aColors[4][1] = 1
    _GDIPlus_LineBrushSetPresetBlend($hBrush_FFT, $aColors)

    Local $hBrush_LED = _GDIPlus_LineBrushCreate(0, 0, 0, 4, 0xAA000000, 0x00000000, 0)

    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $iWidth, $iHeight, $hBrush_FFT)
    _GDIPlus_GraphicsFillRect($hContext, 0, 0, $iWidth, $iHeight, $hBrush_LED)
    _GDIPlus_BrushDispose($hBrush_LED)
    _GDIPlus_BrushDispose($hBrush_FFT)
    _GDIPlus_GraphicsDispose($hContext)

    Local $hBrush = _GDIPlus_TextureCreate($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)

    DllCall($ghGDIPDll, "uint", "GdipTranslateTextureTransform", "hwnd", $hBrush, "float", $iX, "float", $iY, "int", 0)

    Return $hBrush
EndFunc   ;==>_CreateFFTBrush



Func WM_PAINT($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmp_Buffer, 0, 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT


Func _Exit()
    _BASS_StreamFree($hStream)
    _BASS_Free()

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGfx_Buffer)
    _GDIPlus_BitmapDispose($hBmp_Buffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit
Link to comment
Share on other sites

Hi all,

I've searched through this topic, and I did not found any example on how to record microphone into wav file on my HDD.

It is hard for a newcommer to understand such complex project such as this.

Would anyone be kind enough to provide an example how to record microphone into WAV?

#AutoIt3Wrapper_UseX64=n
#include "Bass.au3"
#include "BassExt.au3"
#include "BassEnc.au3"

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

_BASS_Startup()
_BASS_ENCODE_Startup()
_BASS_EXT_Startup()

_BASS_RecordInit(-1)

$hRecord = _BASS_RecordStart(44100, 2, 0, $BASS_EXT_RecordProc)
$hEncoder = _BASS_Encode_Start($hRecord, @ScriptDir & "\Record.wav", $BASS_ENCODE_PCM)

While 1
    ;$iBytes = _BASS_ChannelGetPosition($hRecord, $BASS_POS_BYTE)
    ;ToolTip($iBytes & " bytes recorded")
    Sleep(20)
WEnd


Func _EXIT()
    _BASS_Encode_Stop($hEncoder)
    _BASS_RecordFree()
    Exit
EndFunc   ;==>_EXIT
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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