New Python Developer with Bass

Started by evstevemd,

evstevemd

Hello all,
I need a leap start with bass.dll, that is how to basically Load the file, play pause etc. For now, I have browsed and see that it is not big issue to re-play stop and pause, but to load file. Can someone help me to leap up and running with bass?

My Specs:
python 2.5.2
ctypes to access dll
Vista/Ubuntu

Thanks all guys

evstevemd

Is there anyone who is willing to help me start with bass.dll? I need to load a file and at least play it.
Any help??
  ::)

Ian @ un4seen

I haven't heard of anyone using BASS with Python before, so I think you may be the first! Unfortunately, that means it's unlikely anyone here will be able to help with that, but if you're familiar with other languages (C/C++, Delphi, VB), you could have a look at the examples (as well as the documentation) included in the BASS package for some pointers.

The basic calls required to play a file would be as follows...

BASS_Init(...); // initialize output device
stream=BASS_StreamCreateFile(...); // create a stream from the file
BASS_ChannelPlay(stream, FALSE); // play the stream

...

BASS_StreamFree(stream); // free the stream
BASS_Free(); // free output device

Please lookup those functions in the documentation for further details.

evstevemd

so only those lines of code? I will dive in to see if they works
Thanks Sir

evstevemd

Quote from: Ian @ un4seenThe basic calls required to play a file would be as follows...

BASS_Init(...); // initialize output device
stream=BASS_StreamCreateFile(...); // create a stream from the file
BASS_ChannelPlay(stream, FALSE); // play the stream

...

BASS_StreamFree(stream); // free the stream
BASS_Free(); // free output device

Please lookup those functions in the documentation for further details.

I started working with the Library, but in API havent said the optional and mandatory parameter so I find little confused. Any help

evstevemd

Yep, I have managed to run BASS_Init with no problem and returns 1
I haven't able been to create sample yet. I need help on which parameters are mandatory to BASS_StreamCreate? Iam now at different PC and will post te full result while at Home

Thanks

Chris

Hi
 OnForm load or create
   //Initialize BASS to use the first output device,
   // and a nominal format of 44100hz stereo 16-bit.

   BASS_Init(1, 44100, 0, hwnd, NULL); //
-------------------------------------------------------
on a button click or whatever
  BASS_StreamFree(stream); // free the old stream         
  HSTREAM stream=BASS_StreamCreateFile(FALSE, "C:\afile.mp3", 0, 0, 0);
-----------------------------------------------------------
on a button click or whatever
lets play the stuff
     BASS_ChannelPlay(stream, FALSE); // play the stream
------------------------------------------------------------

 OnForm close or destroy
  Bass_Free();
-------------------------------------------------------------

Chris

 

evstevemd

Thanks Chris!
Unfortunately Im not good at C/C++ and I'm programming in Python.
However I use ctypes to acces DLL functions. here is simple app I came with with no freeing functions yet. I want to roughly be able to play file with it before I do neat stuffs, so dont worry of alot of comments (some useless)
I have stucked here and everytime I call it, it tells me this:

ValueError: Procedure probably called with not enough arguments (8 bytes missing)

can someone decode this, anyway the failure occurs here: stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)

here is whole code:

Code (python) Select
#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL
# sample I got somehwere: BASS_Init(-1,44100,0,win,NULL) win The application's main window... 0 = the current foreground window (use this for console applications).
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_int, ct.c_int, ct.c_int, ct.c_int]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int , ct.c_int, ct.c_int]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = HANDLE
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
   
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [HANDLE, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
   
onInit_Lib()
stream = onStream()
onPlay(stream)

Ian @ un4seen

Quote from: evstevemd
Code (python) Select
#import ctypes module
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int , ct.c_int, ct.c_int]

That looks like the cause of the "8 bytes missing" trouble. The "offset" and "length" parameters are 64-bit (QWORD), but it appears that you have defined them as 32-bit. Does Python have a 64-bit integer type? If not, you could replace each QWORD parameter with 2x 32-bit parameters.


Ian @ un4seen

From that, I guess the "QWORD" parameters would be "ct.c_uint64" in Python.

evstevemd

ok let me give a try, BTW I tries ct.c_longlong and rsult is:
I:\Documents\Projects\Coding\Bass MP3 Player\test.mp3
2952790017

evstevemd

have tried that variable and 8 byte missing resusmed. BTW what does this means?
 I:\Documents\Projects\Coding\Bass MP3 Player\test.mp3
2952790017

evstevemd

Here is the code that no error no sound,
help!

#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL
# sample I got somehwere: BASS_Init(-1,44100,0,win,NULL) win The application's main window... 0 = the current foreground window (use this for console applications).
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_int, ct.c_int, ct.c_int, ct.c_int]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_longlong , ct.c_longlong, ct.c_int]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = HANDLE
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
   
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [HANDLE, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
   
onInit_Lib()
stream = onStream()
onPlay(stream)

Chris

#14
Hi if I_m reading the ctype lib doku right the code must looks like the following
Integer -> c_int
DWORD -> c_uint
QWORD -> c_int64


#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL
# sample I got somehwere: BASS_Init(-1,44100,0,win,NULL) win The application's main window... 0 = the current foreground window (use this for console applications).
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_uint, ct.c_uint, ct.c_uint, ct.c_uint]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int64 , ct.cc_int64, ct.c_uint]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = ct.c_uint
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
   
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [ct.c_uint, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
   
onInit_Lib()
stream = onStream()
onPlay(stream)

Chris

evstevemd

I wonder why no sound comes out!  ???
Can someone figure out?? No error, but yet no sound!  ::)

Chris

Did you have look at my last post??
and you can do a BASS_ErrorGetCode call to look what error will happens
int BASS_ErrorGetCode();

Chris

evstevemd

I used your code and nothing came out. Let me see what happens using that code

evstevemd

print bass_dll.BASS_ErrorGetCode() gives error code 0 which I think suggests that it loaded successful, isn't it?
I suspect may be something is wrong with onPlay function

Ian @ un4seen

What is happening after the "onPlay" call? Does the app wait for something (eg. a button click) before closing? If not, that'll probably be why you hear nothing; the app is closing (and playback stopping) as soon as playback begins.

evstevemd

Hello Ian,
here is onPlay code. I do first play the file in console, and if succesful I will think of GUI
Code (python) Select
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [ct.c_uint, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
It is supposed to play file once the program runs!

Here is full code:
Code (python) Select
#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL
# sample I got somehwere: BASS_Init(-1,44100,0,win,NULL) win The application's main window... 0 = the current foreground window (use this for console applications).
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_uint, ct.c_uint, ct.c_uint, ct.c_uint]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int64 , ct.c_int64, ct.c_uint]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = ct.c_uint
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
   
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [ct.c_uint, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
   
onInit_Lib()
stream = onStream()
onPlay(stream)

print bass_dll.BASS_ErrorGetCode()

Chris

Hi
 onInit_Lib()
stream = onStream()
onPlay(stream)

try this

onInit_Lib()
print bass_dll.BASS_ErrorGetCode()
stream = onStream()
print bass_dll.BASS_ErrorGetCode()
onPlay(stream)
print bass_dll.BASS_ErrorGetCode()

Chris


evstevemd

Results:
0
I:\Documents\Projects\Coding\Bass MP3 Player\test.mp3
2952790017
0
0

Ian @ un4seen

It still looks to me like the problem is just that the program is ending/closing before it has played the file. You could try adding a wait for a key press after the "onPlay" call.