Example #1
0
def init(freq=48000):
    """
Initialize BASS and the opus plugin
    """
    global dll, use_ctypes
    if not dll:
        if platform.system() == "Darwin":
            dll = ctypes.CDLL(dllf)
            use_ctypes = True
        else:
            import pybass as dll

    dll.BASS_Init(ini.read_ini_int("aaio.ini", "Audio", "device", -1), freq, 0,
                  0, 0)
    dll.BASS_PluginLoad(os.path.abspath(opus), 0)
Example #2
0
    def __init__(self, *args, **kwargs):

        self.stream = kwargs.pop('stream', None)
        self.name_stream = kwargs.pop('name_stream', 'memory_stream')
        self.bass_handle = 0
        self.sound_font = 0

        result = pybass.BASS_Init(-1, 44100, 0, 0, 0)
        if not result:
            bass_error_code = pybass.BASS_ErrorGetCode()
            if bass_error_code != pybass.BASS_ERROR_ALREADY:
                self.slider.Enable(False)
                self.btn_play.Enable(False)
                self.btn_stop.Enable(False)
                print('BASS_Init error %s' %
                      pybass.get_error_description(bass_error_code))
        self.plugins = {}
        self.plugins['aac'] = (pybass.BASS_PluginLoad('bass_aac.dll',
                                                      0), '|AAC|*.aac')
        self.plugins['ac3'] = (pybass.BASS_PluginLoad('bass_ac3.dll',
                                                      0), '|AC3|*.ac3')
        self.plugins['aix'] = (pybass.BASS_PluginLoad('bass_aix.dll',
                                                      0), '|AIX|*.aix')
        self.plugins['ape'] = (pybass.BASS_PluginLoad('bass_ape.dll',
                                                      0), '|APE|*.ape')
        self.plugins['mpc'] = (pybass.BASS_PluginLoad('bass_mpc.dll',
                                                      0), '|MPC|*.mpc')
        self.plugins['ofr'] = (pybass.BASS_PluginLoad('bass_ofr.dll',
                                                      0), '|OFR|*.ofr')
        self.plugins['spx'] = (pybass.BASS_PluginLoad('bass_spx.dll',
                                                      0), '|SPX|*.spx')
        self.plugins['tta'] = (pybass.BASS_PluginLoad('bass_tta.dll',
                                                      0), '|TTA|*.tta')
        self.plugins['cda'] = (pybass.BASS_PluginLoad('basscd.dll',
                                                      0), '|CDA|*.cda')
        self.plugins['flac'] = (pybass.BASS_PluginLoad('bassflac.dll',
                                                       0), '|FLAC|*.flac')
        self.plugins['wma'] = (pybass.BASS_PluginLoad('basswma.dll', 0),
                               '|WMA, WMV|*.wma;*.wmv')
        if pybassmidi:
            sound_font_file_name = 'CT4MGM.SF2'
            self.sound_font = pybassmidi.BASS_MIDI_FontInit(
                sound_font_file_name, 0)
            if self.sound_font == 0:
                print(
                    'BASS_MIDI_FontInit error %s (sound font file must be %s)'
                    % (pybass.get_error_description(
                        pybass.BASS_ErrorGetCode()), sound_font_file_name))
            else:
                self.plugins['midi'] = (pybass.BASS_PluginLoad(
                    'bassmidi.dll', 0), '|MID|*.mid')
        else:
            print('pybassmidi module not accessible')

        wx.Panel.__init__(self, *args, **kwargs)

        sizer_h = wx.BoxSizer(wx.HORIZONTAL)

        self.btn_play = wx.Button(self,
                                  wx.ID_ANY,
                                  _('Play'),
                                  style=wx.NO_BORDER)
        self.btn_play.SetToolTip(_('Play media data'))
        self.Bind(wx.EVT_BUTTON, self.event_play, self.btn_play)
        sizer_h.Add(self.btn_play)

        self.btn_stop = wx.Button(self,
                                  wx.ID_ANY,
                                  _('Stop'),
                                  style=wx.NO_BORDER)
        self.Bind(wx.EVT_BUTTON, self.event_stop, self.btn_stop)
        sizer_h.Add(self.btn_stop)

        self.btn_open = wx.Button(self,
                                  wx.ID_OPEN,
                                  _('Open'),
                                  style=wx.NO_BORDER)
        self.Bind(wx.EVT_BUTTON, self.event_open, self.btn_open)
        sizer_h.Add(self.btn_open)

        sizer_v = wx.BoxSizer(wx.VERTICAL)

        self.status_line = Ticker(self,
                                  fgcolor='#000062',
                                  bgcolor='#7F7F8F',
                                  start=False,
                                  ppf=1,
                                  fps=50,
                                  direction='ltr')
        sizer_v.Add(self.status_line, 0, wx.EXPAND)

        self.slider = slider_ctrl(self, wx.ID_ANY, 0, 0, 1)
        sizer_v.Add(self.slider, 0, wx.EXPAND)

        sizer_v.Add(sizer_h)

        self.SetSizer(sizer_v)
        self.SetAutoLayout(True)

        self.volume_slider = wx.Slider(self, wx.ID_ANY,
                                       pybass.BASS_GetVolume() * 100, 0, 100)
        self.Bind(wx.EVT_SCROLL, self.event_volume_slider, self.volume_slider)
        sizer_h.Add(self.volume_slider, 0, wx.EXPAND)

        self.method_check_controls()
Example #3
0
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 libloader

bassflac_module = libloader.load_library('bassflac',
                                         x86_path=x86_path,
                                         x64_path=x64_path)
func_type = libloader.get_functype()
#Register the plugin with the Bass plugin system.
pybass.BASS_PluginLoad(
    libloader.find_library_path('bassflac',
                                x86_path=x86_path,
                                x64_path=x64_path), 0)

QWORD = pybass.QWORD
HSTREAM = pybass.HSTREAM
DOWNLOADPROC = pybass.DOWNLOADPROC
BASS_FILEPROCS = pybass.BASS_FILEPROCS

# BASS_CHANNELINFO type
BASS_CTYPE_STREAM_FLAC = 0x10900
BASS_CTYPE_STREAM_FLAC_OGG = 0x10901

#HSTREAM BASSFLACDEF(BASS_FLAC_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
BASS_FLAC_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p,
                                       QWORD, QWORD, ctypes.c_ulong)(
                                           ('BASS_FLAC_StreamCreateFile',