我有代码来生成和导出12个立体声WAV
目前我只是在做:
for i in range(0,12):
filename = "out_%d.wav" % i
L = ... some list of floats between -1.0 and +1.0 ...
R = ... similarly ...
exportWAV(filename,L,R)
但是音量太小了.
我需要做的是找到所有L& R,然后将所有L& R按此卷.然后,我所有的值都将在-1和1之间.
这不是一项艰巨的任务,我可以破解一些丑陋的代码来完成它.
但是如何做到干净呢?
我应该能够在几行中做到这一点,例如:
all_LR = ''
all_file = ''
for i in range(0,12):
filename = ...
L, R = ...
all_LR += (L,R)
all_file += filename
maxVal = max( abs(all_LR) )
all_LR /= maxVal
for file,L,R in zip( all_file, all_LR ):
exportWAV(filename L,R)
但我看不到如何将此伪代码转换为实际的有效Python. abs和max不会对元组数组进行操作,其中元组中的每个元素本身都是浮点数组.
我觉得我正在通过尝试保存几行代码来使其变得比原来更加困难.
编辑:由于下面的答案,我现在有以下工作代码:
all_LR = []
for i in range(0,12):
print "Processing %d" % i
hrtf_file = hrtf_path + "/%02d.wav" % (i+1)
shep_file = shepard_path + "/shepard_%02d.WAV" % i
L, R = import_WAV( hrtf_file )
shep = import_WAV( shep_file )
out_L = np.convolve(shep,L)
out_R = np.convolve(shep,R)
#out_LR = np.array( out_L, out_R )
out_LR = (list(out_L), list(out_R))
all_LR.append(out_LR)
#np.append( all_LR, out_LR )
np_array = np.array(all_LR)
amp_max = np.amax( np.fabs(np_array) )
print( "AmpMAX: %f" % amp_max )
np_array /= amp_max
for i in range(0,12):
out_file = out3d_path + "/s3D_%02d.WAV" % i
print out_file
L,R = np_array[i]
export_WAV( out_file, L, R )