Skip to content

Commit

Permalink
Makes simulation ready
Browse files Browse the repository at this point in the history
  • Loading branch information
fakufaku committed Apr 30, 2020
1 parent 8e1488b commit 77717f5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ dependencies:
- pip
- seaborn
- pip:
- mir_eval
- repsimtools
- pyroomacoustics
1 change: 1 addition & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
Y, n_iter = bss_scale.minimum_distortion(
Y, X[:, :, REF_MIC], p=args.p, q=args.q
)
print("minimum distortion iterations:", n_iter)
elif args.algo not in dereverb_algos:
Y = bss_scale.projection_back(Y, X[:, :, REF_MIC])

Expand Down
2 changes: 1 addition & 1 deletion experiment1_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"minimum_distortion": {
"p_list": [0.1, 2.0, 20],
"kwargs": {
"rtol": 1e-5,
"rtol": 1e-2,
"max_iter": 100
}
},
Expand Down
2 changes: 1 addition & 1 deletion experiment2_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"minimum_distortion": {
"p_list": [0.1, 2.0, 20],
"kwargs": {
"rtol": 1e-5,
"rtol": 1e-2,
"max_iter": 100
}
},
Expand Down
3 changes: 3 additions & 0 deletions paper_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def one_loop(args):
sys.path.append(parameters["base_dir"])
from process import process

res = process(args, parameters)
"""
try:
res = process(args, parameters)
Expand All @@ -70,6 +72,7 @@ def one_loop(args):
f.write(",\n")
res = []
"""

return res

Expand Down
16 changes: 9 additions & 7 deletions process.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def process(args, config):

ref_mic = config["ref_mic"]
metadata_fn = Path(config["metadata_fn"])
dataset_dir = Path(*metadata_fn.absolute().parts[:-2])
dataset_dir = metadata_fn.parent

with open(config["metadata_fn"], "r") as f:
metadata = json.load(f)
Expand All @@ -73,15 +73,15 @@ def process(args, config):

# add the noise
sigma_src = np.std(mix)
sigma_n = sigma_src * 10 ** (-args.snr / 20)
sigma_n = sigma_src * 10 ** (-config["snr"] / 20)
mix += np.random.randn(*mix.shape) * sigma_n

# the reference
if bss_algo_name in dereverb_algos:
# for dereverberation algorithms we use the anechoic reference signal
fn_ref = dataset_dir / rooms[room_id]["anechoic_filenames"][REF_MIC]
fn_ref = dataset_dir / rooms[room_id]["anechoic_filenames"][config["ref_mic"]]
else:
fn_ref = dataset_dir / rooms[room_id]["src_filenames"][REF_MIC]
fn_ref = dataset_dir / rooms[room_id]["src_filenames"][config["ref_mic"]]
fs, ref = load_audio(fn_ref)

# STFT parameters
Expand All @@ -102,15 +102,17 @@ def process(args, config):

runtime_bss = time.perf_counter()
if bss_algo_name == "fastmnmf":
Y = bss_algorithms[bss_name](X, n_iter=n_iter_p_ch * n_channels, **bss_kwargs)
Y = bss_algorithms[bss_algo_name](
X, n_iter=n_iter_p_ch * n_channels, **bss_kwargs
)
elif bss_algo_name in dereverb_algos:
Y, Y_pb, runtime_pb = bss_algorithms[bss_name](
Y, Y_pb, runtime_pb = bss_algorithms[bss_algo_name](
X, n_iter=n_iter_p_ch * n_channels, proj_back_both=True, **bss_kwargs
)
# adjust start time to remove the projection back
runtime_bss += runtime_pb
else:
Y = bss_algorithms[bss_name](
Y = bss_algorithms[bss_algo_name](
X, n_iter=n_iter_p_ch * n_channels, proj_back=False, **bss_kwargs
)
runtime_bss = time.perf_counter() - runtime_bss
Expand Down

0 comments on commit 77717f5

Please sign in to comment.