Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
global pyoSndServer, Sound, audioDriver, duplex, maxChnls
Sound = SoundPyo
global pyo
try:
assert pyo
except NameError: # pragma: no cover
import pyo
# can be needed for microphone.switchOn(), which calls init even
# if audioLib is something else
# subclass the pyo.Server so that we can insert a __del__ function that
# shuts it down skip coverage since the class is never used if we have
# a recent version of pyo
class _Server(pyo.Server): # pragma: no cover
# make libs class variables so they don't get deleted first
core = core
logging = logging
def __del__(self):
self.stop()
# make sure enough time passes for the server to shutdown
self.core.wait(0.5)
self.shutdown()
# make sure enough time passes for the server to shutdown
self.core.wait(0.5)
# this may never get printed
self.logging.debug('pyo sound server shutdown')
if '.'.join(map(str, pyo.getVersion())) < '0.6.4':
Server = _Server
else:
def pyo_server(debug=False):
"""
Returns a booted and started pyo audio server
Warning:
Use of pyo is generally discouraged due to dropout issues and
the general opacity of the module.
Args:
debug (bool): If true, setVerbosity of pyo server to 8.
"""
# Jackd should already be running from the launch script created by setup_pilot, we we just
pyo_server = pyo.Server(audio='jack', nchnls=int(prefs.NCHANNELS),
duplex=0, buffersize=4096, sr=192000, ichnls=0)
# Deactivate MIDI because we don't use it and it's expensive
pyo_server.deactivateMidi()
# We have to set pyo to not automatically try to connect to inputs when there aren't any
pyo_server.setJackAuto(False, True)
# debug
if debug:
pyo_server.setVerbosity(8)
# Then boot and start
pyo_server.boot()
pyo_server.start()
def initializeAudio(self):
self.audioServer = Server(audio='jack')
self.audioServer.boot()
self.audioServer.start()
self.reloadAudioFile()
self.audioInitialized = True
def pyo_server(debug=False):
"""
:param debug:
:return:
"""
# Jackd should already be running from the launch script created by setup_pilot, we we just
pyo_server = pyo.Server(audio='jack', nchnls=int(prefs.NCHANNELS),
duplex=0, buffersize=4096, sr=192000, ichnls=0)
# Deactivate MIDI because we don't use it and it's expensive
pyo_server.deactivateMidi()
# We have to set pyo to not automatically try to connect to inputs when there aren't any
pyo_server.setJackAuto(False, True)
# debug
if debug:
pyo_server.setVerbosity(8)
# Then boot and start
pyo_server.boot()
pyo_server.start()
# Note: To use this example, you will need the pyo library.
# Download link : http://pyo.googlecode.com
# PYMT Plugin integration
IS_PYMT_PLUGIN = True
PLUGIN_TITLE = 'Sine Player'
PLUGIN_AUTHOR = 'Nathanaël Lécaudé'
PLUGIN_DESCRIPTION = 'This plugin is a demonstration of the integration between pymt and the pyo library.'
from pymt import *
from OpenGL.GL import *
import pyo
# will not work if 2 app use pyo
pyo_server = pyo.Server(nchnls=2).boot()
pyo_count = 0
def pymt_plugin_activate(w, ctx):
ctx.c = MTWidget()
# We initialize the pyo server.
global pyo_count
pyo_count += 1
if pyo_count == 1:
pyo_server.start()
# We create 4 lists which will contain our sliders (to control pitch),
# buttons (to trigger the sound), pyo sine waves and fader objects.
sliders = []
buttons = []
sines = []
def pymt_plugin_activate(w, ctx):
ctx.c = MTWidget()
# We initialize the pyo server.
ctx.s = pyo.Server(nchnls = 2).boot()
ctx.s.start()
widget_size = (w.size[0]/25, w.size[1] / 2)
# We create 4 lists which will contain our sliders (to control pitch), buttons (to trigger the sound), pyo sine waves and fader objects.
sliders = []
buttons = []
sines = []
faders = []
vlayouts = []
hlayout = MTBoxLayout(spacing = w.size[0] / 5)
hlayout.pos = (w.size[0] * 0.20, w.size[1] * 0.20)
# We create 4 instances of each of the above
def initialize_sound(self):
s = pyo.Server(audio='jack').boot()
s.start()
return s
def init_pyo(self):
# -- Initialize sound generator (pyo) --
print 'Creating pyo server.'
if USEJACK:
self.pyoServer = pyo.Server(audio='jack').boot()
else:
self.pyoServer = pyo.Server(audio='offline').boot()
self.pyoServer.recordOptions(dur=0.1, filename='/tmp/tempsound.wav',
fileformat=0, sampletype=0)
'''
self.pyoServer = pyo.Server(sr=SAMPLING_RATE, nchnls=N_CHANNELS,
buffersize=BUFFER_SIZE,
duplex=0, audio='jack').boot()
'''
self.pyoServer.start()
print 'Pyo server ready'
def __init__(self, **config):
super(BinauralBeat, self).__init__(**config)
self.server = pyo.Server(buffersize=1024).boot()
centerFreq = pyo.Sig(256)
binauralFreq = pyo.Sine(freq=0.05, add=10.5, mul=1.5)
left = pyo.Sine(freq=centerFreq - binauralFreq / 2)
right = pyo.Sine(freq=centerFreq + binauralFreq / 2)
left.out(chnl=0)
right.out(chnl=1)
#left = pyo.PinkNoise().mix(2).out()
import thread
thread.start_new_thread(self.server.start, ())
self.left = left
self.right = right