Jump to content

BASS.DLL Help


BrettF
 Share

Recommended Posts

Using a mix of Martins and ProgAndy's code, but it keeps crashing.

#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

Thanks for any help, I greatly appreciate it.

Cheers,

Brett

Edited by BrettF
Link to comment
Share on other sites

OKay so I've spent a good hour trying but still nothing is working. First time working with DllCallBack, so hopefully one of you gurus can see where my problem lies. What I would like to achieve is playing of a MP3 file located in a remote location or an internet radio using bass.dll.

Here is my code:

;Constants
; Sample Flages
Global Const $BASS_SAMPLE_FLOAT = 256     ; 32-bit floating-point
Global Const $BASS_SAMPLE_MONO = 2       ; mono
Global Const $BASS_SAMPLE_SOFTWARE = 16 ; not using hardware mixing
Global Const $BASS_SAMPLE_3D = 8        ; 3D functionality
Global Const $BASS_SAMPLE_LOOP = 4       ; looped
Global Const $BASS_SAMPLE_FX = 128       ; old implementation of DX8 effects
;Stream Flags
Global Const $BASS_STREAM_RESTRATE = 0x80000; restrict the download rate of internet file streams
Global Const $BASS_STREAM_BLOCK = 0x100000 ; download/play internet file stream in small blocks
Global Const $BASS_STREAM_STATUS = 0x800000; give server status info (HTTP/ICY tags) in DOWNLOADPROC
Global Const $BASS_STREAM_AUTOFREE = 0x40000; automatically free the stream when it stop/ends
Global Const $BASS_STREAM_DECODE = 0x200000; don;t play the stream, only decode ($BASS_ChannelGetData)
; Speaker assignment flags
Global Const $BASS_SPEAKER_FRONT = 0x1000000; front speakers
Global Const $BASS_SPEAKER_REAR = 0x2000000; rear/side speakers
Global Const $BASS_SPEAKER_CENLFE = 0x3000000; center & LFE speakers (5.1)
Global Const $BASS_SPEAKER_REAR2 = 0x4000000; rear center speakers (7.1)
Global Const $BASS_SPEAKER_LEFT = 0x10000000; modifier: left
Global Const $BASS_SPEAKER_RIGHT = 0x20000000; modifier: right
Global Const $BASS_SPEAKER_FRONTLEFT = $BASS_SPEAKER_FRONT Or $BASS_SPEAKER_LEFT
Global Const $BASS_SPEAKER_FRONTRIGHT = $BASS_SPEAKER_FRONT Or $BASS_SPEAKER_RIGHT
Global Const $BASS_SPEAKER_REARLEFT = $BASS_SPEAKER_REAR Or $BASS_SPEAKER_LEFT
Global Const $BASS_SPEAKER_REARRIGHT = $BASS_SPEAKER_REAR Or $BASS_SPEAKER_RIGHT
Global Const $BASS_SPEAKER_CENTER = $BASS_SPEAKER_CENLFE Or $BASS_SPEAKER_LEFT
Global Const $BASS_SPEAKER_LFE = $BASS_SPEAKER_CENLFE Or $BASS_SPEAKER_RIGHT
Global Const $BASS_SPEAKER_REAR2LEFT = $BASS_SPEAKER_REAR2 Or $BASS_SPEAKER_LEFT
Global Const $BASS_SPEAKER_REAR2RIGHT = $BASS_SPEAKER_REAR2 Or $BASS_SPEAKER_RIGHT

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

;Init Bass.DLL functions
$ret = DllCall($bassdll, "int", "BASS_Init", "int", -1, _
        "int", 44100, _
        "int", 0, _
        "hwnd", 0, _
        "ptr", 0)
If Not $ret[0] Then
;Oh dear couldn't start Bass.DLL or something
    MsgBox(0, "Error", 'Error initializing audio!');
    Exit
EndIf
;Set the URL
; I knows its off like a random site, I just needed an online MP3 to test with. -.^
; Plus its a good song! =P
$S_URL = "http://www.djchuckb.com/Rihanna_-_iTunes_-_01_-_Disturbia.mp3" 
$fName = DllStructCreate("char[255]")
DllStructSetData($fName, 1, $S_URL)
;=============================================================================
;   Everything Above here works, as tested before.... =]
;=============================================================================

;Structure for Callback function

;void CALLBACK DownloadProc(
;   void *buffer,
;   DWORD length,
;   void *user
;)

