Jump to content

Getting playback position with bass.dll


Recommended Posts

Hi guys!

I'm going insane over this problem, I'm working with the bass audio library and I need to get the current playback position.

Here's the two bass functions I use:

(Taken from bass.chm)

QWORD BASS_ChannelGetPosition(
     DWORD   handle,
     DWORD mode
 );
 
double BASS_ChannelBytes2Seconds(
     DWORD handle,
     QWORD   pos
 );

And here's my current code:

Global $bass
 
 
 Bass_Start()
 
 $stream = Bass_StreamCreateFile("roll.mp3")
 Bass_ChannelPlay($stream)
 Do
     ConsoleWrite(Bass_ChannelBytes2Seconds($stream, Bass_ChannelGetPosition($stream, 0)) & @CRLF)
 Until Not Sleep(100)
 
 
 
 Func Bass_ChannelPlay($stream)
     $call = DllCall($bass, "int", "BASS_ChannelPlay", "dword", $stream, "int", 1);
 EndFunc;==>Bass_ChannelPlay
 
 Func Bass_ChannelGetPosition($channel, $mode = 0)
     $call = DllCall($bass, "uint64", "BASS_ChannelGetPosition", "dword", $channel, "dword", $mode)
     Return $call[0]
 EndFunc;==>Bass_ChannelGetPosition
 
 Func Bass_ChannelBytes2Seconds($channel, $bytes)
     $call = DllCall($bass, "double", "BASS_ChannelBytes2Seconds", "dword", $channel, "uint64", $bytes)
     Return $call[0]
 EndFunc;==>Bass_ChannelBytes2Seconds
 
 
 Func Bass_StreamCreateFile($fname)
     $str = DllStructCreate("char[255];")
     DllStructSetData($str, 1, $fname)
     $call = DllCall($bass, "int", "BASS_StreamCreateFile", "int", 0, "ptr", DllStructGetPtr($str), "uint64", 0, "uint64", 0, "dword", 0);
     Return $call[0]
 EndFunc;==>Bass_StreamCreateFile
 
 Func Bass_Start()
     $bass = DllOpen("bass.dll")
     $call = DllCall($bass, "int", "BASS_Init", "int", -1, "dword", 44100, "dword", 0, "hwnd", 0, "ptr", 0)
 EndFunc;==>Bass_Start

I've attached bass.dll as well:

bass.dll

Any help is appreciated! :P

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Maybe they are lying.

Global $bass, $pos 


Bass_Start()

$stream = Bass_StreamCreateFile("roll.mp3")
Bass_ChannelPlay($stream)

While 1 
    
    $pos = Bass_ChannelGetPosition($stream, 0)
    Sleep(10)   
    If Bass_ChannelGetPosition($stream, 0) = $pos Then ExitLoop 
    ConsoleWrite(Bass_ChannelBytes2Seconds($stream, $pos) & " sec" & @CRLF) 
    
WEnd

#cs
    QWORD BASS_ChannelGetPosition(
    DWORD   handle,
    DWORD mode
    );
    
    double BASS_ChannelBytes2Seconds(
    DWORD handle,
    QWORD   pos
    );
#ce

Func Bass_ChannelPlay($stream)
    $call = DllCall($bass, "int", "BASS_ChannelPlay", "dword", $stream, "int", 1);
EndFunc   ;==>Bass_ChannelPlay

Func Bass_ChannelGetPosition($channel, $mode = 0)
    $call = DllCall($bass, "udword", "BASS_ChannelGetPosition", "dword", $channel, "dword", $mode)
    Return $call[0]
EndFunc   ;==>Bass_ChannelGetPosition

Func Bass_ChannelBytes2Seconds($channel, $bytes)
    $call = DllCall($bass, "double", "BASS_ChannelBytes2Seconds", "dword", $channel, "uint64", $bytes)
    Return $call[0]
EndFunc   ;==>Bass_ChannelBytes2Seconds


Func Bass_StreamCreateFile($fname)
    $str = DllStructCreate("char[255];")
    DllStructSetData($str, 1, $fname)
    $call = DllCall($bass, "int", "BASS_StreamCreateFile", "int", 0, "ptr", DllStructGetPtr($str), "uint64", 0, "uint64", 0, "dword", 0);
    Return $call[0]
EndFunc   ;==>Bass_StreamCreateFile

Func Bass_Start()
    $bass = DllOpen("bass.dll")
    $call = DllCall($bass, "int", "BASS_Init", "int", -1, "dword", 44100, "dword", 0, "hwnd", 0, "ptr", 0)
EndFunc   ;==>Bass_Start

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I was just going to start with BASS_ChannelGetPosition myself, but thank you both for saving me some time! :P

Edited by AdmiralAlkex
Link to comment
Share on other sites

No, I'm actually building an audio player, I thought I be the first to do an audio player in autoit :P:(:idea:

Hahahahha well answer this for me, whats this struct in AutoIt? Crashes for me :P

typedef struct {
    char *name;
    char *driver;
    DWORD flags;
} BASS_DEVICEINFO;

:)

Link to comment
Share on other sites

