Fixed crosshair and bug when calculating the RMS of /da/s
This commit is contained in:
+14
-5
@@ -1,14 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
sys.path.insert(0, "../matrix_test/helper_modules")
|
||||
|
||||
from pysndfile import sndio
|
||||
import numpy as np
|
||||
import pdb
|
||||
import matplotlib.pyplot as plt
|
||||
from pathops import dir_must_exist
|
||||
|
||||
def main():
|
||||
'''
|
||||
'''
|
||||
def gen_da_stim(n, outpath):
|
||||
da_file = './BioMAP_da-40ms.wav'
|
||||
da_stim, fs, enc, fmt = sndio.read(da_file, return_format=True)
|
||||
prestim_size = 0.0158
|
||||
@@ -20,9 +21,17 @@ def main():
|
||||
y_part_inv = -y_part
|
||||
|
||||
y_2part = np.concatenate([y_part, y_part_inv])
|
||||
y = np.tile(y_2part, 1500)
|
||||
sndio.write('./3000_da.wav', y, rate = fs, format = fmt, enc=enc)
|
||||
y = np.tile(y_2part, n)
|
||||
sndio.write(outpath, y, rate = fs, format = fmt, enc=enc)
|
||||
return outpath
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
'''
|
||||
'''
|
||||
dir_must_exist('./stimulus')
|
||||
gen_da_stim(1500, './stimulus/3000_da.wav')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
+65
-7
@@ -12,7 +12,8 @@ from shutil import copy2
|
||||
|
||||
from test_base import BaseThread
|
||||
|
||||
from matrix_test.helper_modules.signalops import play_wav
|
||||
from matrix_test.helper_modules.signalops import play_wav, block_mix_wavs
|
||||
from pathops import dir_must_exist
|
||||
from scipy.special import logit
|
||||
from config import socketio
|
||||
import csv
|
||||
@@ -38,21 +39,32 @@ class DaTestThread(BaseThread):
|
||||
Thread for running server side matrix test operations
|
||||
'''
|
||||
def __init__(self, sessionFilepath=None,
|
||||
stimFolder='./da_stim/', nTrials=2,
|
||||
socketio=None, participant=None, srt_50=None, s_50=None):
|
||||
stimFolder='./da_stim/',
|
||||
noiseFilepath="./matrix_test/behavioural_stim/stimulus/wav/noise/noise.wav",
|
||||
noiseRMSFilepath="./matrix_test/behavioural_stim/stimulus/rms/noise_rms.npy",
|
||||
red_coef="./matrix_test/short_concat_stim/out/reduction_coef.npy",
|
||||
nTrials=2, socketio=None, participant=None, srt_50=None,
|
||||
s_50=None):
|
||||
|
||||
self.reduction_coef = np.load(red_coef)
|
||||
self.wav_file = os.path.join(stimFolder, '3000_da.wav')
|
||||
self.noise_path = noiseFilepath
|
||||
self.noise_rms = np.load(noiseRMSFilepath)
|
||||
self.stim_folder = stimFolder
|
||||
self.stim_paths = []
|
||||
|
||||
self.test_name = 'da_test'
|
||||
self.nTrials = nTrials
|
||||
self.trial_ind = 0
|
||||
self._stopevent = Event()
|
||||
self.si = np.array([20.0, 35.0, 50.0, 65.0, 80.0, 90.0, 100.0])
|
||||
|
||||
super(DaTestThread, self).__init__(self.test_name,
|
||||
sessionFilepath=sessionFilepath,
|
||||
socketio=socketio,
|
||||
participant=participant)
|
||||
|
||||
self.toSave = ['trial_ind', 'nTrials', 'wav_file', 'test_name']
|
||||
self.toSave = ['trial_ind', 'nTrials', 'wav_file', 'test_name', 'si']
|
||||
|
||||
self.socketio.on_event('finalise_results', self.finaliseResults, namespace='/main')
|
||||
|
||||
@@ -65,17 +77,18 @@ class DaTestThread(BaseThread):
|
||||
'''
|
||||
self.waitForPageLoad()
|
||||
self.socketio.emit('test_ready', namespace='/main')
|
||||
for self.trial_ind in range(self.nTrials):
|
||||
for wav in self.stim_paths[self.trial_ind:]:
|
||||
self.displayInstructions()
|
||||
self.waitForPartReady()
|
||||
if self._stopevent.isSet() or self.finishTest:
|
||||
break
|
||||
# Play concatenated matrix sentences at set SNR
|
||||
self.playStimulus(self.wav_file)
|
||||
self.saveState(out=self.backupFilepath)
|
||||
self.playStimulus(wav)
|
||||
self.saveState(out=self.backupFilepath)
|
||||
if not self._stopevent.isSet():
|
||||
self.unsetPageLoaded()
|
||||
self.socketio.emit('processing-complete', namespace='/main')
|
||||
self.waitForPageLoad()
|
||||
|
||||
|
||||
def displayInstructions(self):
|
||||
@@ -100,6 +113,51 @@ class DaTestThread(BaseThread):
|
||||
def loadStimulus(self):
|
||||
'''
|
||||
'''
|
||||
self.participant.load('mat_test')
|
||||
try:
|
||||
srt_50=self.participant.data['mat_test']['srt_50']
|
||||
s_50=self.participant.data['mat_test']['s_50']
|
||||
except KeyError:
|
||||
raise KeyError("Behavioural matrix test results not available, make "
|
||||
"sure the behavioural test has been run before "
|
||||
"running this test.")
|
||||
|
||||
#reduction_coef = float(np.load(os.path.join(self.listDir, 'reduction_coef.npy')))
|
||||
|
||||
# Calculate SNRs based on behavioural measures
|
||||
s_50 *= 0.01
|
||||
shuffle(self.si)
|
||||
x = logit(self.si * 0.01)
|
||||
snrs = (x/(4*s_50))+srt_50
|
||||
self.snr_fs = 10**(-snrs/20)
|
||||
self.snr_fs[self.snr_fs == np.inf] = 0.
|
||||
if (self.snr_fs == -np.inf).any():
|
||||
raise ValueError("Noise infinitely louder than signal for an SNR (SNRs: {})".format(self.snr_fs))
|
||||
|
||||
|
||||
wavs = globDir(self.stim_folder, "3000_da.wav") * len(self.si)
|
||||
rms_files = globDir(self.stim_folder, "overall_da_rms.npy") * len(self.si)
|
||||
|
||||
self.socketio.emit('test_stim_load', namespace='/main')
|
||||
# Add noise to audio files at set SNRs and write to participant
|
||||
# directory
|
||||
self.data_path = self.participant.data_paths[self.test_name]
|
||||
out_dir = os.path.join(self.data_path, "stimulus")
|
||||
out_info = os.path.join(out_dir, "stim_info.csv")
|
||||
dir_must_exist(out_dir)
|
||||
|
||||
with open(out_info, 'w') as csvfile:
|
||||
writer = csv.writer(csvfile)
|
||||
writer.writerow(['wav', 'snr_fs', 'rms', 'si', 'snr'])
|
||||
for wav, snr_fs, rms, si, snr in zip(wavs, self.snr_fs, rms_files, self.si, snrs):
|
||||
fp = os.path.splitext(os.path.basename(wav))[0]+"_{}.wav".format(snr)
|
||||
out_wavpath = os.path.join(out_dir, fp)
|
||||
stim_rms = np.load(rms)
|
||||
match_ratio = stim_rms/self.noise_rms
|
||||
block_mix_wavs(wav, self.noise_path, out_wavpath, 1.*self.reduction_coef, snr_fs*match_ratio*self.reduction_coef)
|
||||
self.stim_paths.extend([out_wavpath] * self.nTrials)
|
||||
writer.writerow([wav, snr_fs, rms, si, snr])
|
||||
# TODO: Output SI/snrs of each file to a CSV file
|
||||
#audio, fs, enc, fmt = sndio.read(wav, return_format=True)
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from threading import Thread, Event
|
||||
import os
|
||||
import numpy as np
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ class EEGTestThread(BaseThread):
|
||||
'''
|
||||
def __init__(self, sessionFilepath=None,
|
||||
listFolder="./matrix_test/short_concat_stim/out",
|
||||
noiseFilepath="./matrix_test/stimulus/wav/noise/noise.wav",
|
||||
noiseFilepath="./matrix_test/behavioural_stim/stimulus/wav/noise/noise.wav",
|
||||
socketio=None, participant=None, srt_50=None, s_50=None):
|
||||
self.noise_path = noiseFilepath
|
||||
self.listDir = listFolder
|
||||
|
||||
@@ -209,6 +209,7 @@ def gen_noise(OutDir, b, fs, s_rms):
|
||||
def calc_speech_rms(files, silences, rmsDir, fs=44100, plot=False):
|
||||
'''
|
||||
'''
|
||||
pdb.set_trace()
|
||||
f = sum(files, [])
|
||||
sumsqrd = 0.0
|
||||
n = 0
|
||||
|
||||
@@ -20,6 +20,16 @@
|
||||
z-index: 15; /* Specify a stack order in case you're using a different order for other elements */
|
||||
font-size: xx-large;
|
||||
}
|
||||
#overlay > span {
|
||||
display: none; /* Hidden by default */
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%) translateY(-50%);
|
||||
color: white; /* Black background with opacity */
|
||||
z-index: 15; /* Specify a stack order in case you're using a different order for other elements */
|
||||
font-size: xx-large;
|
||||
}
|
||||
|
||||
#instructions {
|
||||
position: fixed; /* Sit on top of the page content */
|
||||
|
||||
Reference in New Issue
Block a user