;Whats What
;   buffer
;       Pointer to the downloaded data... NULL = finished downloading. 
;   length
;       The number of bytes in the buffer... 0 = HTTP or ICY tags. 
;   user
;       The user instance data given when BASS_StreamCreateURL was called. 


$handle = DllCallbackRegister ("TestFunc", "ptr", "ptr;uint64;ptr")

;Structure for CreatingStream.

;HSTREAM BASS_StreamCreateURL(
;   char *url,
;   DWORD offset,
;   DWORD flags,
;   DOWNLOADPROC *proc,
;   void *user
;)

;WHats what....
;   url 
;       URL of the file to stream. Should begin with "http://" or "ftp://". 
;
;   offset
;       File position to start streaming from. This is ignored by some servers, specifically when the length is unknown/undefined.
;
;   flags Any combination of these flags.
;       BASS_SAMPLE_FLOAT
;            Use 32-bit floating-point sample data. See Floating-point channels for info.  
;       BASS_SAMPLE_MONO
;            Decode/play the stream (MP3/MP2/MP1 only) in mono, reducing the CPU usage (if it was originally stereo). This flag is automatically applied if BASS_DEVICE_MONO was specified when calling BASS_Init.  
;       BASS_SAMPLE_SOFTWARE
;            Force the stream to not use hardware mixing.  
;       BASS_SAMPLE_3D
;            Enable 3D functionality. This requires that the BASS_DEVICE_3D flag was specified when calling BASS_Init, and the stream must be mono. The SPEAKER flags can not be used together with this flag.  
;       BASS_SAMPLE_LOOP
;            Loop the file. This flag can be toggled at any time using BASS_ChannelFlags. This flag is ignored when streaming in blocks (BASS_STREAM_BLOCK).  
;       BASS_SAMPLE_FX
;           requires DirectX 8 or above Enable the old implementation of DirectX 8 effects. See the DX8 effect implementations section for details. Use BASS_ChannelSetFX to add effects to the stream.  
;       BASS_STREAM_RESTRATE
;            Restrict the download rate of the file to the rate required to sustain playback. If this flag is not used, then the file will be downloaded as quickly as the user's internet connection allows.  
;       BASS_STREAM_BLOCK
;            Download and play the file in smaller chunks, instead of downloading the entire file to memory. Uses a lot less memory than otherwise, but it's not possible to seek or loop the stream; once it's ended, the file must be opened again to play it again. This flag will automatically be applied when the file length is unknown, for example with Shout/Icecast streams. This flag also has the effect of restricting the download rate.  
;       BASS_STREAM_STATUS
;            Pass status info (HTTP/ICY tags) from the server to the DOWNLOADPROC callback during connection. This can be useful to determine the reason for a failure.  
;       BASS_STREAM_AUTOFREE
;            Automatically free the stream when playback ends.  
;       BASS_STREAM_DECODE
;            Decode the sample data, without playing it. Use BASS_ChannelGetData to retrieve decoded sample data. The BASS_SAMPLE_3D, BASS_STREAM_AUTOFREE and SPEAKER flags can not be used together with this flag. The BASS_SAMPLE_SOFTWARE and BASS_SAMPLE_FX flags are also ignored.  
;       BASS_SPEAKER_xxx
;            Speaker assignment flags. These flags have no effect when the stream is more than stereo.  
;
;   proc 
;       Callback function to receive the file as it is downloaded... NULL = no callback. 
;   user
;       User instance data to pass to the callback function. 

$stream = DllCall($bassdll, "int", "BASS_StreamCreateURL", "ptr", DllStructGetPtr($fName), "uint64", 0, "uint64", $BASS_SAMPLE_FLOAT, "ptr", DllCallbackGetPtr($handle), "ptr", 0)

;Check error with dllcall.
If Not @error Then
;set music handle
    $music_handle = $stream[0]
;reset filname
    $fName = 0
;play the channel
    $ret = DllCall($bassdll, "int", "BASS_ChannelPlay", "dword", $music_handle, "int", 0)
;check for error
    MsgBox (0, "", _BassGetLastError())
;wait a while.....
    Sleep(10000)
Else
;tell us errors
    MsgBox (0, "", @error)
    MsgBox (0, "", _BassGetLastError())
EndIf

DllCallbackFree($handle)

