Jump to content

BASS Function Library (Sound and Music Functions)


BrettF
 Share

Recommended Posts

i have problems with _BASS_StreamCreateURL

>"C:\Programme\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Dokumente und Einstellungen\Sven\Desktop\client\examples\Example 1.au3"   
C:\Dokumente und Einstellungen\Sven\Desktop\client\Bass.au3 (2362) : ==> Badly formatted "Func" statement.:
$dcProc = DllCallbackRegister ($proc, "ptr", "char[255];dword;char[255];")
Link to comment
Share on other sites

i have problems with _BASS_StreamCreateURL

>"C:\Programme\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Dokumente und Einstellungen\Sven\Desktop\client\examples\Example 1.au3"   
C:\Dokumente und Einstellungen\Sven\Desktop\client\Bass.au3 (2362) : ==> Badly formatted "Func" statement.:
$dcProc = DllCallbackRegister ($proc, "ptr", "char[255];dword;char[255];")
Post your full code. I have been running into some problems with the streams...

Ok this is cool!!...

but.. It when I click pause then it never plays again.. So I can't use it in my player :mellow:

Which example??
Link to comment
Share on other sites

i have problems with _BASS_StreamCreateURL

>"C:\Programme\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Dokumente und Einstellungen\Sven\Desktop\client\examples\Example 1.au3"   
C:\Dokumente und Einstellungen\Sven\Desktop\client\Bass.au3 (2362) : ==> Badly formatted "Func" statement.:
$dcProc = DllCallbackRegister ($proc, "ptr", "char[255];dword;char[255];")
im noob in AutoIt but i solved it myself. i only forgot $proc, it works now

but i found another error

Line 2362 in Bass.au3

$dcProc = DllCallbackRegister ($proc, "ptr", "char[255];dword;char[255];")

AutoItExe will crash

But after i changed that line to

$dcProc = DllCallbackRegister ($proc, "ptr", "ptr;dword;ptr")

it works.

Link to comment
Share on other sites

but i have new problem with _BASS_StreamCreateURL after a while it crashes with no error, how can i solve this?

#include <..\Bass.au3>
#include <..\BassConstants.au3>
;~ ProcessSetPriority(@AutoItExe, 4)
Global $playing_state = -1
;Open Bass.DLL.  Required for all function calls.
Dim $bass_dll = DllOpen("..\BASS.dll")


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

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

;Prompt the user to select a MP3 file
;~ $file = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")
$file = "http://91.121.175.145:80"
;Create a stream from that file.
Dim $MusicHandle = _BASS_StreamCreateURL($bass_dll, $file,0,0,"TestFunc",0)

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

;Iniate playback
_BASS_ChannelPlay($bass_dll, $MusicHandle, 1)
;Get the length of the song in bytes.
;~ $song_length = _BASS_ChannelGetLength($bass_dll, $MusicHandle, $BASS_POS_BYTE)
While 1
    Sleep(20)
;~ ;Get the current position in bytes
;~  $current = _BASS_ChannelGetPosition($bass_dll, $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
ConsoleWrite(@CRLF & _BASS_ErrorGetCode($bass_dll))

Func OnAutoItExit()
;Free Resources
    _BASS_Free($bass_dll)
EndFunc  ;==>OnAutoItExit

Func TestFunc($buffer, $length, $user)
EndFunc
Link to comment
Share on other sites

#include <Bass.au3>
#include <BassConstants.au3>

;Open Bass.DLL
$bass_dll = DllOpen("bass.dll")

;Init Bass.DLL functions
_BASS_Init ($bass_dll, 0, -1, 44100, 0, "")

If @error Then
    MsgBox(0, "Error", 'Error initializing audio!' & @LF & "@ERROR = " & @error);
    Exit
EndIf

$URL = "http://www.djchuckb.com/Rihanna_-_iTunes_-_01_-_Disturbia.mp3"
$music_handle = _BASS_StreamCreateURL($bass_dll, $url, 0, $BASS_SAMPLE_FLOAT, "TestFunc")
$error_e = @error
;Check error with dllcall.
If Not @error Then
    _BASS_ChannelPlay ($bass_dll, $music_handle, 1)
    Sleep(10000)
Else
    GetRadioError ($error_e)
EndIf

Func GetRadioError ($ecode)
;   0 = everything is A-OKAY
;   8 = BASS_ERROR_INIT BASS_Init has not been successfully called.
;   37 = BASS_ERROR_NOTAVAIL Only decoding channels (BASS_STREAM_DECODE) are allowed when using the "no sound" device. The BASS_STREAM_AUTOFREE flag is also unavailable to decoding channels.
;   32 = BASS_ERROR_NONET No internet connection could be opened. Can be caused by a bad proxy setting.
;   20 = BASS_ERROR_ILLPARAM url is not a valid URL.
;   40 = BASS_ERROR_TIMEOUT The server did not respond to the request within the timeout period, as set with the BASS_CONFIG_NET_TIMEOUT config option.
;   2 = BASS_ERROR_FILEOPEN The file could not be opened.
;   41 = BASS_ERROR_FILEFORM The file's format is not recognised/supported.
;   44 = BASS_ERROR_CODEC The file uses a codec that's not available/supported. This can apply to WAV and AIFF files, and also MP3 files when using the "MP3-free" BASS version.
;   6 = BASS_ERROR_FORMAT The sample format is not supported by the device/drivers. If the stream is more than stereo or the BASS_SAMPLE_FLOAT flag is used, it could be that they are not supported.
;   42 = BASS_ERROR_SPEAKER The specified SPEAKER flags are invalid. The device/drivers do not support them, they are attempting to assign a stereo stream to a mono speaker or 3D functionality is enabled.
;   1 = BASS_ERROR_MEM There is insufficient memory.
;   21 = BASS_ERROR_NO3D Could not initialize 3D support.
;   -1 = BASS_ERROR_UNKNOWN Some other mystery problem!
$emsg = ""
Switch $ecode
    Case 0
        $emsg = "everything is A-OKAY"
    Case 8
        $emsg = "BASS_ERROR_INIT BASS_Init has not been successfully called."
    Case 37
        $emsg = "BASS_ERROR_NOTAVAIL Only decoding channels (BASS_STREAM_DECODE) are allowed when using the " & _
        "'no sound' device. The BASS_STREAM_AUTOFREE flag is also unavailable to decoding channels."
    Case 32
        $emsg = "BASS_ERROR_NONET No internet connection could be opened. Can be caused by a bad proxy setting."
    Case 20
        $emsg = "BASS_ERROR_ILLPARAM url is not a valid URL."
    Case 40
        $emsg = "BASS_ERROR_TIMEOUT The server did not respond to the request within the timeout period, as set with the BASS_CONFIG_NET_TIMEOUT config option."
    Case 2
        $emsg = "BASS_ERROR_FILEOPEN The file could not be opened."
    Case 41
        $emsg = "BASS_ERROR_FILEFORM The file's format is not recognised/supported."
    Case 44
        $emsg = "BASS_ERROR_CODEC The file uses a codec that's not available/supported. This can apply" & _
        "to WAV and AIFF files, and also MP3 files when using the 'MP3-free' BASS version."
    Case 6
        $emsg = "BASS_ERROR_FORMAT The sample format is not supported by the device/drivers. " & _
        "If the stream is more than stereo or the BASS_SAMPLE_FLOAT flag is used, it could be that they are not supported."
    Case 42
        $emsg = "BASS_ERROR_SPEAKER The specified SPEAKER flags are invalid. The device/drivers do not support them, they are" & _
        "attempting to assign a stereo stream to a mono speaker or 3D functionality is enabled."
    Case 1
        $emsg = "BASS_ERROR_MEM There is insufficient memory."
    Case 21
        $emsg = "BASS_ERROR_NO3D Could not initialize 3D support."
    Case -1
        $emsg = "BASS_ERROR_UNKNOWN Some other mystery problem!"
EndSwitch
MsgBox (0, "Error Message", $emsg)
EndFunc

Func TestFunc($hWnd, $lParam,$cbuser)
 ; MsgBox (0,$hWnd, $lParam)
   ConsoleWrite(Hex($hwnd) & ', ' & Hex($lparam) & @CRLF)
    return 0
EndFunc

Hope that works for you. As I'm at school I'm unable to test. Thanks go to Martin for getting it working in this thread.

Link to comment
Share on other sites

Forgot a few bits. Mixed martins and ProgAndy's examples to get this....

#include <Bass.au3>
#include <BassConstants.au3>

;Open Bass.DLL
$bass_dll = DllOpen("bass.dll")

Global $S_DOWNLOAD = False; Download = True, Just Play = False
Global $o_file = @DesktopDir & "\download.mp3"; Download Location
Global $FILEHANDLE
Global $STREAMISDOWNLOADING = 0

;Open Bass.DLL
$bass_dll = DllOpen("bass.dll")

;Init Bass.DLL functions
_BASS_Init($bass_dll, 0, -1, 44100, 0, "")

If @error Then
    MsgBox(0, "Error", 'Error initializing audio!' & @LF & "@ERROR = " & @error);
    Exit
EndIf

$URL = "http://www.djchuckb.com/Rihanna_-_iTunes_-_01_-_Disturbia.mp3"
$music_handle = _BASS_StreamCreateURL($bass_dll, $URL, 0, $BASS_SAMPLE_FLOAT, "TestFunc")
$error_e = @error

;Check error with dllcall.
If Not @error Then
    _BASS_ChannelPlay($bass_dll, $music_handle, 1)
    While $STREAMISDOWNLOADING
        Sleep(100)
    WEnd
    While 1
        $state =  _BASS_ChannelIsActive($bass_dll, $music_handle)
        If $state = 0 Then
            Sleep(200)
            $ret = _BASS_ChannelUpdate($bass_dll, $music_handle, 0)
            If $ret = 0 Then ExitLoop
        EndIf
        Sleep(200)
    WEnd
Else
    GetRadioError($error_e)
EndIf

Func GetRadioError($ecode)
    $emsg = ""
    Switch $ecode
        Case 0
            $emsg = "everything is A-OKAY"
        Case 8
            $emsg = "BASS_ERROR_INIT BASS_Init has not been successfully called."
        Case 37
            $emsg = "BASS_ERROR_NOTAVAIL Only decoding channels (BASS_STREAM_DECODE) are allowed when using the " & _
                    "'no sound' device. The BASS_STREAM_AUTOFREE flag is also unavailable to decoding channels."
        Case 32
            $emsg = "BASS_ERROR_NONET No internet connection could be opened. Can be caused by a bad proxy setting."
        Case 20
            $emsg = "BASS_ERROR_ILLPARAM url is not a valid URL."
        Case 40
            $emsg = "BASS_ERROR_TIMEOUT The server did not respond to the request within the timeout period, as set with the BASS_CONFIG_NET_TIMEOUT config option."
        Case 2
            $emsg = "BASS_ERROR_FILEOPEN The file could not be opened."
        Case 41
            $emsg = "BASS_ERROR_FILEFORM The file's format is not recognised/supported."
        Case 44
            $emsg = "BASS_ERROR_CODEC The file uses a codec that's not available/supported. This can apply" & _
                    "to WAV and AIFF files, and also MP3 files when using the 'MP3-free' BASS version."
        Case 6
            $emsg = "BASS_ERROR_FORMAT The sample format is not supported by the device/drivers. " & _
                    "If the stream is more than stereo or the BASS_SAMPLE_FLOAT flag is used, it could be that they are not supported."
        Case 42
            $emsg = "BASS_ERROR_SPEAKER The specified SPEAKER flags are invalid. The device/drivers do not support them, they are" & _
                    "attempting to assign a stereo stream to a mono speaker or 3D functionality is enabled."
        Case 1
            $emsg = "BASS_ERROR_MEM There is insufficient memory."
        Case 21
            $emsg = "BASS_ERROR_NO3D Could not initialize 3D support."
        Case - 1
            $emsg = "BASS_ERROR_UNKNOWN Some other mystery problem!"
    EndSwitch
    MsgBox(0, "Error Message", $emsg)
EndFunc  ;==>GetRadioError

Func TestFunc($buffer, $length, $user)
    If Not $S_DOWNLOAD Then
        $STREAMISDOWNLOADING = 1
        If Not $buffer Then
            $STREAMISDOWNLOADING = 0
        EndIf
    Else
        $STREAMISDOWNLOADING = 1
        If Not $FILEHANDLE Then $FILEHANDLE = FileOpen($o_file, 18)
        If Not $buffer Then
            $STREAMISDOWNLOADING = 0
            FileClose($FILEHANDLE)
            $FILEHANDLE = 0
        Else
            DllStructCreate("byte[" & $length & "]", $buffer)
            FileWrite($FILEHANDLE, DllStructGetData(DllStructCreate("byte[" & $length & "]", $buffer), 1))
        EndIf
    EndIf
EndFunc  ;==>TestFunc

Func OnAutoItExit ()
    _Bass_StreamFree ($bass_dll, $music_handle)
    _Bass_Free($bass_dll)
EndFunc
Link to comment
Share on other sites

Forgot a few bits. Mixed martins and ProgAndy's examples to get this....

#include <Bass.au3>
#include <BassConstants.au3>

;Open Bass.DLL
$bass_dll = DllOpen("bass.dll")

Global $S_DOWNLOAD = False; Download = True, Just Play = False
Global $o_file = @DesktopDir & "\download.mp3"; Download Location
Global $FILEHANDLE
Global $STREAMISDOWNLOADING = 0

;Open Bass.DLL
$bass_dll = DllOpen("bass.dll")

;Init Bass.DLL functions
_BASS_Init($bass_dll, 0, -1, 44100, 0, "")

If @error Then
    MsgBox(0, "Error", 'Error initializing audio!' & @LF & "@ERROR = " & @error);
    Exit
EndIf

$URL = "http://www.djchuckb.com/Rihanna_-_iTunes_-_01_-_Disturbia.mp3"
$music_handle = _BASS_StreamCreateURL($bass_dll, $URL, 0, $BASS_SAMPLE_FLOAT, "TestFunc")
$error_e = @error
Errors for me too.

I get the whole, autoit3.exe has encountered a problem and needs to close. Happens at the $music_handle = _BASS_StreamCreateURL($bass_dll, $URL, 0, $BASS_SAMPLE_FLOAT, "TestFunc") line.

Errors out with; AutoIT3.exe ended.rc:-1073741819

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

same ... after a while music hangs a few seconds and then autoIt exe exit with no error

Edit:

Errors for me too.

I get the whole, autoit3.exe has encountered a problem and needs to close. Happens at the $music_handle = _BASS_StreamCreateURL($bass_dll, $URL, 0, $BASS_SAMPLE_FLOAT, "TestFunc") line.

Errors out with; AutoIT3.exe ended.rc:-1073741819

jou have to add
Func TestFunc()
EndFunc

Edit2:

and you have to change Line 2362 in Bass.au3

$dcProc = DllCallbackRegister ($proc, "ptr", "char[255];dword;char[255];")

to

$dcProc = DllCallbackRegister ($proc, "ptr", "ptr;dword;ptr")
Edited by Hofi
Link to comment
Share on other sites

i played a little bit with this, i found how to use it stable for some hours (or more, i have to test this ...)

This script is optimal to use _BASS_StreamCreateURL, i had no crash for 1 hour now

if it crash i will post here

here is script that working perfectly for me:

#include <Bass.au3>
#include <BassConstants.au3>
;~ ProcessSetPriority(@AutoItExe, 4)

;Open Bass.DLL.  Required for all function calls.
Dim $bass_dll = DllOpen("BASS.dll")


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

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

;Set the Stream URL to listen to
$file = "http://91.121.175.145:80"

;Create a stream from that URL.
Dim $MusicHandle = _BASS_StreamCreateURL($bass_dll, $file,0,0,"TestFunc",0)

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

;Iniate playback
_BASS_ChannelPlay($bass_dll, $MusicHandle, 1)

;endless loop
While 1
;------------------------------------------------------------------------------------------
    Sleep(10);adjusting this to reduce AutoItExe crashs, 10 is optimal on my pc, i think 
;------------------------------------------------------------------------------------------
WEnd


;Functions

Func OnAutoItExit()
;Free Resources
    MsgBox(0,"Exit",'"OnAutoItExit()" was called' & @CRLF & "Error Code: " & _BASS_ErrorGetCode($bass_dll))
    _BASS_Free($bass_dll)
EndFunc;==>OnAutoItExit


Func TestFunc($buffer, $length, $user)
;---------------------------------------------------------------------------
;!!! DO NOT PUT/CHANGE/REMOVE ANYTHING IN HERE OR IT WILL BE UNSTABLE !!!!
;---------------------------------------------------------------------------
EndFunc

EDIT: after 75 min it crashed

OnAutoItExit was called, but the music was still playing until i hit ok button on the message box. I think its an bug in AutoIT

Edited by Hofi
Link to comment
Share on other sites

I can't believe (I can, really) you'd waste of our time with this. How would this be a bug in AutoIt? Did you think about it or was it too convenient to have a knee-jerk reaction that it must be AutoIt's fault? Where's this bass.dll from? Did you read the documentation on it to make sure you're using the library right? The fact that AutoIt itself is doing nothing in your test script when the crash happens should be your first clue that AutoIt's probably not at fault here.

Here's a quick guess. It looks like a DllCallback is being used (I haven't looked at the code beyond the test script). If that's so, is the right calling convention being used? Is the callback supposed to respond to anything by returning a certain value?

Link to comment
Share on other sites

i played a little bit with this, i found how to use it stable for some hours (or more, i have to test this ...)

This script is optimal to use _BASS_StreamCreateURL, i had no crash for 1 hour now

if it crash i will post here

here is script that working perfectly for me:

#include <Bass.au3>
#include <BassConstants.au3>
;~ ProcessSetPriority(@AutoItExe, 4)

;Open Bass.DLL.  Required for all function calls.
Dim $bass_dll = DllOpen("BASS.dll")


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

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

;Set the Stream URL to listen to
$file = "http://91.121.175.145:80"

;Create a stream from that URL.
Dim $MusicHandle = _BASS_StreamCreateURL($bass_dll, $file,0,0,"TestFunc",0)

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

;Iniate playback
_BASS_ChannelPlay($bass_dll, $MusicHandle, 1)

;endless loop
While 1
;------------------------------------------------------------------------------------------
    Sleep(10);adjusting this to reduce AutoItExe crashs, 10 is optimal on my pc, i think 
;------------------------------------------------------------------------------------------
WEnd


;Functions

Func OnAutoItExit()
;Free Resources
    MsgBox(0,"Exit",'"OnAutoItExit()" was called' & @CRLF & "Error Code: " & _BASS_ErrorGetCode($bass_dll))
    _BASS_Free($bass_dll)
EndFunc;==>OnAutoItExit


Func TestFunc($buffer, $length, $user)
;---------------------------------------------------------------------------
;!!! DO NOT PUT/CHANGE/REMOVE ANYTHING IN HERE OR IT WILL BE UNSTABLE !!!!
;---------------------------------------------------------------------------
EndFunc

EDIT: after 75 min it crashed

OnAutoItExit was called, but the music was still playing until i hit ok button on the message box. I think its an bug in AutoIT

You have to use the correct While Loops. See my example.

I agree with Valik... :(

EDIT: Oh and I updated it to the latest version... :mellow:

Edited by BrettF
Link to comment
Share on other sites

I see now,

I will have a look at the example, and see what I can come up with :mellow:

Cheers,

Brett

EDIT: Wowah!

Still crashing like a blind man driving a car.... :(

No matter what I try, it's not doing much difference... :)

But I have to do assignments now, so don't expect anything for a while ;)

Edited by BrettF
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...