コード例 #1
0
ファイル: __init__.py プロジェクト: slavomir-sidor/psychopy
def pyo_init(rate=44100, nchnls=1, buffersize=32, duplex=1):
    """Start and boot a global pyo server, restarting if needed.
    """
    global pyo_server
    if rate < 16000:
        raise ValueError('sample rate must be 16000 or higher')

    # re-init
    if hasattr(pyo_server, 'shutdown'):
        pyo_server.stop()
        sleep(0.25)  #make sure enough time passes for the server to shutdown
        pyo_server.shutdown()
        sleep(0.25)
        pyo_server.reinit(sr=rate,
                          nchnls=nchnls,
                          buffersize=buffersize,
                          duplex=duplex)
    else:
        pyo_server = pyo.Server(
            sr=rate,
            nchnls=nchnls,  # 1 = mono
            buffersize=buffersize,  # ideal = 64 or higher
            duplex=duplex)  # 1 = input + output
    pyo_server.boot().start()

    # avoid mac issue of losing first 0.5s if no sound played for ~1 minute:
    if sys.platform == 'darwin':
        z2 = np.zeros(2)
        _sndTable = pyo.DataTable(size=2, init=z2.T.tolist(), chnls=nchnls)
        _snd = pyo.TableRead(_sndTable, freq=rate, mul=0)
        _snd.play()
        time.sleep(0.510)
コード例 #2
0
 def __init__(self):
     self.__server = pyo.Server(sr=96000, audio="offline", nchnls=1).boot()