Func _BassGetLastError ()
;get the last error. 
; List of associated error codes.
;   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! 

    $ret = DllCall($bassdll, "int", "BASS_ErrorGetCode")
    Return $ret[0]
EndFunc

Func TestFunc($hWnd, $lParam)
    MsgBox (0,$hWnd, $lParam)
EndFunc

And here is 1 example for using the CallBack in the function in some other language :) (Stream an MP3 file, and save a local copy.)

FILE *file=NULL;
...
void CALLBACK downproc(void *buffer, DWORD length, void *user)
{
    if (!file) file=fopen("afile.mp3", "wb"); // create the file
    if (!buffer) fclose(file); // finished downloading
    else fwrite(buffer, 1, length, file);
}
...
HSTREAM stream=BASS_StreamCreateURL("http://www.asite.com/afile.mp3", 0, 0, &downproc, 0);

BASS_StreamCreateURL Example (Stream an MP3 file.)

HSTREAM stream=BASS_StreamCreateURL("http://www.asite.com/afile.mp3", 0, 0, NULL, 0);

Thanks for any help, I greatly appreciate it.

Cheers,

Brett

I made changes to your dllcallbackregister, dllcall lines (you had used "unint64" but should have used "dword"), and to the test function which needed an extra parameter. This must be getting very close.

;Constants
; Sample Flages
Global Const $BASS_SAMPLE_FLOAT = 256     ; 32-bit floating-point
Global Const $BASS_SAMPLE_MONO = 2       ; mono
Global Const $BASS_SAMPLE_SOFTWARE = 16 ; not using hardware mixing
Global Const $BASS_SAMPLE_3D = 8           ; 3D functionality
Global Const $BASS_SAMPLE_LOOP = 4       ; looped
Global Const $BASS_SAMPLE_FX = 128       ; old implementation of DX8 effects
;Stream Flags
Global Const $BASS_STREAM_RESTRATE = 0x80000; restrict the download rate of internet file streams
Global Const $BASS_STREAM_BLOCK = 0x100000 ; download/play internet file stream in small blocks
Global Const $BASS_STREAM_STATUS = 0x800000; give server status info (HTTP/ICY tags) in DOWNLOADPROC
Global Const $BASS_STREAM_AUTOFREE = 0x40000; automatically free the stream when it stop/ends
Global Const $BASS_STREAM_DECODE = 0x200000; don;t play the stream, only decode ($BASS_ChannelGetData)
; Speaker assignment flags
Global Const $BASS_SPEAKER_FRONT = 0x1000000; front speakers
Global Const $BASS_SPEAKER_REAR = 0x2000000; rear/side speakers
Global Const $BASS_SPEAKER_CENLFE = 0x3000000; center & LFE speakers (5.1)
Global Const $BASS_SPEAKER_REAR2 = 0x4000000; rear center speakers (7.1)
Global Const $BASS_SPEAKER_LEFT = 0x10000000; modifier: left
Global Const $BASS_SPEAKER_RIGHT = 0x20000000; modifier: right
Global Const $BASS_SPEAKER_FRONTLEFT = $BASS_SPEAKER_FRONT Or $BASS_SPEAKER_LEFT
Global Const $BASS_SPEAKER_FRONTRIGHT = $BASS_SPEAKER_FRONT Or $BASS_SPEAKER_RIGHT
Global Const $BASS_SPEAKER_REARLEFT = $BASS_SPEAKER_REAR Or $BASS_SPEAKER_LEFT
Global Const $BASS_SPEAKER_REARRIGHT = $BASS_SPEAKER_REAR Or $BASS_SPEAKER_RIGHT
Global Const $BASS_SPEAKER_CENTER = $BASS_SPEAKER_CENLFE Or $BASS_SPEAKER_LEFT
Global Const $BASS_SPEAKER_LFE = $BASS_SPEAKER_CENLFE Or $BASS_SPEAKER_RIGHT
Global Const $BASS_SPEAKER_REAR2LEFT = $BASS_SPEAKER_REAR2 Or $BASS_SPEAKER_LEFT
Global Const $BASS_SPEAKER_REAR2RIGHT = $BASS_SPEAKER_REAR2 Or $BASS_SPEAKER_RIGHT

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

;Init Bass.DLL functions
$ret = DllCall($bassdll, "int", "BASS_Init", "int", -1, _
        "int", 44100, _
        "int", 0, _
        "hwnd", 0, _
        "ptr", 0)