Hahahahha well answer this for me, whats this struct in AutoIt? Crashes for me :(

typedef struct {
     char *name;
     char *driver;
     DWORD flags;
 } BASS_DEVICEINFO;

:P

Like this:

$struct=DllStructCreate("ptr name;ptr driver;dword flags;")

And to save a string in name you create a char[] in another struct and saves the pointer to the char[] struct in ptr name.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Hi! i found a wrong datatype in Bass_ChannelGetPosition

TH retrun type should be "uint64", not "udword"

( QWORD in definition -> uint64 in AutoIt )

*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

Like this:

$struct=DllStructCreate("ptr name;ptr driver;dword flags;")

And to save a string in name you create a char[] in another struct and saves the pointer to the char[] struct in ptr name.

Lost me with the last bit mate. So something like

$str = DllStructCreate("ptr name;ptr driver;dword flags;")

Dllcall(...)

$ret2 = DllStructCreate("char[]", DllStructGetPtr($str))

$ret = DllStructGetData($ret2, 1)

MsgBox (0, "", $ret[0])

??

I'm so confused. Heh least im learning :P

Link to comment
Share on other sites

Struct with String-Pointer:

Global Const $tagBASS_DEVICEINFO = "ptr name;ptr driver;dword flags;" ; char* char* dword

$BASS_DEVICEINFO = DllStructCreate($tagBASS_DEVICEINFO)
$NameStruct = _CreateTextStruct("the Name")
DllStructSetData($BASS_DEVICEINFO,"name",DllStructGetPtr($NameStruct))

; Prog@ndy
Func _CreateTextStruct($text)
    Local $s = DllStructCreate("char[" & StringLen($text)+1 & "]")
    DllStructSetData($s,1,$text)
    Return $s
EndFunc

*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

Hi! i found a wrong datatype in Bass_ChannelGetPosition

TH retrun type should be "uint64", not "udword"

( QWORD in definition -> uint64 in AutoIt )

Yeah, that's what I thought (see my first source), but it doesn't work unless you specify udword :P

Lost me with the last bit mate. So something like

$str = DllStructCreate("ptr name;ptr driver;dword flags;")

Dllcall(...)

$ret2 = DllStructCreate("char[]", DllStructGetPtr($str))

$ret = DllStructGetData($ret2, 1)

MsgBox (0, "", $ret[0])

??

I'm so confused. Heh least im learning :idea:

Here's how I mean :(

$struct=DllStructCreate("ptr name;ptr driver;dword flags;")

$strstruct=DllStructCreate("char str[255];"); In C strings are stored in array of chars

DllStructSetData($strstruct,"Andreas"); Save a string in the array

DllStructSetData($struct,"name",DllStructGetPtr($strstruct)); Save the pointer to the array in first struct

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Oops didn't see it :P sorry

*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

Thanks. Starting Make sense now!

How does this look?

Func _BASS_GetDeviceInfo($bass_dll, $device)
    Local $aRet[3]
    Local $Retstruct = DllStructCreate("ptr name;ptr driver;dword flags;")
    Local $Retstrstruct1 = DllStructCreate("char str[255];"); In C strings are stored in array of chars
    Local $Retstrstruct2 = DllStructCreate("char str[255];"); In C strings are stored in array of chars
    DllStructSetData($Retstruct, "name", DllStructGetPtr($Retstrstruct1)); Save the pointer to the array in first struct
    DllStructSetData($Retstruct, "driver", DllStructGetPtr($Retstrstruct2)); Save the pointer to the array in first struct
    
    $ret = DllCall($bass_dll, "int", "BASS_GetDeviceInfo", "dword", $device, "ptr", DllStructGetPtr($Retstruct))
    
    $error = _BASS_ErrorGetCode($bass_dll)
    If $error <> 0 Then
        Return SetError($error, "", 0)
    Else
        $aRet[0] = DllStructGetData($Retstrstruct1, 1)
        $aRet[1] = DllStructGetData($Retstrstruct2, 1)
        $aRet[2] = DllStructGetData($Retstruct, 3)
        Return SetError(0, "", $aRet)
    EndIf
EndFunc  ;==>_BASS_GetDeviceInfo

Getting there :P

Edited by BrettF
Link to comment
Share on other sites

That's not correct. The strings are created from bass.dll, so you have to create the struct after the call:

Func _BASS_GetDeviceInfo($bass_dll, $device)
    Local $aRet[3]
    Local $Retstruct = DllStructCreate("ptr name;ptr driver;dword flags;")
    
    $ret = DllCall($bass_dll, "int", "BASS_GetDeviceInfo", "dword", $device, "ptr", DllStructGetPtr($Retstruct))
    
;    $error = _BASS_ErrorGetCode($bass_dll)
;    If $error <> 0 Then
;        Return SetError($error, "", 0)
;    Else
        $aRet[0] = _PtrStringREad(DllStructGetData($Retstruct, 1))
        $aRet[1] = _PtrStringRead(DllStructGetData($Retstruct, 2))
        $aRet[2] = DllStructGetData($Retstruct, 3)
        Return SetError(0, "", $aRet)
;    EndIf
EndFunc  ;==>_BASS_GetDeviceInfo

; Prog@ndy
Func _PtrStringLen($ptr,$IsUniCode=False)
    Local $UniCodeFunc=""
    If $IsUniCode Then $UniCodeFunc = "W"
    Local $ret = DllCall("kernel32.dll","int","lstrlen"&$UniCodeFunc,"ptr",$ptr)
    If @error Then Return SetError(1,0,-1)
    Return $ret[0]
EndFunc
; Prog@ndy
Func _PtrStringRead($ptr,$IsUniCode=False,$StringLen=-1)
    Local $UniCodeString=""
    If $IsUniCode Then $UniCodeString = "W"
    If $StringLen < 1 Then $StringLen = _PtrStringLen($ptr,$IsUniCode)
    If $StringLen < 1 Then Return SetError(1,0,"")
    Local $struct = DllStructCreate($UniCodeString&"char["&($StringLen+1)&"]",$ptr)
    Return DllStructGetData($struct,1)
EndFunc

*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

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