| 1 |
|
| 2 |
"""Print OpenAL driver information. |
| 3 |
|
| 4 |
Options: |
| 5 |
-d <device> Optionally specify device to query. |
| 6 |
""" |
| 7 |
import ctypes |
| 8 |
import optparse |
| 9 |
import sys |
| 10 |
|
| 11 |
from pyglet.util import asbytes |
| 12 |
from pyglet.media.drivers import openal |
| 13 |
from pyglet.media.drivers.openal.interface import alc |
| 14 |
|
| 15 |
|
| 16 |
def split_nul_strings(s): |
| 17 |
|
| 18 |
nul = False |
| 19 |
i = 0 |
| 20 |
while True: |
| 21 |
if s[i] == b'\x00': |
| 22 |
if nul: |
| 23 |
break |
| 24 |
else: |
| 25 |
nul = True |
| 26 |
else: |
| 27 |
nul = False |
| 28 |
i += 1 |
| 29 |
s = s[:i - 1] |
| 30 |
return s.split(b'\x00') |
| 31 |
|
| 32 |
|
| 33 |
if __name__ == '__main__': |
| 34 |
op = optparse.OptionParser() |
| 35 |
op.add_option('-d', '--device', dest='device', |
| 36 |
help='use device DEVICE', metavar='DEVICE') |
| 37 |
(options, args) = op.parse_args(sys.argv[1:]) |
| 38 |
|
| 39 |
default_device = ctypes.cast( |
| 40 |
alc.alcGetString(None, alc.ALC_DEFAULT_DEVICE_SPECIFIER), ctypes.c_char_p).value |
| 41 |
capture_default_device = ctypes.cast( |
| 42 |
alc.alcGetString(None, alc.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER), ctypes.c_char_p).value |
| 43 |
|
| 44 |
print('Default device: %s' % default_device) |
| 45 |
print('Default capture device: %s' % capture_default_device) |
| 46 |
|
| 47 |
if alc.alcIsExtensionPresent(None, ctypes.create_string_buffer(b'ALC_ENUMERATION_EXT')): |
| 48 |
devices = split_nul_strings(alc.alcGetString(None, alc.ALC_DEVICE_SPECIFIER)) |
| 49 |
capture_devices = split_nul_strings(alc.alcGetString(None, alc.ALC_CAPTURE_DEVICE_SPECIFIER)) |
| 50 |
|
| 51 |
print('Devices: %s' % b', '.join(devices)) |
| 52 |
print('Capture devices: %s\n' % b', '.join(capture_devices)) |
| 53 |
|
| 54 |
if options.device: |
| 55 |
print('Using device "%s"...' % options.device) |
| 56 |
driver = openal.create_audio_driver(asbytes(options.device)) |
| 57 |
else: |
| 58 |
print('Using default device...') |
| 59 |
driver = openal.create_audio_driver() |
| 60 |
|
| 61 |
print('OpenAL version %d.%d' % driver.get_version()) |
| 62 |
print('Extensions: %s' % ', '.join(driver.get_extensions())) |