@@ -15,19 +15,27 @@ def core(
15
15
16
16
def hpd_n_shift (data , lpf , sft , gain ):
17
17
sr = output_sr * inter_sr
18
+ # 计算增益
19
+ gain_src = round (2 * data .shape [0 ]* sft / sr )
20
+ gain_dst = round (gain_src + 0.025 * data .shape [0 ])
21
+ src_power = np .mean (np .abs (data [gain_src :gain_dst ,:]))
18
22
# 高通滤波
19
23
b ,a = signal .butter (3 ,lpf / (sr / 2 ),'high' )
20
24
data = librosa .stft (np .asfortranarray (signal .filtfilt (b ,a ,librosa .istft (data ))))
21
25
# 拷贝频谱
22
26
shift = sft
23
- shift_point = round (shift / (sr / data .shape [0 ]))
27
+ shift = sft - lpf
28
+ shift_point = round (2 * data .shape [0 ]* shift / sr )
24
29
# 调制
25
30
for i in range (data .shape [1 ]):
26
31
update .emit (i / data .shape [1 ])
27
32
data [:,i ] = np .roll (data [:,i ], shift_point , axis = 0 )
28
- # 高通滤波
29
- data = librosa .stft (np .asfortranarray (signal .filtfilt (b ,a ,librosa .istft (data ))))
30
- data *= gain
33
+ now_power = np .mean (np .abs (data [gain_src :gain_dst ,:]))
34
+ # 应用增益
35
+ if auto_opti and no_hpf :
36
+ data /= now_power / src_power
37
+ else :
38
+ data *= gain
31
39
32
40
return data
33
41
@@ -63,6 +71,8 @@ def hpd_n_shift(data, lpf, sft, gain):
63
71
# 谐波增强模式
64
72
for chan in stft_list :
65
73
processed = np .empty (chan .shape )
74
+
75
+
66
76
if no_hpf :
67
77
print ('[CopyBand] Info: 开始频谱拷贝...' )
68
78
D_percussive = np .copy (chan )
@@ -82,15 +92,11 @@ def hpd_n_shift(data, lpf, sft, gain):
82
92
adp = processed
83
93
adp_power = np .mean (np .abs (adp ))
84
94
src_power = np .mean (np .abs (chan ))
85
- src_f = 1 - (adp_power / src_power )
86
- adp += src_f * chan
95
+ adj_factor = src_power / (adp_power + src_power )
96
+ sum_chan = np .empty (chan .shape )
97
+ sum_chan = (adp * adj_factor )+ (chan * adj_factor )
87
98
chan *= 0
88
- chan += adp
89
-
90
- # 自动 EQ 优化
91
- if auto_opti :
92
- print ('[CopyBand] Info: 自动优化进行中...' )
93
- auto_eq (stft_list , 2 * percussive_hpfc / output_sr , 2 * percussive_stf / output_sr )
99
+ chan += sum_chan
94
100
95
101
# 合并输出
96
102
print ('[CopyBand] Info: ISTFT 进行中...' )
@@ -120,41 +126,6 @@ def hpd_n_shift(data, lpf, sft, gain):
120
126
percussive_gain ,msgbox )
121
127
122
128
123
- def auto_eq (stft_list , lpf , stf ):
124
- # 产生 STFT 谱
125
- combine_stft = np .sum (np .abs (np .asarray (stft_list )), axis = (0 , 2 ))
126
- # 平滑化
127
- freq_analysis = np .log2 (combine_stft )
128
- raw_freq = signal .savgol_filter (freq_analysis , 61 , 3 )
129
-
130
- # 计算需要调整的量
131
- if stf < 0.2 :
132
- print (f'[CopyBand] ERROR: 调制频率不满足要求 (0.2<=STF<=0.9),当前 STF={ stf } ' )
133
- return
134
- # 第一步:调整下连接点增益
135
- s_pos , e_pos = round (raw_freq .shape [0 ]* (stf - 0.2 )), round (raw_freq .shape [0 ]* (stf - 0.1 ))
136
- diff_tail = np .exp2 (np .max (raw_freq [s_pos :e_pos ])- np .min (raw_freq [s_pos :e_pos ]))
137
- diff_range = np .exp2 (raw_freq [s_pos :e_pos ]- np .min (raw_freq [s_pos :e_pos ]))
138
- factor = np .ones (combine_stft .shape )
139
- factor [e_pos :] /= diff_tail
140
- factor [s_pos :e_pos ] /= diff_range + np .random .uniform (low = 0.01 , high = 0.05 , size = factor [s_pos :e_pos ].shape )
141
- # 第二步,调整上连接点增益
142
- stf += stf - lpf
143
- if stf < 0.8 :
144
- s_pos , e_pos = round (raw_freq .shape [0 ]* (stf )), round (raw_freq .shape [0 ]* (stf + 0.1 ))
145
- diff_tail = np .exp2 (np .max (raw_freq [s_pos :e_pos ])- np .min (raw_freq [s_pos :e_pos ]))
146
- factor [e_pos :] *= diff_tail * (1 - 0.05 )
147
- # 第三步:平滑化连接点
148
- avg_pos = (combine_stft [s_pos ]+ combine_stft [e_pos ])/ 2
149
- factor [s_pos :e_pos ] = avg_pos / combine_stft [s_pos :e_pos ]
150
-
151
- # 应用 EQ
152
- for chan in stft_list :
153
- newchan = np .multiply (np .copy (chan ), factor [:, np .newaxis ])
154
- chan *= 0
155
- chan += newchan
156
-
157
-
158
129
def envelope_detect (input_path ):
159
130
# 加载音频
160
131
y , sr = librosa .load (input_path ,mono = False ,sr = None )
0 commit comments