If Not $ret[0] Then
;Oh dear couldn't start Bass.DLL or something
    MsgBox(0, "Error", 'Error initializing audio!');
    Exit
EndIf
;Set the URL
; I knows its off like a random site, I just needed an online MP3 to test with. -.^
; Plus its a good song! =P
$S_URL = "http://www.djchuckb.com/Rihanna_-_iTunes_-_01_-_Disturbia.mp3"
$fName = DllStructCreate("char[255]")
DllStructSetData($fName, 1, $S_URL)
;=============================================================================
;   Everything Above here works, as tested before.... =]
;=============================================================================

;Structure for Callback function

;void CALLBACK DownloadProc(
;   void *buffer,
;   DWORD length,
;   void *user
;)

;Whats What
;   buffer
;       Pointer to the downloaded data... NULL = finished downloading.
;   length
;       The number of bytes in the buffer... 0 = HTTP or ICY tags.
;   user
;       The user instance data given when BASS_StreamCreateURL was called.


$handle = DllCallbackRegister ("TestFunc", "int", "ptr;dword;ptr")

;Structure for CreatingStream.

;HSTREAM BASS_StreamCreateURL(
;   char *url,
;   DWORD offset,
;   DWORD flags,
;   DOWNLOADPROC *proc,
;   void *user
;)

;WHats what....
;   url
;       URL of the file to stream. Should begin with "http://" or "ftp://".
;
;   offset
;       File position to start streaming from. This is ignored by some servers, specifically when the length is unknown/undefined.
;
;   flags Any combination of these flags.
;       BASS_SAMPLE_FLOAT
;            Use 32-bit floating-point sample data. See Floating-point channels for info.  
;       BASS_SAMPLE_MONO
;            Decode/play the stream (MP3/MP2/MP1 only) in mono, reducing the CPU usage (if it was originally stereo). This flag is automatically applied if BASS_DEVICE_MONO was specified when calling BASS_Init.  
;       BASS_SAMPLE_SOFTWARE
;            Force the stream to not use hardware mixing.  
;       BASS_SAMPLE_3D
;            Enable 3D functionality. This requires that the BASS_DEVICE_3D flag was specified when calling BASS_Init, and the stream must be mono. The SPEAKER flags can not be used together with this flag.  
;       BASS_SAMPLE_LOOP
;            Loop the file. This flag can be toggled at any time using BASS_ChannelFlags. This flag is ignored when streaming in blocks (BASS_STREAM_BLOCK).  
;       BASS_SAMPLE_FX
;           requires DirectX 8 or above Enable the old implementation of DirectX 8 effects. See the DX8 effect implementations section for details. Use BASS_ChannelSetFX to add effects to the stream.  
;       BASS_STREAM_RESTRATE
;            Restrict the download rate of the file to the rate required to sustain playback. If this flag is not used, then the file will be downloaded as quickly as the user's internet connection allows.  
;       BASS_STREAM_BLOCK
;            Download and play the file in smaller chunks, instead of downloading the entire file to memory. Uses a lot less memory than otherwise, but it's not possible to seek or loop the stream; once it's ended, the file must be opened again to play it again. This flag will automatically be applied when the file length is unknown, for example with Shout/Icecast streams. This flag also has the effect of restricting the download rate.  
;       BASS_STREAM_STATUS
;            Pass status info (HTTP/ICY tags) from the server to the DOWNLOADPROC callback during connection. This can be useful to determine the reason for a failure.  
;       BASS_STREAM_AUTOFREE
;            Automatically free the stream when playback ends.  
;       BASS_STREAM_DECODE
;            Decode the sample data, without playing it. Use BASS_ChannelGetData to retrieve decoded sample data. The BASS_SAMPLE_3D, BASS_STREAM_AUTOFREE and SPEAKER flags can not be used together with this flag. The BASS_SAMPLE_SOFTWARE and BASS_SAMPLE_FX flags are also ignored.  
;       BASS_SPEAKER_xxx
;            Speaker assignment flags. These flags have no effect when the stream is more than stereo.  
;
;   proc
;       Callback function to receive the file as it is downloaded... NULL = no callback.
;   user
;       User instance data to pass to the callback function.

