-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpybass_ac3.py
54 lines (42 loc) · 2.2 KB
/
pybass_ac3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright(c) Max Kolosov 2009 [email protected]
# http://vosolok2008.narod.ru
# BSD license
__version__ = '0.2'
__versionTime__ = '2013-01-22'
__author__ = 'Max Kolosov <[email protected]>'
__doc__ = '''
pybass_ac3.py - is ctypes python module for
BASS_AC3 - extension to the BASS audio library that enables the playback
of Dolby Digital AC-3 streams (http://www.maresweb.de).
'''
import sys, ctypes, platform, pybass
QWORD = pybass.QWORD
HSTREAM = pybass.HSTREAM
DOWNLOADPROC = pybass.DOWNLOADPROC
BASS_FILEPROCS = pybass.BASS_FILEPROCS
if platform.system().lower() == 'windows':
bass_ac3_module = ctypes.WinDLL('bass_ac3')
func_type = ctypes.WINFUNCTYPE
else:
bass_ac3_module = ctypes.CDLL('bass_ac3')
func_type = ctypes.CFUNCTYPE
# BASS_Set/GetConfig options
BASS_CONFIG_AC3_DYNRNG = 0x10001
# Additional BASS_AC3_StreamCreateFile/User/URL flags
BASS_AC3_DYNAMIC_RANGE = 0x800 # enable dynamic range compression
# BASS_CHANNELINFO type
BASS_CTYPE_STREAM_AC3 = 0x11000
#HSTREAM BASSAC3DEF(BASS_AC3_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
BASS_AC3_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)(('BASS_AC3_StreamCreateFile', bass_ac3_module))
#HSTREAM BASSAC3DEF(BASS_AC3_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user);
BASS_AC3_StreamCreateURL = func_type(HSTREAM, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_ulong, DOWNLOADPROC, ctypes.c_void_p)(('BASS_AC3_StreamCreateURL', bass_ac3_module))
#HSTREAM BASSAC3DEF(BASS_AC3_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user);
BASS_AC3_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_AC3_StreamCreateFileUser', bass_ac3_module))
if __name__ == "__main__":
if not pybass.BASS_Init(-1, 44100, 0, 0, 0):
print('BASS_Init error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))
else:
handle = BASS_AC3_StreamCreateFile(False, b'test.ac3', 0, 0, 0)
pybass.play_handle(handle)
if not pybass.BASS_Free():
print('BASS_Free error %s' % pybass.get_error_description(pybass.BASS_ErrorGetCode()))