Update sound_lib.

This commit is contained in:
Bill Dengler 2017-06-16 19:02:26 +00:00
parent bf4c09d0bb
commit 7349e3b3f3
62 changed files with 3540 additions and 3520 deletions

View File

@ -136,7 +136,7 @@ class Session(object):
def init_sound(self):
try: self.sound = sound.soundSystem(self.settings["sound"])
except: pass
except: log.exception("Exception thrown during sound system initialization")
@_require_configuration
def login(self, verify_credentials=True):

View File

@ -6,7 +6,11 @@ import os
import logging as original_logger
log = original_logger.getLogger("sound")
import paths
import sound_lib
from sound_lib.output import Output
from sound_lib.input import Input
from sound_lib.recording import WaveRecording
from sound_lib.stream import FileStream
from sound_lib.stream import URLStream as SoundlibURLStream
import subprocess
import platform
import output
@ -30,7 +34,7 @@ def recode_audio(filename, quality=4.5):
def recording(filename):
# try:
val = sound_lib.recording.WaveRecording(filename=filename)
val = WaveRecording(filename=filename)
# except sound_lib.main.BassError:
# sound_lib.input.Input()
# val = sound_lib.recording.WaveRecording(filename=filename)
@ -57,9 +61,9 @@ class soundSystem(object):
self.config = soundConfig
# Set the output and input default devices.
try:
self.output = sound_lib.output.Output()
self.input = sound_lib.input.Input()
except:
self.output = Output()
self.input = Input()
except IOError:
pass
# Try to use the selected device from the configuration. It can fail if the machine does not has a mic.
try:
@ -67,7 +71,7 @@ class soundSystem(object):
self.output.set_device(self.output.find_device_by_name(self.config["output_device"]))
self.input.set_device(self.input.find_device_by_name(self.config["input_device"]))
except:
log.error("Error in input or output devices, using defaults...")
log.exception("Error in input or output devices, using defaults...")
self.config["output_device"] = "Default"
self.config["input_device"] = "Default"
@ -89,7 +93,7 @@ class soundSystem(object):
def play(self, sound, argument=False):
if self.soundpack_OK == False: return
if self.config["session_mute"] == True: return
sound_object = sound_lib.stream.FileStream(file="%s/%s" % (self.path, sound))
sound_object = FileStream(file="%s/%s" % (self.path, sound))
sound_object.volume = float(self.config["volume"])
self.files.append(sound_object)
sound_object.play()
@ -140,7 +144,7 @@ class URLStream(object):
elif stream != None:
self.stream=stream
if self.prepared == True:
self.stream = sound_lib.stream.URLStream(url=self.url)
self.stream = SoundlibURLStream(url=self.url)
if hasattr(self,'stream'):
self.stream.volume = float(volume)
self.stream.play()

View File

@ -1,7 +1,6 @@
import output, input, recording, stream
__author__ = 'Christopher Toth'
__version__ = 0.73
__version__ = 0.8
def find_datafiles():
from glob import glob

View File

@ -73,7 +73,7 @@ class Channel (FlagObject):
__len__ = get_length
def __bool__(self):
def __nonzero__(self):
return True
def get_device(self):

View File

@ -50,7 +50,7 @@ class BassConfig(collections.Mapping):
return bass_call(pybass.BASS_SetConfig, key, val)
def __iter__(self):
for key in self.config_map.keys():
for key in self.config_map.iterkeys():
yield key
def __len__(self):

View File

@ -1 +1,2 @@
from __future__ import absolute_import
from .tempo import Tempo

View File

@ -1,6 +1,5 @@
from __future__ import absolute_import
from sound_lib.external import pybass_fx
from .effect import SoundEffect
from effect import SoundEffect
class Volume(SoundEffect):
effect_type = pybass_fx.BASS_FX_BFX_VOLUME

View File

@ -1,4 +1,3 @@
from future.builtins import object
from sound_lib.main import bass_call
import ctypes
from sound_lib.external import pybass

View File

@ -1,8 +1,9 @@
from __future__ import absolute_import
import ctypes
from sound_lib.external import pybass, pybass_fx
from sound_lib.stream import BaseStream
from sound_lib.channel import Channel
from sound_lib.main import bass_call, bass_call_0
from ..external import pybass, pybass_fx
from ..stream import BaseStream
from ..channel import Channel
from ..main import bass_call, bass_call_0
class Tempo(BaseStream):

View File

@ -1,6 +1,5 @@
from __future__ import absolute_import
from .external import pybass, pybassenc
from .main import bass_call, bass_call_0, FlagObject
from external import pybass, pybassenc
from main import bass_call, bass_call_0, FlagObject
class Encoder(FlagObject):

View File