;$stream = DllCall($bassdll, "int", "BASS_StreamCreateURL", "ptr", DllStructGetPtr($fName), "uint64", 0, "uint64", $BASS_SAMPLE_FLOAT, "ptr", DllCallbackGetPtr($handle), "ptr", 0)
ConsoleWrite("try dll" & @CRLF)
$stream = DllCall($bassdll, "int", "BASS_StreamCreateURL", "str",$S_URL, "dword", 0, "dword", $BASS_SAMPLE_FLOAT, "ptr",DllCallbackGetPtr($handle), "ptr", 0); DllCallbackGetPtr($handle)
ConsoleWrite("passed" & @CRLF)

;Check error with dllcall.
If Not @error Then
;set music handle
    $music_handle = $stream[0]
;reset filname
    $fName = 0
;play the channel
    $ret = DllCall($bassdll, "int", "BASS_ChannelPlay", "dword", $music_handle, "int", 0)
;check for error
    MsgBox (0, "", _BassGetLastError())
;wait a while.....
    Sleep(10000)
Else
;tell us errors
    MsgBox (0, "", @error)
    MsgBox (0, "", _BassGetLastError())
EndIf

DllCallbackFree($handle)

Func _BassGetLastError ()
;get the last error.
; List of associated error codes.
;   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!

    $ret = DllCall($bassdll, "int", "BASS_ErrorGetCode")
    Return $ret[0]
EndFunc

Func TestFunc($hWnd, $lParam,$cbuser)
  ; MsgBox (0,$hWnd, $lParam)
   ConsoleWrite(Hex($hwnd) & ', ' & Hex($lparam) & @CRLF)
    return 0
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Well, in theory, this is right, but AutoIt crashes after a few secinds, when doing anything in the callback function :) Or the stream just hangs because AutoIt is too slow... Write the CallBack in e.g. FreeBasci and all should work >_<

Edit: The uint64 is wrong this must always be DWORD ! Also, it would be better to use hwnd for the stream Handles.

CODE
;Constants

; Sample Flages

Global Const $BASS_SAMPLE_FLOAT = 256 ; 32-bit floating-point

Global Const $BASS_SAMPLE_MONO = 2 ; mono

Global Const $BASS_SAMPLE_SOFTWARE = 16 ; not using hardware mixing

Global Const $BASS_SAMPLE_3D = 8 ; 3D functionality

Global Const $BASS_SAMPLE_LOOP = 4 ; looped

Global Const $BASS_SAMPLE_FX = 128 ; old implementation of DX8 effects

;Stream Flags

Global Const $BASS_STREAM_RESTRATE = 0x80000; restrict the download rate of internet file streams

Global Const $BASS_STREAM_BLOCK = 0x100000 ; download/play internet file stream in small blocks

Global Const $BASS_STREAM_STATUS = 0x800000 ; give server status info (HTTP/ICY tags) in DOWNLOADPROC

Global Const $BASS_STREAM_AUTOFREE = 0x40000; automatically free the stream when it stop/ends

Global Const $BASS_STREAM_DECODE = 0x200000 ; don;t play the stream, only decode ($BASS_ChannelGetData)

; Speaker assignment flags

Global Const $BASS_SPEAKER_FRONT = 0x1000000; front speakers

Global Const $BASS_SPEAKER_REAR = 0x2000000 ; rear/side speakers

Global Const $BASS_SPEAKER_CENLFE = 0x3000000; center & LFE speakers (5.1)

Global Const $BASS_SPEAKER_REAR2 = 0x4000000; rear center speakers (7.1)

Global Const $BASS_SPEAKER_LEFT = 0x10000000; modifier: left

Global Const $BASS_SPEAKER_RIGHT = 0x20000000; modifier: right

Global Const $BASS_SPEAKER_FRONTLEFT = $BASS_SPEAKER_FRONT Or $BASS_SPEAKER_LEFT

Global Const $BASS_SPEAKER_FRONTRIGHT = $BASS_SPEAKER_FRONT Or $BASS_SPEAKER_RIGHT

Global Const $BASS_SPEAKER_REARLEFT = $BASS_SPEAKER_REAR Or $BASS_SPEAKER_LEFT

Global Const $BASS_SPEAKER_REARRIGHT = $BASS_SPEAKER_REAR Or $BASS_SPEAKER_RIGHT

Global Const $BASS_SPEAKER_CENTER = $BASS_SPEAKER_CENLFE Or $BASS_SPEAKER_LEFT

Global Const $BASS_SPEAKER_LFE = $BASS_SPEAKER_CENLFE Or $BASS_SPEAKER_RIGHT

