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): def init_sound(self):
try: self.sound = sound.soundSystem(self.settings["sound"]) try: self.sound = sound.soundSystem(self.settings["sound"])
except: pass except: log.exception("Exception thrown during sound system initialization")
@_require_configuration @_require_configuration
def login(self, verify_credentials=True): def login(self, verify_credentials=True):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,5 @@
from __future__ import absolute_import
from sound_lib.external import pybass_fx from sound_lib.external import pybass_fx
from .effect import SoundEffect from effect import SoundEffect
class Volume(SoundEffect): class Volume(SoundEffect):
effect_type = pybass_fx.BASS_FX_BFX_VOLUME 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 from sound_lib.main import bass_call
import ctypes import ctypes
from sound_lib.external import pybass from sound_lib.external import pybass

View File

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

View File

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

View File

@ -1,9 +1,10 @@
from __future__ import absolute_import
import platform import platform
#if platform.system() == 'Windows': from . import pybassopus
# import sound_lib.external.pybasswma if platform.system() == 'Windows':
from . import pybasswma
if platform.system() != 'Darwin': if platform.system() != 'Darwin':
import sound_lib.external.pybass_aac from . import pybass_aac
import sound_lib.external.pybass_alac from . import pybass_alac
import sound_lib.external.pybassopus from . import pybassflac
import sound_lib.external.pybassflac from . import pybassmidi
import sound_lib.external.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 # copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru # http://vosolok2008.narod.ru
# BSD license # BSD license
@ -523,7 +519,7 @@ BASS_STREAMPROC_END = (-2147483648)# end of user stream flag
# special STREAMPROCs # special STREAMPROCs
def streamproc_dummy(handle, buffer, length, user): return 0 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_DUMMY = STREAMPROC(streamproc_dummy)# "dummy" stream
STREAMPROC_PUSH = STREAMPROC(streamproc_push)# push 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)) BASS_GetVolume = func_type(ctypes.c_float)(('BASS_GetVolume', bass_module))
#HPLUGIN BASSDEF(BASS_PluginLoad)(const char *file, DWORD flags); #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)) _BASS_PluginLoad = func_type(HPLUGIN, ctypes.c_char_p, ctypes.c_ulong)(('BASS_PluginLoad', bass_module))
def BASS_PluginLoad(path, flags): def BASS_PluginLoad(file, flags):
return BASS_PluginLoad_(path.encode(sys.getfilesystemencoding()), flags) if type(file) != bytes:
file = file.encode(sys.getfilesystemencoding())
return _BASS_PluginLoad(file, flags)
#BOOL BASSDEF(BASS_PluginFree)(HPLUGIN handle); #BOOL BASSDEF(BASS_PluginFree)(HPLUGIN handle);
BASS_PluginFree = func_type(ctypes.c_byte, HPLUGIN)(('BASS_PluginFree', bass_module)) BASS_PluginFree = func_type(ctypes.c_byte, HPLUGIN)(('BASS_PluginFree', bass_module))
#const BASS_PLUGININFO *BASSDEF(BASS_PluginGetInfo)(HPLUGIN handle); #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)) 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); #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)) 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__ import absolute_import
from future.builtins import range
"BASS_FX wrapper by Christopher Toth""" "BASS_FX wrapper by Christopher Toth"""
import ctypes import ctypes

View File

