942,520 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 785
  • Python RSS
Dec 18th, 2008
0

Help with this code

Expand Post »
I use ctypes to play AUDIO using bass.dll found here:
http://www.un4seen.com/
I have gone so far and tried as they advised me at their forum entry here:
http://www.un4seen.com/forum/?topic=9257.0
But I still get errors. Can anyone take code and analyze to point out source of error?
Here is the code, pse ignore any useless comment, I was using the editor as scratch pad too
python Syntax (Toggle Plain Text)
  1. #import ctypes module
  2. import ctypes as ct
  3. #import OS
  4. import os
  5. #get BOOL C++ value from ctypes
  6. from ctypes.wintypes import BOOL
  7. from ctypes.wintypes import HANDLE
  8. #Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
  9. bass_dll = ct.windll.bass
  10. #initialize the DLL
  11. # 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).
  12. #function to intialize the DLL
  13.  
  14. def onInit_Lib():
  15. #define arg types
  16. bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_int, ct.c_int, ct.c_int, ct.c_int]
  17. #define result types
  18. bass_dll.BASS_Init.restype = ct.c_int
  19. #call function with args
  20. c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
  21. print c
  22.  
  23. def onStream():
  24. #arg definitions
  25. #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
  26. bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int , ct.c_int, ct.c_int]
  27. #defining restypes
  28. bass_dll.BASS_StreamCreateFile.restype = HANDLE
  29. path = os.getcwd()
  30. full = os.path.join(path, "test.mp3")
  31. print full
  32. stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
  33. print stream
  34. return stream
  35.  
  36. def onPlay(stream):
  37. #define args
  38. #BASS_ChannelPlay(stream, FALSE); // play the stream
  39. bass_dll.BASS_ChannelPlay.argtypes = [HANDLE, BOOL]
  40. #call function
  41. bass_dll.BASS_ChannelPlay(stream, False)
  42.  
  43. onInit_Lib()
  44. stream = onStream()
  45. onPlay(stream)
With thanks,
Similar Threads
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007
Dec 18th, 2008
0

Re: Help with this code

here is modified code that fix the error but no sound
python Syntax (Toggle Plain Text)
  1. #import ctypes module
  2. import ctypes as ct
  3. #import OS
  4. import os
  5. #get BOOL C++ value from ctypes
  6. from ctypes.wintypes import BOOL
  7. from ctypes.wintypes import HANDLE
  8. #Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
  9. bass_dll = ct.windll.bass
  10. #initialize the DLL
  11. # 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).
  12. #function to intialize the DLL
  13.  
  14. def onInit_Lib():
  15. #define arg types
  16. bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_int, ct.c_int, ct.c_int, ct.c_int]
  17. #define result types
  18. bass_dll.BASS_Init.restype = ct.c_int
  19. #call function with args
  20. c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
  21. print c
  22.  
  23. def onStream():
  24. #arg definitions
  25. #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
  26. bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_longlong , ct.c_longlong, ct.c_int]
  27. #defining restypes
  28. bass_dll.BASS_StreamCreateFile.restype = HANDLE
  29. path = os.getcwd()
  30. full = os.path.join(path, "test.mp3")
  31. print full
  32. stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
  33. print stream
  34. return stream
  35.  
  36. def onPlay(stream):
  37. #define args
  38. #BASS_ChannelPlay(stream, FALSE); // play the stream
  39. bass_dll.BASS_ChannelPlay.argtypes = [HANDLE, BOOL]
  40. #call function
  41. bass_dll.BASS_ChannelPlay(stream, False)
  42.  
  43. onInit_Lib()
  44. stream = onStream()
  45. onPlay(stream)
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007
Dec 19th, 2008
0

Re: Help with this code

Finally solved. Codes are roughly arranged and are not in order because I was learning the bass.dll & ctypes basics
python Syntax (Toggle Plain Text)
  1. #Play audio with bass.dll and python ctypes
  2. #Code By Steve
  3. #import ctypes module
  4. import ctypes as ct
  5. #import OS
  6. import os
  7. #get BOOL C++ value from ctypes
  8. from ctypes.wintypes import BOOL
  9. from ctypes.wintypes import HANDLE
  10. #Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
  11. bass_dll = ct.windll.bass
  12. #initialize the DLL
  13. # 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).
  14. #function to intialize the DLL
  15.  
  16. def onInit_Lib():
  17. #define arg types
  18. bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_uint, ct.c_uint, ct.c_uint, ct.c_uint]
  19. #define result types
  20. bass_dll.BASS_Init.restype = ct.c_int
  21. #call function with args
  22. c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
  23. print c
  24.  
  25. def onStream():
  26. #arg definitions
  27. #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
  28. bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int64 , ct.c_int64, ct.c_uint]
  29. #defining restypes
  30. bass_dll.BASS_StreamCreateFile.restype = ct.c_uint
  31. path = os.getcwd()
  32. full = os.path.join(path, "test.mp3")
  33. print full
  34. stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
  35. print stream
  36. return stream
  37.  
  38. def onPlay(stream):
  39. #define args
  40. #BASS_ChannelPlay(stream, FALSE); // play the stream
  41. bass_dll.BASS_ChannelPlay.argtypes = [ct.c_uint, BOOL]
  42. #call function
  43. bass_dll.BASS_ChannelPlay(stream, False)
  44.  
  45. onInit_Lib()
  46. print bass_dll.BASS_ErrorGetCode()
  47. stream = onStream()
  48. print bass_dll.BASS_ErrorGetCode()
  49. onPlay(stream)
  50. print bass_dll.BASS_ErrorGetCode()
  51. while True:
  52. print "Playing"
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Python Intrepeter in programs
Next Thread in Python Forum Timeline: Subtracting values w/list





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC