belangeo / pyo

Python DSP module

Home Page:http://ajaxsoundstudio.com/software/pyo/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unanticipated Host Error

chigkim opened this issue · comments

If I run the following code, I get this error after playing for a few seconds and stuttering.
Portaudio error in Pa_AbortStream (pa_stop): Unanticipated host error
Portaudio error in Pa_CloseStream (pa_deinit): PortAudio not initialized
Portaudio error in Pa_Terminate (pa_deinit): PortAudio not initialized
Pyo error: Error closing audio backend.

import numpy as np
n = 20
# I get data from files, but I use random for this demo.
data = np.random.random((n, n))
panData = np.random.random(n)
speed = 0.5
from pyo import *
import time
s = Server()
s.boot()
s.start()
pink = PinkNoise()
split = BandSplit(pink, num=n, q=500)
panTableReader = TableRead(DataTable(n, init=panData.tolist()), freq=speed, loop=1, interp=1)
dataTableReader = [TableRead(DataTable(n, init=data[i].tolist()), freq=speed, loop=1, interp=1) for i in range(n)]
pans = []
for i in range(n):
	pans.append(SPan(split[i], pan=panTableReader.play(), mul=dataTableReader[i].play()).out())
time.sleep(3)
exit()

You should exit your program more gracefully than simply exit() after a given time. A good habit is to stop the audio server before leaving the program.

Instead of:

time.sleep(3)
exit()

You can try something like:

time.sleep(3)
s.stop()
time.sleep(.2)
exit()