@ -1,12 +1,10 @@
from __future__ import absolute_import
from future.builtins import range
"BASSENC wrapper by Christopher Toth""" "BASSENC wrapper by Christopher Toth"""
import ctypes import ctypes
import os import os
import platform import platform
from . import pybass import pybass
from .paths import x86_path, x64_path from paths import x86_path, x64_path
import libloader import libloader
bassenc_module = libloader.load_library('bassenc', x86_path=x86_path, x64_path=x64_path) 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 import os, sys, ctypes
from . import pybass from . import pybass
from .paths import x86_path, x64_path from . paths import x86_path, x64_path
import libloader import libloader
bassflac_module = libloader.load_library('bassflac', x86_path=x86_path, x64_path=x64_path) 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)) BASS_MIDI_FontSetVolume = func_type(ctypes.c_byte, HSOUNDFONT, ctypes.c_float)(('BASS_MIDI_FontSetVolume', bassmidi_module))
#float BASSMIDIDEF(BASS_MIDI_FontGetVolume)(HSOUNDFONT handle); #float BASSMIDIDEF(BASS_MIDI_FontGetVolume)(HSOUNDFONT handle);
BASS_MIDI_FontGetVolume = func_type(ctypes.c_float, HSOUNDFONT)(('BASS_MIDI_FontGetVolume', bassmidi_module)) 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 # Copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru # http://vosolok2008.narod.ru
# BSD license # 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. BASS channel into multiple channels.
''' '''
import os, sys, ctypes, platform import os, sys, ctypes, platform, pybass
from . import pybass
QWORD = pybass.QWORD QWORD = pybass.QWORD
HSYNC = pybass.HSYNC HSYNC = pybass.HSYNC
@ -24,7 +22,7 @@ DOWNLOADPROC = pybass.DOWNLOADPROC
SYNCPROC = pybass.SYNCPROC SYNCPROC = pybass.SYNCPROC
BASS_FILEPROCS = pybass.BASS_FILEPROCS BASS_FILEPROCS = pybass.BASS_FILEPROCS
from .paths import x86_path, x64_path from paths import x86_path, x64_path
import libloader import libloader
bassmix_module = libloader.load_library('bassmix', x86_path=x86_path, x64_path=x64_path) 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' __version__ = '0.1'
__versionTime__ = '2009-11-15' __versionTime__ = '2009-11-15'
__author__ = 'Max Kolosov <maxkolosov@inbox.ru>' __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 import os, sys, ctypes
from paths import x86_path, x64_path from . import pybass
from .paths import x86_path, x64_path
import libloader import libloader
bassopus_module = libloader.load_library('bassopus', x86_path=x86_path, x64_path=x64_path) 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); #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)) 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). 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 from .paths import x86_path, x64_path
import libloader 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); #void *BASSWMADEF(BASS_WMA_GetWMObject)(DWORD handle);
BASS_WMA_GetWMObject = func_type(ctypes.c_void_p, ctypes.c_ulong)(('BASS_WMA_GetWMObject', basswma_module)) 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 from ctypes import string_at
import platform
import wave import wave
from .external.pybass import * from .external.pybass import *
if platform.system() == 'Windows':
from .external.pybasswasapi import *
from . import config from . import config
from .main import bass_call, bass_call_0, BassError from .main import bass_call, bass_call_0
class Input (object): class Input (object):
def __init__ (self, device=-1): def __init__ (self, device=-1):
try:
bass_call(BASS_RecordInit, device) bass_call(BASS_RecordInit, device)
except BassError:
pass
self._device = device self._device = device
self.config = config.BassConfig() self.config = config.BassConfig()
@ -48,6 +46,8 @@ class Input (object):
retrieved = info.name retrieved = info.name
if platform.system() == 'Windows': if platform.system() == 'Windows':
retrieved = retrieved.decode('mbcs') retrieved = retrieved.decode('mbcs')
elif platform.system() == 'Darwin':
retrieved = retrieved.decode('utf-8')
retrieved = retrieved.replace('(', '').replace(')', '').strip() retrieved = retrieved.replace('(', '').replace(')', '').strip()
result.append(retrieved) result.append(retrieved)
count += 1 count += 1
@ -64,3 +64,31 @@ class Input (object):
return self.find_device_by_name(device_name) return self.find_device_by_name(device_name)
except ValueError: except ValueError:
return self.find_default_device() 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 ctypes import pointer
from functools import partial from functools import partial
from .main import bass_call, update_3d_system from main import bass_call, update_3d_system
from .external.pybass import * from external.pybass import *
def _getter(base_prop, attr, obj): def _getter(base_prop, attr, obj):
return getattr(getattr(obj, base_prop), attr) return getattr(getattr(obj, base_prop), attr)

