-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Sg4Dylan/dev
Stage version
- Loading branch information
Showing
12 changed files
with
1,192 additions
and
959 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ui": "res/window.ui", | ||
"lang": "chs", | ||
"eng": "res/eng.qm", | ||
"chs": "res/chs.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import random | ||
import librosa | ||
import resampy | ||
#from tqdm import tqdm | ||
|
||
|
||
def core( | ||
input_path,output_path, | ||
output_sr=48000,inter_sr=1, | ||
test_mode=False, | ||
sv_l=0.02,sv_h=0.55, | ||
update=None | ||
): | ||
|
||
# 加载音频 | ||
y, sr = librosa.load(input_path,mono=False,sr=None) | ||
if test_mode: | ||
y, sr = librosa.load(input_path,mono=False,sr=None,offset=round(len(y[0])/sr/2),duration=5) | ||
y = resampy.resample(y, sr, output_sr * inter_sr, filter='kaiser_fast') | ||
|
||
# AkkoMode | ||
for chan in y: | ||
# 是否第一次执行 | ||
is_loop_once = True | ||
# 前一次的数值 | ||
pre_value = 0 | ||
# 前一次操作的数值 | ||
pre_opt = 0 | ||
# 实际操作 | ||
#for i in tqdm(range(len(chan)),unit='Segment',ascii=True): | ||
for i in range(len(chan)): | ||
update.emit(i/len(chan)) | ||
this_value = chan[i] | ||
# 构造抖动值 | ||
linear_jitter = 0 | ||
if pre_value < this_value: | ||
linear_jitter = random.uniform(this_value*-sv_l, this_value*sv_h) | ||
else: | ||
linear_jitter = random.uniform(this_value*sv_h, this_value*-sv_l) | ||
# 应用抖动 | ||
if pre_opt*linear_jitter > 0: | ||
chan[i] = this_value + linear_jitter | ||
elif pre_opt*linear_jitter < 0: | ||
chan[i] = this_value - linear_jitter | ||
else: | ||
pass | ||
# 第一次操作特殊化处理 | ||
if is_loop_once: | ||
linear_jitter = random.uniform(this_value*-sv_h, this_value*sv_h) | ||
chan[i] += linear_jitter | ||
is_loop_once = False | ||
# 保存到上一次记录 | ||
pre_value = this_value | ||
pre_opt = linear_jitter | ||
|
||
# 合并输出 | ||
final_data = resampy.resample(y, | ||
output_sr * inter_sr, | ||
output_sr, | ||
filter='kaiser_fast') | ||
librosa.output.write_wav(output_path, final_data, output_sr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import numpy as np | ||
import scipy.signal as signal | ||
import librosa | ||
import resampy | ||
#from tqdm import tqdm | ||
|
||
|
||
def core( | ||
input_path,output_path, | ||
output_sr=48000,inter_sr=1, | ||
test_mode=False, | ||
harmonic_hpfc=6000,harmonic_sft=16000,harmonic_gain=1.2, | ||
percussive_hpfc=6000,percussive_stf=16000,percussive_gain=2.5, | ||
update=None | ||
): | ||
|
||
def hpd_n_shift(data, lpf, sft, gain): | ||
# 高通滤波 | ||
b,a = signal.butter(3,lpf/(sr/2),'high') | ||
data = librosa.stft(signal.filtfilt(b,a,librosa.istft(data))) | ||
# 拷贝频谱 | ||
#for i in tqdm(range(data.shape[1]),unit='Segment',ascii=True): | ||
for i in range(data.shape[1]): | ||
update.emit(i/data.shape[1]) | ||
shift = sft | ||
shift_point = round(shift/(sr/data.shape[0])) | ||
# 调制 | ||
for p in reversed(range(len(chan[:,i]))): | ||
data[:,i][p] = data[:,i][p-shift_point] | ||
# 高通滤波 | ||
data = librosa.stft(signal.filtfilt(b,a,librosa.istft(data))) | ||
data *= gain | ||
return data | ||
|
||
# 加载音频 | ||
y, sr = librosa.load(input_path,mono=False,sr=None) | ||
if test_mode: | ||
y, sr = librosa.load(input_path,mono=False,sr=None,offset=round(len(y[0])/sr/2),duration=5) | ||
y = resampy.resample(y, sr, output_sr * inter_sr, filter='kaiser_fast') | ||
# 产生 STFT 谱 | ||
stft_list = [librosa.stft(chan) for chan in y] | ||
|
||
# 谐波增强模式 | ||
for chan in stft_list: | ||
D_harmonic,D_percussive = librosa.decompose.hpss(chan, margin=4) | ||
D_harmonic = hpd_n_shift(D_harmonic,harmonic_hpfc,harmonic_sft,harmonic_gain) | ||
D_percussive = hpd_n_shift(D_percussive,percussive_hpfc,percussive_stf,percussive_gain) | ||
chan += D_harmonic | ||
chan += D_percussive | ||
|
||
# 合并输出 | ||
istft_list = [librosa.istft(chan) for chan in stft_list] | ||
final_data = resampy.resample(np.array(istft_list), | ||
output_sr * inter_sr, | ||
output_sr, | ||
filter='kaiser_fast') | ||
librosa.output.write_wav(output_path, final_data, output_sr) |
Oops, something went wrong.