From a20c82bc9956bb5cb0a5231b7891dc1b2acad269 Mon Sep 17 00:00:00 2001 From: Sg4Dylan Date: Sun, 26 Feb 2017 19:38:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=90=84=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E5=AE=8C=E5=B7=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EmiyaEngine.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/EmiyaEngine.py b/EmiyaEngine.py index 18042b6..67fb7f6 100644 --- a/EmiyaEngine.py +++ b/EmiyaEngine.py @@ -63,37 +63,37 @@ def process_leader(self): # 生成进程池 pool = multiprocessing.Pool(processes=self.cpu_thread) # 初始化结果字典 + raw_result_dict = {} result_dict = {} # 分割时间域 - each_piece_length = round(len(self.input_signal_array[channel_index]) / self.cpu_thread) + splited_input_signal = np.array_split(self.input_signal_array[channel_index], self.cpu_thread) for i in range(self.cpu_thread): - # 计算分发分片的起始位置 - piece_start_pos = i * each_piece_length - piece_end_pos = (i + 1) * each_piece_length - if piece_end_pos > len(self.input_signal_array[channel_index]): - piece_end_pos = len(self.input_signal_array[channel_index]) - # 生成分片 - process_piece = self.input_signal_array[channel_index][piece_start_pos:piece_end_pos] # 下发分片 - result_dict[i] = pool.apply_async(self.process_core, (process_piece, i, )) + raw_result_dict[i] = pool.apply_async(self.process_core, (splited_input_signal[i], i, )) pool.close() pool.join() # 拼合分片 - # 接下来处理这里的同步拼接问题 temp_array = np.array([()]) + # 理清顺序 for i in range(self.cpu_thread): - temp_array = np.append(result_dict[i].get(), temp_array) + result_dict[raw_result_dict[i].get()[1]] = raw_result_dict[i].get()[0] + # 追加分片 + for i in range(self.cpu_thread): + temp_array = np.append(temp_array, result_dict[i]) + # 合并到各声道 if channel_index == 0: self.mid_signal_larray = temp_array else: self.mid_signal_rarray = temp_array + # 拼合左右声道 self.mid_signal_carray = np.array([self.mid_signal_larray, self.mid_signal_rarray]) + # 保存文件 self.save_file() def process_core(self, signal_piece, index): - print("Entering process Index %s" % index) - print(len(signal_piece)) - return signal_piece + + + return [signal_piece, index] def save_file(self): librosa.output.write_wav(self.output_file_path, self.mid_signal_carray, self.input_sr)