Archived
Initial commit
This commit is contained in:
commit
d89b82be4a
103 files changed
+23110
No files matched your search
@@ -0,0 +1,236 @@
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
from pick import pick
|
||||
from parse_corpus import parseCorpus
|
||||
from scipy.io import savemat
|
||||
import warnings
|
||||
from tools.load_matrix import loadmat
|
||||
|
||||
CALIBRATE = False
|
||||
|
||||
|
||||
def expe_build_conditions(options):
|
||||
options["fs"] = 44100
|
||||
options["gain"] = 0
|
||||
mat = loadmat('./calibration.mat')
|
||||
cal = mat["calibration"]
|
||||
options["attenuation_dB"] = cal["crm"]
|
||||
# options["attenuation_dB"] = 10 # Calibrated attenuation from fishy
|
||||
|
||||
options["target_corpus_language"] = options["language"]
|
||||
options["target_corpus_path"] = "./stimuli/crm/spk1F-" + \
|
||||
options["language"].lower()
|
||||
|
||||
if options["target_corpus_language"] == "tr_tr":
|
||||
options["target_corpus_filemask"] = 'cat_*.wav'
|
||||
else:
|
||||
options["target_corpus_filemask"] = 'dog_*.wav'
|
||||
|
||||
options["target_corpus"] = parseCorpus(options["target_corpus_path"],
|
||||
options["target_corpus_filemask"])
|
||||
|
||||
options["n_colours"] = len(options["target_corpus"]["colours"])
|
||||
options["n_numbers"] = len(options["target_corpus"]["numbers"])
|
||||
options["n_call_signs"] = len(options["target_corpus"]["call_signs"])
|
||||
|
||||
np.random.shuffle(options["target_corpus"]["colours"])
|
||||
|
||||
if options["target_corpus_language"] == "tr_tr":
|
||||
options["images"] = "girl+cat.jpg"
|
||||
else:
|
||||
options["images"] = "woman+dog.jpg"
|
||||
|
||||
# Masker options
|
||||
options["masker_corpus_language"] = options["language"]
|
||||
options["masker_corpus_path"] = options["target_corpus_path"]
|
||||
if options["target_corpus_language"] == "tr_tr":
|
||||
options["masker_corpus_filemask"] = "rabbit_*.wav"
|
||||
else:
|
||||
options["masker_corpus_filemask"] = "cat_*.wav"
|
||||
|
||||
lst = [
|
||||
f for f in os.listdir(options["masker_corpus_path"])
|
||||
if f.startswith(options["masker_corpus_filemask"].split('_')[0])
|
||||
and f.endswith('.wav')
|
||||
]
|
||||
options["masker_corpus"] = lst
|
||||
|
||||
options["sounds_for_calibration"] = []
|
||||
|
||||
lst = [
|
||||
f for f in os.listdir(options["target_corpus_path"])
|
||||
if f.startswith(options["target_corpus_filemask"].split('_')[0])
|
||||
and f.endswith('.wav')
|
||||
]
|
||||
|
||||
if not CALIBRATE:
|
||||
for k in range(len(lst)):
|
||||
options["sounds_for_calibration"].append(
|
||||
os.path.join(options["target_corpus_path"], lst[k]))
|
||||
|
||||
for k in range(len(options["masker_corpus"])):
|
||||
options["sounds_for_calibration"].append(
|
||||
os.path.join(options["masker_corpus_path"], lst[k]))
|
||||
else:
|
||||
for k in range(10):
|
||||
options["sounds_for_calibration"].append(
|
||||
os.path.join(options["target_corpus_path"], lst[k]))
|
||||
|
||||
for k in range(10):
|
||||
options["sounds_for_calibration"].append(
|
||||
os.path.join(options["masker_corpus_path"], lst[k]))
|
||||
|
||||
options["cache_path"] = "./stimuli_store/crm/spk1F-" + \
|
||||
options["masker_corpus_language"].lower()
|
||||
|
||||
if not os.path.exists(options["cache_path"]):
|
||||
os.makedirs(options["cache_path"])
|
||||
|
||||
options["voices"] = {}
|
||||
|
||||
i = 1
|
||||
|
||||
for dF0 in np.linspace(0, -12, 3):
|
||||
for dVTL in np.linspace(0, 3.8, 3):
|
||||
options["voices"]["v" + str(i)] = {}
|
||||
options["voices"]["v" + str(i)]["dF0"] = dF0
|
||||
options["voices"]["v" + str(i)]["dVTL"] = dVTL
|
||||
i += 1
|
||||
|
||||
options["n_voices"] = len(options["voices"])
|
||||
|
||||
# Check if NH or HI
|
||||
grp = ""
|
||||
if "subject_name" in options and options["subject_name"] != "":
|
||||
grp = options["subject_name"][0:2]
|
||||
else:
|
||||
grp = "NH"
|
||||
if grp == "NH":
|
||||
options["tmrs"] = np.array([-6, 0, 6, np.inf])
|
||||
elif grp == "HI" or grp == "CI":
|
||||
options["tmrs"] = np.array([0, 6, 12, np.inf])
|
||||
|
||||
# Strategy on hoe to change the TMR
|
||||
# - In the 'louder_constant' strategy, the TMR is such that we keep the target level constant for TMRs>0, and the masker level constant for TMRs<0
|
||||
# - In the 'constant_level' strategy, we keep the overall level constant
|
||||
|
||||
options["tmr_strategy"] = 'constant_level'
|
||||
|
||||
options["target_delay"] = 750e-3
|
||||
options["masker_end_delay"] = 250e-3
|
||||
options["masker_min_chunk_duration"] = 150e-3
|
||||
options["masker_max_chunk_duration"] = 300e-3
|
||||
options["masker_chunk_ramp"] = 2e-3
|
||||
options["masker_ramp"] = 50e-3
|
||||
|
||||
options["test"] = {}
|
||||
options["training"] = {}
|
||||
|
||||
options["test"]["n_repeat"] = 7
|
||||
options["training"]["n_repeat"] = 1
|
||||
|
||||
options["training"]["block_size"] = 20
|
||||
options["test"]["block_size"] = 30
|
||||
|
||||
test = {}
|
||||
|
||||
for i_repeat in range(options["test"]["n_repeat"]):
|
||||
for i_tmr in range(len(options["tmrs"])):
|
||||
if options["tmrs"][i_tmr] == np.inf:
|
||||
i_voices = np.array([1])
|
||||
else:
|
||||
i_voices = np.array([1, 3, 7, 9])
|
||||
|
||||
for i_voice in i_voices:
|
||||
trial = {}
|
||||
trial["target"] = {}
|
||||
|
||||
trial["target"]["colour"], trial["target"][
|
||||
"colour_index"] = pick(options["target_corpus"]["colours"])
|
||||
number, trial["target"]["number_index"] = pick(
|
||||
options["target_corpus"]["numbers"])
|
||||
|
||||
trial["target"]["number"] = int(number)
|
||||
|
||||
trial["target"]["call_sign"] = options[
|
||||
"target_corpus_filemask"].split('_')[0]
|
||||
trial["target"]["sound_file"] = '{}_{}_{}.wav'.format(
|
||||
trial["target"]["call_sign"], trial["target"]["colour"],
|
||||
trial["target"]["number"])
|
||||
|
||||
trial["image"] = options["images"][0]
|
||||
|
||||
trial["voice"] = options["voices"]["v" + str(i_voice)]
|
||||
trial["voice"]["index"] = i_voice
|
||||
|
||||
trial["i_repeat"] = i_repeat
|
||||
trial["tmr"] = options["tmrs"][i_tmr]
|
||||
trial["visual_feedback"] = 1
|
||||
trial["done"] = 0
|
||||
|
||||
if 'trials' not in test:
|
||||
test["trials"] = [trial]
|
||||
else:
|
||||
test["trials"].append(trial)
|
||||
|
||||
np.random.shuffle(test["trials"])
|
||||
|
||||
training = {}
|
||||
i = 1
|
||||
for i_repeat in range(options["training"]["n_repeat"]):
|
||||
for i_voice in range(options["n_voices"]):
|
||||
|
||||
trial = {}
|
||||
trial["target"] = {}
|
||||
|
||||
trial["target"]["colour"], trial["target"]["colour_index"] = pick(
|
||||
options["target_corpus"]["colours"])
|
||||
number, trial["target"]["number_index"] = pick(
|
||||
options["target_corpus"]["numbers"])
|
||||
|
||||
trial["target"]["number"] = int(number)
|
||||
|
||||
trial["target"]["call_sign"] = options[
|
||||
"target_corpus_filemask"].split('_')[0]
|
||||
trial["target"]["sound_file"] = '{}_{}_{}.wav'.format(
|
||||
trial["target"]["call_sign"], trial["target"]["colour"],
|
||||
trial["target"]["number"])
|
||||
|
||||
trial["image"] = options["images"][0]
|
||||
|
||||
trial["voice"] = options["voices"]["v" + str(i_voice + 1)]
|
||||
trial["voice"]["index"] = i_voice
|
||||
|
||||
trial["i_repeat"] = i_repeat
|
||||
|
||||
if i <= 2:
|
||||
trial["tmr"] = np.inf
|
||||
else:
|
||||
trial["tmr"] = 6
|
||||
i += 1
|
||||
|
||||
trial["visual_feedback"] = 1
|
||||
trial["done"] = 0
|
||||
|
||||
if 'trials' not in training:
|
||||
training["trials"] = [trial]
|
||||
else:
|
||||
training["trials"].append(trial)
|
||||
|
||||
training_short = {}
|
||||
training_short["trials"] = training["trials"][:4]
|
||||
expe = {}
|
||||
expe["test"] = test
|
||||
expe["training"] = training_short
|
||||
|
||||
if "res_filename" in options:
|
||||
savemat(options["res_filename"],
|
||||
mdict={
|
||||
"expe": expe,
|
||||
"options": options
|
||||
})
|
||||
else:
|
||||
warnings.warn("The test file was not saved: no filename provided")
|
||||
|
||||
return expe, options
|
||||
Reference in new issue
Block a user