[BASS] 2 Channels "überfaden" und Ergebnis direkt an Encoder weitergeben (-> Shoutcast)

  • Hi Leute,

    Ich habe im moment ein kleines Problem mit dem BASS-Kram.

    Ich würde gerne 2 getrennte Musik-Channels ineinanderfaden (also sowas wie CrossFade) und das Ergebnis in Echtzeit an den Bass Encoder weiterleiten (der die Daten an einen Shoutcastserver übermittelt).

    Die Übertragung zum Shoutcast Server klappt tadellos (bis auf den Fade, wie gesagt)

    Ich habe es bisjetzt mit dem Mixer-Modul von BASS probiert, aber bisjetzt kein zufriedenstellendes Ergebnis. :(

    Den aktuellen Sourcecode packe Ich natürlich bei.
    Edit: Ich häng ihn auch mal als Spoiler an

    Spoiler anzeigen
    [autoit]


    ;~ #NoTrayIcon
    #include ".\Includes\Bass.au3"
    #include ".\Includes\BassEnc.au3"
    #include ".\Includes\BassMix.au3"
    #include ".\Includes\Helper.au3"

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

    Global $hStream1, $hStream2, $hEncoder

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

    Global Const $sStreamInfo_Server = "*****"
    Global Const $sStreamInfo_PW = "*****"

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

    Global $aMixerMatrix[2][3]
    $aMixerMatrix[0][0] = 1
    $aMixerMatrix[0][1] = 2

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

    Global Const $sStreamInfo_Content = "Keine Ahnung"
    Global Const $sStreamInfo_Name = "Name"
    Global Const $sStreamInfo_URL = "URL"
    Global Const $sStreamInfo_Genre = "Genre"
    Global Const $sStreamInfo_Desc = "Description"
    Global Const $sStreamInfo_Headers = ""
    Global Const $iStreamInfo_Bitrate = 128
    Global Const $fStreamInfo_Pub = False

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

    __Debug("init Bass libarys")
    _BASS_Startup(@ScriptDir & "\Resources\Bass.dll")
    _BASS_ENCODE_Startup(@ScriptDir & "\Resources\BassEnc.dll")
    _BASS_MIX_Startup(@ScriptDir & "\Resources\BassMix.dll")
    _BASS_Init(0, -1, 44100, 0, "")

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

    __Debug("create stream(s) with music")
    $hStream1 = _BASS_StreamCreateFile(False, @ScriptDir & "\Music1.mp3", 0, 0, $BASS_STREAM_DECODE)
    _BASS_ChannelStop($hStream1)
    $hStream2 = _BASS_StreamCreateFile(False, @ScriptDir & "\Music2.mp3", 0, 0, $BASS_STREAM_DECODE)
    _BASS_ChannelStop($hStream2)

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

    __Debug("create mixer")
    $hMixer = _BASS_Mixer_StreamCreate(44100, 2, $BASS_MIXER_NONSTOP)

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

    __Debug("set channel matrix")
    ;~ _BASS_Mixer_ChannelSetMatrix($hStream1, $aMixerMatrix)
    ;~ _BASS_Mixer_ChannelSetMatrix($hStream2, $aMixerMatrix)

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

    __Debug("add channels to mixer")
    _BASS_Mixer_StreamAddChannel($hMixer, $hStream1, $BASS_MIXER_DOWNMIX)
    _BASS_Mixer_StreamAddChannel($hMixer, $hStream2, $BASS_MIXER_DOWNMIX)

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

    __Debug("create encoder")
    $hEncoder = _BASS_Encode_Start($hMixer, '"' & @ScriptDir & '\Resources\lame" -r -x -s 44.1 -m j -b 128 -', 0)
    _BASS_Encode_SetNotify($hEncoder, "_EncodeNotifyProc", 0)

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

    __Debug("init encoder cast")
    $fCastSuccess = _BASS_Encode_CastInit($hEncoder, "stream2cloud.de:8002", "wechseln", $BASS_ENCODE_TYPE_MP3, $sStreamInfo_Name, $sStreamInfo_URL, _
    $sStreamInfo_Genre, $sStreamInfo_Desc, $sStreamInfo_Headers, $iStreamInfo_Bitrate, $fStreamInfo_Pub)

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

    __Debug("set encoder title/url")
    _BASS_Encode_CastSetTitle($hEncoder, $sStreamInfo_Name, $sStreamInfo_URL)

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

    Sleep(1000)

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

    _BASS_ChannelSetVolume($hStream1, 100)
    _BASS_ChannelSetVolume($hStream2, 0)

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

    __Debug("play file(s) on channel(s)")
    _BASS_ChannelPlay($hStream1, True)
    _BASS_ChannelPlay($hStream2, True)

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

    ProgressOn("StreamerTool", "streaming (" & (@ScriptDir & "\Music.mp3") & ")", "please wait")
    $iPercent = 0
    $iChannel1Vol = 0
    $iChannel2Vol = 0
    For $iX = 0 To 200
    $iPercent = $iX * 100 / 200
    $iChannel1Vol = 100 - $iPercent
    $iChannel2Vol = $iPercent

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

    ProgressSet($iPercent, $iPercent & " percent of song finished")
    _BASS_ChannelSetVolume($hStream1, $iChannel1Vol)
    _BASS_ChannelSetVolume($hStream2, $iChannel2Vol)

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

    ConsoleWrite("Channel1: " & $iChannel1Vol & " | Channel2: " & $iChannel2Vol & @LF)

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

    Sleep(100)
    Next
    ProgressOff()

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

    __Debug("stop encoder")
    _BASS_Encode_Stop($hEncoder)
    __Debug("free stream")
    _BASS_StreamFree($hStream1)
    __Debug("release bass libary")
    _BASS_Free()

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

    Func _EncodeNotifyProc($handle, $status, $user)
    Switch $status
    Case $BASS_ENCODE_NOTIFY_ENCODER
    ConsoleWrite(@CRLF & "!The encoder died." & @CRLF)
    Case $BASS_ENCODE_NOTIFY_CAST
    ConsoleWrite(@CRLF & "!Cast server connection died." & @CRLF)
    Case $BASS_ENCODE_NOTIFY_CAST_TIMEOUT
    ConsoleWrite(@CRLF & "!Cast server connection died." & @CRLF)
    Case Else
    ConsoleWrite(@CRLF & "!EncodeNotifyProc" & @CRLF)
    EndSwitch
    EndFunc ;==>_EncodeNotifyProc

    [/autoit]

    Wäre Nett, wen mir da jemand helfen könnte.

    mfg,
    Dominik

  • probier mal das hier,ist zwar noch nicht fertig,sollte mal ein kleiner DJ-Player werden,aber die FAde-Funktion sollte klappen.Songs per Drag&Drop ins Window,dann gehts gleich los(autoplay)

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <SliderConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <Bass.au3>
    #include <BassExt.au3>
    #include <BassConstants.au3>
    #include <BassFXConstants.au3>
    #include <BassFX.au3>
    #include <Array.au3>

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

    Global $playing_state = -1
    Opt("GuiOnEventMode", 1)
    AdlibRegister("fader1",10)
    HotKeySet("{ESC}", "ende")
    HotKeySet("{y}", "cuesetleft")
    HotKeySet("{x}", "cueleft")
    HotKeySet("{d}", "cueleft")
    Global $_MusicHandleleft,$tempoleft, $_CURRENTPositionleft,$_MusicHandleright,$temporight, $_CURRENTPositionright,$links=100,$rechts=0

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

    #Region ### START Koda GUI section ### Form=
    $Form1_1 = GUICreate("Form1", 1149, 218,81, 29, $WS_BORDER, $WS_EX_ACCEPTFILES)
    GUISetFont(16, 400, 0, "Myriad Pro")
    $Label1 = GUICtrlCreateInput("", 24, 14, 375, 37,$WS_BORDER )
    GUICtrlSetState(-1, $GUI_DROPACCEPTED )
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetBkColor(-1, 0x808000)
    $Label2 = GUICtrlCreateInput("", 738, 12, 375, 37,$WS_BORDER )
    GUICtrlSetState(-1, $GUI_DROPACCEPTED )
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetBkColor(-1, 0x808000)
    $Play = GUICtrlCreateButton("Play", 36, 142, 51, 35, $WS_GROUP)
    $Stop = GUICtrlCreateButton("Stop", 114, 142, 51, 35, $WS_GROUP)
    $Slider3 = GUICtrlCreateSlider(24, 78, 377, 41, BitOR($TBS_AUTOTICKS,$TBS_BOTH))
    $Slider2 = GUICtrlCreateSlider(738, 76, 377, 41, BitOR($TBS_AUTOTICKS,$TBS_BOTH))
    $Button1 = GUICtrlCreateButton("Stop", 981, 140, 51, 35, $WS_GROUP)
    $Button2 = GUICtrlCreateButton("Play", 1059, 140, 51, 35, $WS_GROUP)
    Global $Slider1 = GUICtrlCreateSlider(456, 140, 229, 33, BitOR($TBS_TOP,$TBS_LEFT,$TBS_BOTH,$TBS_NOTICKS,$WS_BORDER))
    GUISetState(@SW_SHOW)
    GUICtrlSetOnEvent($Play, "Play1")
    GUICtrlSetOnEvent($Stop, "stop1")
    GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "reverse1")
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "forward1")
    GUISetOnEvent($GUI_EVENT_DROPPED,"laden")
    #EndRegion ### END Koda GUI section ###
    _BASS_Startup ("G:\CODING\AutoIt3\Include\bass.dll")
    _BASS_FX_Startup ("G:\CODING\AutoIt3\Include\bass_fx.dll")
    _BASS_Init(0, -1, 44100, 0, "")

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

    func laden()
    if @GUI_DropId=$Label1 then
    _BASS_StreamFree($_MusicHandleleft)
    $_MusicHandleleft = _BASS_StreamCreateFile(False, @GUI_DRAGFILE, 0, 0,$BASS_STREAM_DECODE)
    $tempoleft = _BASS_FX_ReverseCreate ($_MusicHandleleft, 1, 0)
    _BASS_ChannelSetAttribute ($tempoleft, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_FORWARD)
    _BASS_ChannelSetPosition($tempoleft, $_CURRENTPositionleft, $BASS_POS_BYTE)
    _BASS_ChannelPlay($_MusicHandleleft, False)
    play1()
    endif
    if @GUI_DropId=$Label2 then
    _BASS_StreamFree($_MusicHandleright)
    $_MusicHandleright = _BASS_StreamCreateFile(False, @GUI_DRAGFILE, 0, 0,$BASS_STREAM_DECODE)
    $temporight = _BASS_FX_ReverseCreate ($_MusicHandleright, 1, 0)
    _BASS_ChannelSetAttribute ($temporight, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_FORWARD)
    _BASS_ChannelSetPosition($temporight, $_CURRENTPositionright, $BASS_POS_BYTE)
    _BASS_ChannelPlay($_MusicHandleright, False)
    play2()
    endif
    EndFunc

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

    Func fader1()
    _BASS_ChannelSetVolume($tempoleft,$links)
    _BASS_ChannelSetVolume($temporight,$rechts)
    fader()
    EndFunc

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

    func fader()
    Select
    case guictrlread($Slider1)=0
    $links=100
    $rechts=0
    case guictrlread($Slider1)=100
    $links=0
    $rechts=100
    case guictrlread($Slider1)=50
    $links=100
    $rechts=100
    case guictrlread($Slider1)>0 And guictrlread($Slider1)<50
    $links=100
    $rechts=guictrlread($Slider1)*2
    case guictrlread($Slider1)>50 And guictrlread($Slider1)<100
    $links=200-guictrlread($Slider1)*2
    $rechts=100
    EndSelect
    EndFunc

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

    #region left

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

    Func forward1()
    if _IsPressed(01) then
    _BASS_ChannelSetAttribute ($tempoleft, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_FORWARD)
    endif
    EndFunc ;==>forward

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

    Func reverse1()
    if _IsPressed(02) then
    _BASS_ChannelSetAttribute ($tempoleft, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_REVERSE)
    endif
    EndFunc ;==>reverse

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

    Func play1()
    _BASS_ChannelPlay($tempoleft, False)
    EndFunc ;==>play

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

    Func stop1()
    _BASS_ChannelStop($tempoleft)
    EndFunc ;==>play

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

    Func cueleft()
    _BASS_ChannelSetPosition($tempoleft, $_CURRENTPositionleft, $BASS_POS_BYTE)
    EndFunc ;==>stop

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

    Func cuesetleft()
    $_CURRENTPositionleft = _BASS_ChannelGetPosition($tempoleft, $BASS_POS_BYTE)
    EndFunc ;==>load

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

    #endregion left

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

    #region right

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

    Func forward2()
    if _IsPressed(01) then
    _BASS_ChannelSetAttribute ($temporight, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_FORWARD)
    endif
    EndFunc ;==>forward

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

    Func reverse2()
    if _IsPressed(02) then
    _BASS_ChannelSetAttribute ($temporight, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_REVERSE)
    endif
    EndFunc ;==>reverse

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

    Func play2()
    _BASS_ChannelPlay($temporight, False);
    EndFunc ;==>play

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

    Func stop2()
    _BASS_ChannelSetPosition($temporight, $_CURRENTPositionright, $BASS_POS_BYTE)
    EndFunc ;==>stop

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

    Func load2()
    $_CURRENTPositionright = _BASS_ChannelGetPosition($temporight, $BASS_POS_BYTE)
    EndFunc ;==>load

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

    #endregion right
    While 1
    Sleep(10)
    ;$_CURRENTPosition = _BASS_ChannelGetPosition($_MusicHandle, $BASS_POS_BYTE)
    WEnd

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

    Func ende()
    _BASS_ChannelStop($_MusicHandleleft)
    _BASS_StreamFree($_MusicHandleleft)
    _BASS_Free()
    Exit
    EndFunc ;==>ende

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

    #cs
    #include <Bass.au3>
    #include <BassConstants.au3>
    #include <BassFX.au3>
    ;#include <BassFXConstants.au3>

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

    Global $playing_state = -1
    _BASS_STARTUP ("H:\Programme\AutoIt3\Include\BASS.dll")
    _BASS_FX_Startup("H:\Programme\AutoIt3\Include\bass_fx.dll")
    _BASS_Init(0, -1, 44100, 0, "")

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

    $file = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")
    $MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, $BASS_STREAM_DECODE)
    $tempo = _BASS_FX_ReverseCreate ($MusicHandle, 10, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_FORWARD)

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

    ;Iniate playback
    _BASS_ChannelPlay($tempo, 1)

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

    ;Get the length of the song in bytes.
    $song_length = _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE)
    $timer = TimerInit ()
    $next = 30000; 30seconds into the song so we can try reduce the chance of going backwards....
    $state = 1

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

    While 1
    If TimerDiff ($timer) >= $next Then
    If $state = 1 Then
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_REVERSE)
    $next = Random (3000, 5000, 1)
    ToolTip ("Reverse for " & $next & "ms", 0,0)
    $state = 0
    Else
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_REVERSE_DIR, $BASS_FX_RVS_FORWARD)
    $next = Random (5000, 10000, 1)
    ToolTip ("Forward for " & $next & "ms", 0,0)
    $state = 1
    EndIf
    $timer = TimerInit ()
    Sleep (2000)
    EndIf
    Sleep(20)
    ;Get the current position in bytes
    $current = _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE)
    ;Calculate the percentage
    $percent = Round(($current / $song_length) * 100, 0)
    ;Display that to the user
    ToolTip("Completed " & $percent & "%", 0, 0)
    ;If the song is complete, then exit.
    If $current >= $song_length Then ExitLoop
    WEnd

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

    Func OnAutoItExit()
    ;Free Resources
    _BASS_Free()
    EndFunc ;==>OnAutoItExit
    #ce
    #cs

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

    #include <Bass.au3>
    #include <BassConstants.au3>
    #include <BassFX.au3>
    ;#include <BassFXConstants.au3>

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

    Global $playing_state = -1
    ;Startup Bass & BassFX. Also check if loading failed.
    _BASS_STARTUP ("H:\Programme\AutoIt3\Include\BASS.dll")
    If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist? Please check file exists.")
    Exit
    EndIf

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

    _BASS_FX_Startup("H:\Programme\AutoIt3\Include\bass_fx.dll")
    If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist? Please check file exists.")
    Exit
    EndIf

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

    ;Initalize bass. Required for most functions.
    _BASS_Init(0, -1, 44100, 0, "")

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

    ;Check if bass iniated. If not, we cannot continue.
    If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
    EndIf

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

    ;Prompt the user to select a MP3 file
    $file = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")

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

    ;Create a stream from that file.
    $MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, $BASS_STREAM_DECODE)

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

    ;Check if we opened the file correctly.
    If @error Then
    MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
    Exit
    EndIf
    $tempo = _BASS_FX_TempoCreate ($MusicHandle, 0)

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

    ;Iniate playback
    _BASS_ChannelPlay($tempo, 1)

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

    ;Get the length of the song in bytes.
    $song_length = _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE)

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

    ;Create a timer
    $timer = TimerInit ()
    ;So we can set it to something different each time.
    $numberchanges = 0
    While 1
    ;Test so we can change the tempo after 5 seconds.
    If TimerDiff ($timer) >= 5000 Then
    ;Make it a loop - reseting after we've cycled through the changes
    Switch $numberchanges
    Case 0 ; Tempo is 0% Set it to 75%
    ToolTip ("Setting Tempo to +75%", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, 75)
    Case 1; Tempo is 75% Set it to 100%
    ToolTip ("Setting Tempo to 100%", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, 100)
    Case 2; Tempo is 100% Set it to 50%
    ToolTip ("Setting Tempo to +50%", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, 50)
    Case 3; Tempo is 50% Set it to -50%
    ToolTip ("Setting Tempo to -50%", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, -50)
    Case 4; Tempo is -50% Set it to -75%
    ToolTip ("Setting Tempo to -75%", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO, -75)
    Case Else
    $numberchanges = 0
    EndSwitch
    $numberchanges += 1
    ;Reset the timer
    $timer = TimerInit ()
    Sleep (2000)
    EndIf
    Sleep(20)
    ;Get the current position in bytes
    $current = _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE)
    ;Calculate the percentage
    $percent = Round(($current / $song_length) * 100, 0)
    ;Display that to the user
    ToolTip("Completed " & $percent & "%", 0, 0)
    ;If the song is complete, then exit.
    If $current >= $song_length Then ExitLoop
    WEnd

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

    Func OnAutoItExit()
    ;Free Resources
    _BASS_Free()
    EndFunc ;==>OnAutoItExit
    #ce
    #cs
    #include <Bass.au3>
    #include <BassConstants.au3>
    #include <BassFX.au3>
    ;#include <BassFXConstants.au3>

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

    Global $playing_state = -1
    ;Startup Bass & BassFX. Also check if loading failed.
    _BASS_STARTUP ("H:\Programme\AutoIt3\Include\BASS.dll")
    If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist? Please check file exists.")
    Exit
    EndIf

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

    _BASS_FX_Startup("H:\Programme\AutoIt3\Include\bass_fx.dll")
    If @error = -1 Then
    MsgBox (0, "", "DLL Does not exist? Please check file exists.")
    Exit
    EndIf

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

    ;Initalize bass. Required for most functions.
    _BASS_Init(0, -1, 44100, 0, "")

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

    ;Check if bass iniated. If not, we cannot continue.
    If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
    EndIf

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

    ;Prompt the user to select a MP3 file
    $file = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")

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

    ;Create a stream from that file.
    $MusicHandle = _BASS_StreamCreateFile(False, $file, 0, 0, $BASS_STREAM_DECODE)

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

    ;Check if we opened the file correctly.
    If @error Then
    MsgBox(0, "Error", "Could not load audio file" & @CR & "Error = " & @error)
    Exit
    EndIf
    $tempo = _BASS_FX_TempoCreate ($MusicHandle, 0)

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

    ;Iniate playback
    _BASS_ChannelPlay($tempo, 1)

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

    ;Get the length of the song in bytes.
    $song_length = _BASS_ChannelGetLength($MusicHandle, $BASS_POS_BYTE)

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

    ;Create a timer
    $timer = TimerInit ()
    ;So we can set it to something different each time.
    $numberchanges = 0
    While 1
    ;Test so we can change the tempo after 5 seconds.
    If TimerDiff ($timer) >= 5000 Then
    ;Make it a loop - reseting after we've cycled through the changes
    Switch $numberchanges
    Case 0
    ToolTip ("Setting Tempo to +60", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, 60)
    Case 1
    ToolTip ("Setting Tempo to +30", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, 30)
    Case 2
    ToolTip ("Setting Tempo to +10", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, 10)
    Case 3
    ToolTip ("Setting Tempo to -30", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, -30)
    Case 4
    ToolTip ("Setting Tempo to -60", 0, 0)
    _BASS_ChannelSetAttribute ($tempo, $BASS_ATTRIB_TEMPO_PITCH, -60)
    Case Else
    $numberchanges = 0
    EndSwitch
    $numberchanges += 1
    ;Reset the timer
    $timer = TimerInit ()
    Sleep (2000)
    EndIf
    Sleep(20)
    ;Get the current position in bytes
    $current = _BASS_ChannelGetPosition($MusicHandle, $BASS_POS_BYTE)
    ;Calculate the percentage
    $percent = Round(($current / $song_length) * 100, 0)
    ;Display that to the user
    ToolTip("Completed " & $percent & "%", 0, 0)
    ;If the song is complete, then exit.
    If $current >= $song_length Then ExitLoop
    WEnd

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

    Func OnAutoItExit()
    ;Free Resources
    _BASS_Free()
    EndFunc ;==>OnAutoItExit
    #ce
    #cs
    #region waveform
    #AutoIt3Wrapper_UseX64=n
    #include "Bass.au3"
    #include "BassExt.au3"
    #include <GDIPlus.au3>
    $basspfad="H:\Programme\AutoIt3\Include"
    Opt("GUIOnEventMode", 1)

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

    $sFile = FileOpenDialog("Open...", "", "playable formats (*.MP3;*.MP2;*.MP1;*.OGG;*.WAV;*.AIFF;*.AIF)")
    ___Debug($sFile = "", $sFile)

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

    $hGui = GUICreate("WaveformDecode", 800, 250)
    GUISetOnEvent(-3, "_EXIT")
    GUISetState()

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

    _GDIPlus_Startup()
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    $hBmpBuffer = _GDIPlus_BitmapCreateFromGraphics(800, 250, $hGraphics)
    $hGfxBuffer = _GDIPlus_ImageGetGraphicsContext($hBmpBuffer)

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

    $hBmpBk = _GDIPlus_BitmapCreateFromGraphics(800, 250, $hGraphics)
    $hGfxBk = _GDIPlus_ImageGetGraphicsContext($hBmpBk)
    _GDIPlus_GraphicsSetSmoothingMode($hGfxBk, 2)

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

    $hPenL = _GDIPlus_PenCreate(0xFF00FF00, 1)
    $hPenR = _GDIPlus_PenCreate(0xFFFF0000, 1)
    $hBrushL = _GDIPlus_BrushCreateSolid(0xBB00BB00)
    $hBrushR = _GDIPlus_BrushCreateSolid(0xBBBB0000)
    $hPenPos = _GDIPlus_PenCreate(0xFF000099, 3)
    $hPenPos2 = _GDIPlus_PenCreate(0x99FFFF00, 1)

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

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

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

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

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

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

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

    $hStreamDecode = _BASS_StreamCreateFile(False, $sFile, 0, 0, $BASS_STREAM_DECODE)
    ___Debug(@error, "create stream from file")

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

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

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

    $iBytes = _BASS_ChannelGetLength($hStreamDecode, $BASS_POS_BYTE)
    $iLength = _BASS_ChannelBytes2Seconds($hStreamDecode, $iBytes)

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

    $iRes = 88; polygon segments per second

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

    $iWidth = $iLength * $iRes
    $aWave = _BASS_EXT_ChannelGetWaveformDecode($hStreamDecode, $iWidth, 200, 0, $iLength, $iRes, "_WaveformGetProc")

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

    _BASS_StreamFree($hStreamDecode)

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

    $hBmpWave = _BASS_EXT_GDIpBitmapCreateWaveform($hGraphics, $aWave, $hBrushL, $hPenL, $hBrushR, $hPenR, 0, 1)
    ToolTip("")

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

    _GDIPlus_GraphicsClear($hGfxBk, 0xFF000000)
    Switch $iWidth
    Case 0 To 30000
    _GDIPlus_GraphicsDrawImageRect($hGfxBk, $hBmpWave, 0, 200, 800, 50)
    Case Else
    For $i = 0 To $iWidth Step 30000
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBk, $hBmpWave, $i, 0, 30000, 200, Round($i * 800 / $iWidth), 200, Ceiling(30000 * 800 / $iWidth), 50)
    Next
    EndSwitch

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

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

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

    GUIRegisterMsg(0x000F, "WM_PAINT")
    GUIRegisterMsg(0x0014, "WM_ERASEBKGND")

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

    $iTimer = TimerInit()
    While _BASS_ChannelIsActive($hStreamPlay)
    If TimerDiff($iTimer) > 20 Then
    $iTimer = TimerInit()
    $iPosByte = _BASS_ChannelGetPosition($hStreamPlay, $BASS_POS_BYTE)
    $iPosSec = _BASS_ChannelBytes2Seconds($hStreamPlay, $iPosByte)
    $iOffset = Round($iPosSec * $iRes)
    _GDIPlus_GraphicsDrawImage($hGfxBuffer, $hBmpBk, 0, 0)
    _GDIPlus_GraphicsDrawLine($hGfxBuffer, 400, 2, 400, 198, $hPenPos)
    _GDIPlus_GraphicsDrawLine($hGfxBuffer, 800 * $iOffset / $iWidth, 202, 800 * $iOffset / $iWidth, 248, $hPenPos2)
    Select
    Case $iOffset < 400
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpWave, 0, 0, 800, $aWave[6] * 4, 400 - $iOffset, 0, 800, $aWave[6] * 4)
    Case $iOffset >= $iWidth - 800
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpWave, $iWidth - ($iWidth - $iOffset) - 400, 0, $iWidth - $iOffset + 400, $aWave[6] * 4, 0, 0, $iWidth - $iOffset + 400, $aWave[6] * 4)
    Case Else
    _GDIPlus_GraphicsDrawImageRectRect($hGfxBuffer, $hBmpWave, $iOffset - 400, 0, 800, $aWave[6] * 4, 0, 0, 800, $aWave[6] * 4)
    EndSelect
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    EndIf
    Sleep(10)
    WEnd

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

    _Exit()

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

    Func _WaveformGetProc($handle, $percent)
    ToolTip("Get Waveform: " & $percent & "%")
    EndFunc ;==>_WaveformGetProc

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

    Func _Exit()
    _BASS_ChannelStop($hStreamPlay)
    ___Debug(@error, "stop stream")

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

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

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

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

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

    GUIRegisterMsg(0x000F, "")
    GUIRegisterMsg(0x0014, "")
    _GDIPlus_PenDispose($hPenL)
    _GDIPlus_PenDispose($hPenR)
    _GDIPlus_BrushDispose($hBrushL)
    _GDIPlus_BrushDispose($hBrushR)
    _GDIPlus_PenDispose($hPenPos)
    _GDIPlus_PenDispose($hPenPos2)
    _GDIPlus_BitmapDispose($hBmpBk)
    _GDIPlus_GraphicsDispose($hGfxBk)
    _GDIPlus_BitmapDispose($hBmpWave)
    _GDIPlus_GraphicsDispose($hGfxBuffer)
    _GDIPlus_BitmapDispose($hBmpBuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Exit

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

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

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

    Func WM_ERASEBKGND($hWnd, $uMsgm, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBmpBuffer, 0, 0)
    Return True
    EndFunc ;==>WM_ERASEBKGND

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

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

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

    #endregion
    #ce

    [/autoit]