monoceres Posted October 24, 2008 Share Posted October 24, 2008 (edited) 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: expandcollapse popupGlobal $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! Edited October 24, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
trancexx Posted October 24, 2008 Share Posted October 24, 2008 Maybe they are lying. expandcollapse popupGlobal $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 More sharing options...
AdmiralAlkex Posted October 25, 2008 Share Posted October 25, 2008 (edited) I was just going to start with BASS_ChannelGetPosition myself, but thank you both for saving me some time! Edited October 25, 2008 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
monoceres Posted October 25, 2008 Author Share Posted October 25, 2008 Maybe they are lying.Yeah, it seems so. I wonder why though.Thanks. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
BrettF Posted October 25, 2008 Share Posted October 25, 2008 Are you working on a BASS.au3? Cause if so damn, I only just started... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
monoceres Posted October 25, 2008 Author Share Posted October 25, 2008 Are you working on a BASS.au3? Cause if so damn, I only just started... No, I'm actually building an audio player, I thought I be the first to do an audio player in autoit Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
dbzfanatic Posted October 25, 2008 Share Posted October 25, 2008 What about Evolutionized Media Player? Doesn't that count as an audio player? lol Go to my website. | My Zazzle Page (custom products)Al Bhed Translator | Direct linkScreenRec ProSimple Text Editor (STE) [TUTORIAL]Task Scheduler UDF <--- First ever UDF!_ControlPaste() UDF[quote name='renanzin' post='584064' date='Sep 26 2008, 07:00 AM']whats help ?[/quote] Link to comment Share on other sites More sharing options...
BrettF Posted October 25, 2008 Share Posted October 25, 2008 No, I'm actually building an audio player, I thought I be the first to do an audio player in autoit Hahahahha well answer this for me, whats this struct in AutoIt? Crashes for me typedef struct { char *name; char *driver; DWORD flags; } BASS_DEVICEINFO; Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
monoceres Posted October 25, 2008 Author Share Posted October 25, 2008 Hahahahha well answer this for me, whats this struct in AutoIt? Crashes for me typedef struct { char *name; char *driver; DWORD flags; } BASS_DEVICEINFO; 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 More sharing options...
ProgAndy Posted October 25, 2008 Share Posted October 25, 2008 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 More sharing options...
BrettF Posted October 25, 2008 Share Posted October 25, 2008 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 Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
ProgAndy Posted October 25, 2008 Share Posted October 25, 2008 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 More sharing options...
monoceres Posted October 25, 2008 Author Share Posted October 25, 2008 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 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 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 More sharing options...
ProgAndy Posted October 25, 2008 Share Posted October 25, 2008 Oops didn't see it 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 More sharing options...
BrettF Posted October 25, 2008 Share Posted October 25, 2008 (edited) 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 Edited October 25, 2008 by BrettF Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
ProgAndy Posted October 25, 2008 Share Posted October 25, 2008 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 More sharing options...
BrettF Posted October 25, 2008 Share Posted October 25, 2008 Okay thanks! Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now