@ -1,9 +1,10 @@
from __future__ import absolute_import
import platform
#if platform.system() == 'Windows':
# import sound_lib.external.pybasswma
from . import pybassopus
if platform.system() == 'Windows':
from . import pybasswma
if platform.system() != 'Darwin':
import sound_lib.external.pybass_aac
import sound_lib.external.pybass_alac
import sound_lib.external.pybassopus
import sound_lib.external.pybassflac
import sound_lib.external.pybassmidi
from . import pybass_aac
from . import pybass_alac
from . import pybassflac
from . import pybassmidi

View File

@ -1,7 +1,3 @@
from __future__ import division
from __future__ import absolute_import
from future.builtins import str
from future.builtins import range
# copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru
# BSD license
@ -523,7 +519,7 @@ BASS_STREAMPROC_END = (-2147483648)# end of user stream flag
# special STREAMPROCs
def streamproc_dummy(handle, buffer, length, user): return 0
def streamproc_push(handle, buffer, length, user): return -1
streamproc_push = -1
STREAMPROC_DUMMY = STREAMPROC(streamproc_dummy)# "dummy" stream
STREAMPROC_PUSH = STREAMPROC(streamproc_push)# push stream
@ -887,9 +883,13 @@ BASS_SetVolume = func_type(ctypes.c_byte, ctypes.c_float)(('BASS_SetVolume', bas
BASS_GetVolume = func_type(ctypes.c_float)(('BASS_GetVolume', bass_module))
#HPLUGIN BASSDEF(BASS_PluginLoad)(const char *file, DWORD flags);
BASS_PluginLoad_ = func_type(HPLUGIN, ctypes.c_char_p, ctypes.c_ulong)(('BASS_PluginLoad', bass_module))
def BASS_PluginLoad(path, flags):
return BASS_PluginLoad_(path.encode(sys.getfilesystemencoding()), flags)
_BASS_PluginLoad = func_type(HPLUGIN, ctypes.c_char_p, ctypes.c_ulong)(('BASS_PluginLoad', bass_module))
def BASS_PluginLoad(file, flags):
if type(file) != bytes:
file = file.encode(sys.getfilesystemencoding())
return _BASS_PluginLoad(file, flags)
#BOOL BASSDEF(BASS_PluginFree)(HPLUGIN handle);
BASS_PluginFree = func_type(ctypes.c_byte, HPLUGIN)(('BASS_PluginFree', bass_module))
#const BASS_PLUGININFO *BASSDEF(BASS_PluginGetInfo)(HPLUGIN handle);

View File

@ -51,4 +51,3 @@ BASS_AAC_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulon
BASS_MP4_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)(('BASS_MP4_StreamCreateFile', bass_aac_module))
#HSTREAM BASSAACDEF(BASS_MP4_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user);
BASS_MP4_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_MP4_StreamCreateFileUser', bass_aac_module))

View File

@ -1,5 +1,4 @@
from __future__ import absolute_import
from future.builtins import range
"BASS_FX wrapper by Christopher Toth"""
import ctypes

View File

@ -1,12 +1,10 @@
from __future__ import absolute_import
from future.builtins import range
"BASSENC wrapper by Christopher Toth"""
import ctypes
import os
import platform
from . import pybass
from .paths import x86_path, x64_path
import pybass
from paths import x86_path, x64_path
import libloader
bassenc_module = libloader.load_library('bassenc', x86_path=x86_path, x64_path=x64_path)

View File

@ -14,7 +14,7 @@ enabling the playing of FLAC (Free Lossless Audio Codec) encoded files.
import os, sys, ctypes
from . import pybass
from .paths import x86_path, x64_path
from . paths import x86_path, x64_path
import libloader
bassflac_module = libloader.load_library('bassflac', x86_path=x86_path, x64_path=x64_path)

View File

@ -202,3 +202,4 @@ BASS_MIDI_FontUnpack = func_type(ctypes.c_byte, HSOUNDFONT, ctypes.c_void_p, cty
BASS_MIDI_FontSetVolume = func_type(ctypes.c_byte, HSOUNDFONT, ctypes.c_float)(('BASS_MIDI_FontSetVolume', bassmidi_module))
#float BASSMIDIDEF(BASS_MIDI_FontGetVolume)(HSOUNDFONT handle);
BASS_MIDI_FontGetVolume = func_type(ctypes.c_float, HSOUNDFONT)(('BASS_MIDI_FontGetVolume', bassmidi_module))

View File

@ -1,4 +1,3 @@
from __future__ import absolute_import
# Copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru
# BSD license
@ -14,8 +13,7 @@ features. It also provides the ability to go the other way and split a
BASS channel into multiple channels.
'''
import os, sys, ctypes, platform
from . import pybass
import os, sys, ctypes, platform, pybass
QWORD = pybass.QWORD
HSYNC = pybass.HSYNC
@ -24,7 +22,7 @@ DOWNLOADPROC = pybass.DOWNLOADPROC
SYNCPROC = pybass.SYNCPROC
BASS_FILEPROCS = pybass.BASS_FILEPROCS
from .paths import x86_path, x64_path
from paths import x86_path, x64_path
import libloader
bassmix_module = libloader.load_library('bassmix', x86_path=x86_path, x64_path=x64_path)

View File

@ -1,18 +1,11 @@
# Copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru
# BSD license
__version__ = '0.1'
__versionTime__ = '2009-11-15'
__author__ = 'Max Kolosov <maxkolosov@inbox.ru>'
__doc__ = '''
pybassflac.py - is ctypes python module for
BASSFLAC - extension to the BASS audio library,
enabling the playing of FLAC (Free Lossless Audio Codec) encoded files.
'''
import os, sys, ctypes, pybass
from paths import x86_path, x64_path
import os, sys, ctypes
from . import pybass
from .paths import x86_path, x64_path
import libloader
bassopus_module = libloader.load_library('bassopus', x86_path=x86_path, x64_path=x64_path)
@ -36,12 +29,3 @@ BASS_OPUS_StreamCreateURL = func_type(HSTREAM, ctypes.c_char_p, ctypes.c_ulong,
#HSTREAM BASSFLACDEF(BASS_FLAC_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user);
BASS_OPUS_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_OPUS_StreamCreateFileUser', bassopus_module))
if __name__ == "__main__":
if not pybass.BASS_Init(-1, 44100, 0, 0, 0):
print 'BASS_Init error', pybass.get_error_description(pybass.BASS_ErrorGetCode())
else:
handle = BASS_OPUS_StreamCreateFile(False, 'test.opus', 0, 0, 0)
pybass.play_handle(handle)
if not pybass.BASS_Free():
print 'BASS_Free error', pybass.get_error_description(pybass.BASS_ErrorGetCode())

View File

@ -21,9 +21,9 @@ Windows Media player, so will already be on most users' systems, but they
can also be installed separately (WMFDIST.EXE is available from the BASS website).
'''
import os, sys, ctypes
from sound_lib.external import pybass
import os, sys, ctypes
from . import pybass
from .paths import x86_path, x64_path
import libloader
@ -146,3 +146,4 @@ BASS_WMA_EncodeClose = func_type(ctypes.c_byte, HWMENCODE)(('BASS_WMA_EncodeClos
#void *BASSWMADEF(BASS_WMA_GetWMObject)(DWORD handle);
BASS_WMA_GetWMObject = func_type(ctypes.c_void_p, ctypes.c_ulong)(('BASS_WMA_GetWMObject', basswma_module))

View File

@ -1,19 +1,17 @@
from __future__ import absolute_import
from future.builtins import object
from ctypes import string_at
import platform
import wave
from .external.pybass import *
if platform.system() == 'Windows':
from .external.pybasswasapi import *
from . import config
from .main import bass_call, bass_call_0, BassError
from .main import bass_call, bass_call_0
class Input (object):
def __init__ (self, device=-1):
try:
bass_call(BASS_RecordInit, device)
except BassError:
pass
self._device = device
self.config = config.BassConfig()
@ -48,6 +46,8 @@ class Input (object):
retrieved = info.name
if platform.system() == 'Windows':
retrieved = retrieved.decode('mbcs')
elif platform.system() == 'Darwin':
retrieved = retrieved.decode('utf-8')
retrieved = retrieved.replace('(', '').replace(')', '').strip()
result.append(retrieved)
count += 1
@ -64,3 +64,31 @@ class Input (object):
return self.find_device_by_name(device_name)
except ValueError:
return self.find_default_device()
class WASAPIInput(object):
def __init__(self, device=-2, frequency=0, channels=0, flags=0, buffer=0.0, period=0.0, callback=None):
if callback is None:
callback = lambda buffer, length, user: True
self.proc = WASAPIPROC(callback)
bass_call(BASS_WASAPI_Init, device, frequency, channels, flags, buffer, period, self.proc, None)
def free(self):
bass_call(BASS_WASAPI_Free)
def set_device(self, device):
bass_call(BASS_WASAPI_SetDevice, device)
def get_device(self):
return bass_call_0(BASS_WASAPI_GetDevice)
device = property(fget=get_device, fset=set_device)
def start(self):
return bass_call(BASS_WASAPI_Start)
def stop(self, reset=False):
return bass_call(BASS_WASAPI_Stop, reset)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,9 +1,7 @@
from __future__ import absolute_import
from future.builtins import object
from ctypes import pointer
from functools import partial
from .main import bass_call, update_3d_system
from .external.pybass import *
from main import bass_call, update_3d_system
from external.pybass import *
def _getter(base_prop, attr, obj):
return getattr(getattr(obj, base_prop), attr)

View File

@ -1,5 +1,4 @@
from __future__ import absolute_import
from future.builtins import object
from .external.pybass import *
from functools import update_wrapper

View File

@ -1,18 +1,17 @@
from __future__ import absolute_import
from .external import pybass
from .channel import Channel
from external import pybass
from channel import Channel
class Music(Channel):
def __init__(self, mem=False, file=None, offset=0, length=0, flags=0, freq=0):
handle = pybass.BASS_MusicLoad(mem, file, offset, length, flags, freq)
handle = BASS_MusicLoad(mem, file, offset, length, flags, freq)
super(Music, self).__init__(handle)
self.add_attributes_to_mapping(
music_amplify=pybass.BASS_ATTRIB_MUSIC_AMPLIFY,
music_bpm = pybass.BASS_ATTRIB_MUSIC_BPM,
music_pansep=pybass.BASS_ATTRIB_MUSIC_PANSEP,
music_speed=pybass.BASS_ATTRIB_MUSIC_SPEED,
music_vol_chan=pybass.BASS_ATTRIB_MUSIC_VOL_CHAN,
music_vol_global=pybass.BASS_ATTRIB_MUSIC_VOL_GLOBAL,
music_vol_inst=pybass.BASS_ATTRIB_MUSIC_VOL_INST,
music_bpm = BASS_ATTRIB_MUSIC_BPM,
music_pansep=BASS_ATTRIB_MUSIC_PANSEP,
music_speed=BASS_ATTRIB_MUSIC_SPEED,
music_vol_chan=BASS_ATTRIB_MUSIC_VOL_CHAN,
music_vol_global=BASS_ATTRIB_MUSIC_VOL_GLOBAL,
music_vol_inst=BASS_ATTRIB_MUSIC_VOL_INST,
)

View File

@ -1,10 +1,8 @@
from __future__ import division
from __future__ import absolute_import
from future.builtins import object
from functools import partial
import platform
from ctypes import c_char_p, c_float, pointer, string_at
from sound_lib.external.pybass import *
from .external.pybass import *
from . import config
from .main import bass_call, bass_call_0, EAX_ENVIRONMENTS, update_3d_system
@ -111,6 +109,8 @@ class Output (object):
retrieved = info.name
if platform.system() == 'Windows':
retrieved = retrieved.decode('mbcs')
elif platform.system() == 'Darwin':
retrieved = retrieved.decode('utf-8')
retrieved = retrieved.replace('(', '').replace(')', '').strip()
result.append(retrieved)
count += 1
@ -168,7 +168,7 @@ class ThreeDOutput(Output):
arg = -1
return arg
environment = convert_arg(environment)
if isinstance(environment, str) and environment in EAX_ENVIRONMENTS:
if isinstance(environment, basestring) and environment in EAX_ENVIRONMENTS:
environment = EAX_ENVIRONMENTS[environment]
volume = convert_arg(volume)
decay = convert_arg(decay)

View File

@ -4,8 +4,10 @@ import sys
from .channel import Channel
from .main import bass_call, bass_call_0
from .external.pybass import *
convert_to_unicode = str
try:
convert_to_unicode = unicode
except NameError:
convert_to_unicode = str
class BaseStream(Channel):
@ -32,7 +34,7 @@ class FileStream(BaseStream):
def __init__(self, mem=False, file=None, offset=0, length=0, flags=0, three_d=False, mono=False, autofree=False, decode=False, unicode=True):
"""Creates a sample stream from an MP3, MP2, MP1, OGG, WAV, AIFF or plugin supported file."""
if platform.system() == 'Darwin' or platform.system() == "Linux":
if platform.system() == 'Darwin':
unicode = False
file = file.encode(sys.getfilesystemencoding())
self.setup_flag_mapping()
@ -59,3 +61,14 @@ class URLStream(BaseStream):
flags = flags | self.flags_for(three_d=three_d, autofree=autofree, decode=decode)
handle = bass_call(BASS_StreamCreateURL, url, offset, flags, self.downloadproc, user)
super(URLStream, self).__init__(handle)
class PushStream(BaseStream):
def __init__(self, freq=44100, chans=2, flags=0, user=None, three_d=False, autofree=False, decode=False):
self.proc = STREAMPROC_PUSH
self.setup_flag_mapping()
flags = flags | self.flags_for(three_d=three_d, autofree=autofree, decode=decode)
handle = bass_call(BASS_StreamCreate, freq, chans, flags, self.proc, user)
super(PushStream, self).__init__(handle)
def push(self, data):
return bass_call_0(BASS_StreamPutData, self.handle, data, len(data))