Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PyBASS_FX Example Wrapper
'''
This is a simple wrapper for BASS FX in Python, based on PyBASS.
It's incomplete code, but demonstrates basic functionality of the FX plugin in Python.
Feel free to do whatever you like with this. Make it your own.
More info: http://mediarealm.com.au/articles/2014/08/un4seen-bass-audio-library-python/
'''
if platform.system().lower() == 'windows':
fx_module = ctypes.WinDLL('./libbass_fx.dll')
fx_func_type = ctypes.WINFUNCTYPE
else:
fx_module = ctypes.CDLL('./libbass_fx.so')
fx_func_type = ctypes.CFUNCTYPE
BASS_FX_GetVersion = func_type(ctypes.c_ulong)(('BASS_FX_GetVersion', fx_module))
BASS_FX_BFX_ROTATE = 0x10000
BASS_FX_BFX_ECHO = 0x10001
BASS_FX_BFX_FLANGER = 0x10002
BASS_FX_BFX_VOLUME = 0x10003
BASS_FX_BFX_PEAKEQ = 0x10004
BASS_FX_BFX_MIX = 0x10005
BASS_FX_BFX_DAMP = 0x10006
BASS_FX_BFX_AUTOWAH = 0x10007
BASS_FX_BFX_ECHO2 = 0x10008
BASS_FX_BFX_PHASER = 0x10009
BASS_FX_BFX_CHORUS = 0x10010
BASS_FX_BFX_DISTORTION = 0x10011
BASS_FX_BFX_COMPRESSOR2 = 0x10012
BASS_FX_BFX_VOLUME_ENV = 0x10013
BASS_FX_BFX_BQF = 0x10014
BASS_FX_BFX_ECHO4 = 0x10015
BASS_ATTRIB_TEMPO = 0x10000
BASS_FX_FREESOURCE = 0x10000
BASS_FX_TempoCreate = func_type(HSTREAM, ctypes.c_ulong)(('BASS_FX_TempoCreate', fx_module))
#This must be called for the FX stuff to work:
BASS_FX_GetVersion()
###########################################################
#Below is a example of time stretching in Un4Seen BASS FX
BASS_Init(-1, 44100, 0, 0, 0)
filePlayerHandle = BASS_StreamCreateFile(False, fileName, 0, 0, BASS_STREAM_DECODE)
tempoChannel = BASS_FX_TempoCreate(filePlayerHandle, BASS_FX_FREESOURCE)
BASS_ChannelSetAttribute(tempoChannel, BASS_ATTRIB_TEMPO, 100)
if not BASS_ChannelPlay(tempoChannel, False):
print('BASS_ChannelPlay error %s' % get_error_description(BASS_ErrorGetCode()))
else:
print "Started playing..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment