试图将以下内容转换为 def 但做一些可能不允许的事情......我做错了什么,如何才能做得更好?
# Same for both
import alsaaudio
l_input = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, card='default')
r_input = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, card='default')
#
l, data = l_input.read()
if l > 0:
# transform data to logarithmic scale
lin_vu = (math.log(float(max(audioop.max(data, 2),1)))-log_lo)/(log_hi-log_lo)
# Calculate value
lin_vu = (min(max(int(lin_vu*15),0),15))
l, data = r_input.read()
if l > 0:
# transform data to logarithmic scale
rin_vu = (math.log(float(max(audioop.max(data, 2),1)))-log_lo)/(log_hi-log_lo)
# Calculate value
rin_vu = (min(max(int(rin_vu*15),0),15))
我希望做这样的事情,因为我需要读取 4 个值,而不仅仅是列出的两个:
def readvu( src ):
l, data = src.read()
if l > 0:
# transform data to logarithmic scale
l_vu = (math.log(float(max(audioop.max(data, 2),1)))-log_lo)/(log_hi-log_lo)
# Calculate value
l_vu = (min(max(int(l_vu*15),0),15))
lin_vu = readvu( 'l_input' );
rin_vu = readvu( 'r_input' );
但这会产生上述错误......