View File

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

View File

@ -1,18 +1,17 @@
from __future__ import absolute_import from external import pybass
from .external import pybass from channel import Channel
from .channel import Channel
class Music(Channel): class Music(Channel):
def __init__(self, mem=False, file=None, offset=0, length=0, flags=0, freq=0): 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) super(Music, self).__init__(handle)
self.add_attributes_to_mapping( self.add_attributes_to_mapping(
music_amplify=pybass.BASS_ATTRIB_MUSIC_AMPLIFY, music_amplify=pybass.BASS_ATTRIB_MUSIC_AMPLIFY,
music_bpm = pybass.BASS_ATTRIB_MUSIC_BPM, music_bpm = BASS_ATTRIB_MUSIC_BPM,
music_pansep=pybass.BASS_ATTRIB_MUSIC_PANSEP, music_pansep=BASS_ATTRIB_MUSIC_PANSEP,
music_speed=pybass.BASS_ATTRIB_MUSIC_SPEED, music_speed=BASS_ATTRIB_MUSIC_SPEED,
music_vol_chan=pybass.BASS_ATTRIB_MUSIC_VOL_CHAN, music_vol_chan=BASS_ATTRIB_MUSIC_VOL_CHAN,
music_vol_global=pybass.BASS_ATTRIB_MUSIC_VOL_GLOBAL, music_vol_global=BASS_ATTRIB_MUSIC_VOL_GLOBAL,
music_vol_inst=pybass.BASS_ATTRIB_MUSIC_VOL_INST, 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__ import absolute_import
from future.builtins import object
from functools import partial from functools import partial
import platform import platform
from ctypes import c_char_p, c_float, pointer, string_at 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 . import config
from .main import bass_call, bass_call_0, EAX_ENVIRONMENTS, update_3d_system from .main import bass_call, bass_call_0, EAX_ENVIRONMENTS, update_3d_system
@ -111,6 +109,8 @@ class Output (object):
retrieved = info.name retrieved = info.name
if platform.system() == 'Windows': if platform.system() == 'Windows':
retrieved = retrieved.decode('mbcs') retrieved = retrieved.decode('mbcs')
elif platform.system() == 'Darwin':
retrieved = retrieved.decode('utf-8')
retrieved = retrieved.replace('(', '').replace(')', '').strip() retrieved = retrieved.replace('(', '').replace(')', '').strip()
result.append(retrieved) result.append(retrieved)
count += 1 count += 1
@ -168,7 +168,7 @@ class ThreeDOutput(Output):
arg = -1 arg = -1
return arg return arg
environment = convert_arg(environment) 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] environment = EAX_ENVIRONMENTS[environment]
volume = convert_arg(volume) volume = convert_arg(volume)
decay = convert_arg(decay) decay = convert_arg(decay)

View File

@ -4,8 +4,10 @@ import sys
from .channel import Channel from .channel import Channel
from .main import bass_call, bass_call_0 from .main import bass_call, bass_call_0
from .external.pybass import * from .external.pybass import *
try:
convert_to_unicode = str convert_to_unicode = unicode
except NameError:
convert_to_unicode = str
class BaseStream(Channel): 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): 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.""" """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 unicode = False
file = file.encode(sys.getfilesystemencoding()) file = file.encode(sys.getfilesystemencoding())
self.setup_flag_mapping() self.setup_flag_mapping()
@ -59,3 +61,14 @@ class URLStream(BaseStream):
flags = flags | self.flags_for(three_d=three_d, autofree=autofree, decode=decode) flags = flags | self.flags_for(three_d=three_d, autofree=autofree, decode=decode)
handle = bass_call(BASS_StreamCreateURL, url, offset, flags, self.downloadproc, user) handle = bass_call(BASS_StreamCreateURL, url, offset, flags, self.downloadproc, user)
super(URLStream, self).__init__(handle) 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))