Global Const $BASS_SPEAKER_REAR2LEFT = $BASS_SPEAKER_REAR2 Or $BASS_SPEAKER_LEFT

Global Const $BASS_SPEAKER_REAR2RIGHT = $BASS_SPEAKER_REAR2 Or $BASS_SPEAKER_RIGHT

DllCall("D:\Dokumente\Dateien von Andreas\AutoIt3\bass24\bass.dll","none","Test for DLL")

If @error = 1 Then Exit MsgBox(0, '', "No Bass.dll found")

;Open Bass.DLL

Global $bassdll = DllOpen("D:\Dokumente\Dateien von Andreas\AutoIt3\bass24\bass.dll")

Func OnAutoItExit()

If IsDeclared("music_handle") And IsDeclared("bassdll") Then

DllCall($bassdll, "int", "BASS_ChannelStop","hwnd",$music_handle)

DllCall($bassdll, "int", "BASS_StreamFree","hwnd",$music_handle)

EndIf

EndFunc

;Init Bass.DLL functions

$ret = DllCall($bassdll, "int", "BASS_Init", "int", -1, _

"int", 44100, _

"int", 0, _

"hwnd", 0, _

"ptr", 0)

If Not $ret[0] Then

;Oh dear couldn't start Bass.DLL or something

MsgBox(0, "Error", 'Error initializing audio!');

Exit

EndIf

;Set the URL

; I knows its off like a random site, I just needed an online MP3 to test with. -.^

; Plus its a good song! =P

$S_URL = "http://www.djchuckb.com/Rihanna_-_iTunes_-_01_-_Disturbia.mp3"

$fName = DllStructCreate("char[255]")

DllStructSetData($fName, 1, $S_URL)

$handle = DllCallbackRegister ("TestFunc", "ptr", "ptr;dword;ptr")

;Structure for CreatingStream.

Global $FILEHANDLE

Global $STREAMISDOWNLOADING=0

$stream = DllCall($bassdll, "hwnd", "BASS_StreamCreateURL", "ptr", DllStructGetPtr($fName), "dword", 0, "dword", $BASS_SAMPLE_FLOAT, "ptr", DllCallbackGetPtr($handle), "ptr", 0)

;Check error with dllcall.

If Not @error Then

;set music handle

$music_handle = $stream[0]

;reset filname

$fName = 0

;play the channel

$ret = DllCall($bassdll, "int", "BASS_ChannelPlay", "hwnd", $music_handle, "int", 0)

;check for error

MsgBox (0, "", _BassGetLastError())

;wait a while.....

While $STREAMISDOWNLOADING

Sleep(100)

WEnd

While 1

$ret = DllCall($bassdll, "int", "BASS_ChannelIsActive","hwnd",$music_handle)

If $ret[0] = 0 Then

Sleep(200)

$ret = DllCall($bassdll, "int", "BASS_ChannelUpdate","hwnd",$music_handle,"int",0)

If $ret[0] = 45 Then ExitLoop

EndIf

Sleep(200)

WEnd

DllCall($bassdll, "int", "BASS_StreamFree","hwnd",$music_handle)

Else

;tell us errors

MsgBox (0, "", @error)

MsgBox (0, "", _BassGetLastError())

EndIf

;~ DllCallbackFree($handle)

Func _BassGetLastError ()

;get the last error.

; List of associated error codes.

; 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!

$ret = DllCall($bassdll, "int", "BASS_ErrorGetCode")

Return $ret[0]

EndFunc

Func TestFunc($buffer, $length, $user)

;~ MsgBox (0,$buffer, $length & @CRLF & $user)

;~ ConsoleWrite($buffer&@CRLF& $length & @CRLF & $user & @CRLF)

$STREAMISDOWNLOADING = 1

;~ If Not $FILEHANDLE Then $FILEHANDLE = FileOpen(@DesktopDir & "\test.mp3",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

EndFunc

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 1 month later...

Hey All,

Bumping this topic, as it has started to crash, mostly after around 20 seconds max.

Any ideas?

Cheers,

Brett

EDIT:

Current code is in the first post. You will need BASS.au3 which is in my signature... Well it will be in a moment... :mellow:

Edited by BrettF
Link to comment
Share on other sites

I think, the AutoIt-Interpreter is too slow for the callbacks of BASS.dll... Propably BASS has to wait too long and then crashes because the resources arent used correctly :mellow:

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 2 months later...

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...