Skip to content

Commit 1b1a7ff

Browse files
Merge pull request #22 from marcobarilari/marco_audio-file-load
update loadAudioFiles and doAuditoryMotion for the new sounds
2 parents b846970 + 36f29f6 commit 1b1a7ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+128
-51
lines changed

audioLocTranslational.m

+7-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@
8282
% set direction, speed of that event and if it is a target
8383
thisEvent.trial_type = cfg.design.blockNames{iBlock};
8484
thisEvent.direction = cfg.design.directions(iBlock, iEvent);
85-
% thisEvent.speed = cfg.design.speeds(iBlock, iEvent);
86-
thisEvent.target = cfg.design.fixationTargets(iBlock, iEvent);
85+
thisEvent.fixationTarget = cfg.design.fixationTargets(iBlock, iEvent);
86+
87+
% % % WIP % % %
88+
89+
% thisEvent.soundTarget = cfg.design.soundTargets(iBlock, iEvent);
90+
91+
% % % WIP % % %
8792

8893
% we wait for a trigger every 2 events
8994
if cfg.pacedByTriggers.do && mod(iEvent, 2) == 1
-207 KB
Binary file not shown.
-103 KB
Binary file not shown.
-207 KB
Binary file not shown.
-103 KB
Binary file not shown.
-207 KB
Binary file not shown.
-103 KB
Binary file not shown.
-207 KB
Binary file not shown.
-103 KB
Binary file not shown.
-207 KB
Binary file not shown.
-103 KB
Binary file not shown.
-207 KB
Binary file not shown.
604 KB
Binary file not shown.
604 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
-103 KB
Binary file not shown.
-207 KB
Binary file not shown.
604 KB
Binary file not shown.
604 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
-103 KB
Binary file not shown.
-207 KB
Binary file not shown.
-103 KB
Binary file not shown.
604 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
604 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

input/Static/Static.wav

100755100644
397 KB
Binary file not shown.

input/Static/Static_T.wav

100755100644
500 KB
Binary file not shown.

input/equateRmsWav.m

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
function equateRmsWav(subjName)
2+
% function equateRmsWav(subjName)
3+
% Not used during the experiment itself but allows to root mean square the sounds of a given
4+
% subject.
5+
if nargin < 1
6+
subjName = input('Enter Subjects name: ', 's');
7+
end
8+
9+
referenceDir = fullfile(pwd, 'Static');
10+
subjectDir = fullfile(pwd, ['Motion/sub-', subjName]);
11+
12+
% reference folder (Static)
13+
cd(referenceDir);
14+
referenceWavFn = fullfile(pwd, 'Static.wav');
15+
16+
% Subject motion folder
17+
cd(subjectDir);
18+
19+
targetWavFn = ['sub-', subjName, '_LRL.wav'];
20+
runFunction(referenceWavFn, targetWavFn);
21+
22+
targetWavFn = [subjName, '_RLR.wav'];
23+
runFunction(referenceWavFn, targetWavFn);
24+
25+
% Targets
26+
cd(referenceDir);
27+
referenceWavFn = fullfile(pwd, 'Static_T.wav');
28+
29+
cd(subjectDir);
30+
31+
targetWavFn = [subjName, '_LRL_T.wav'];
32+
runFunction(referenceWavFn, targetWavFn);
33+
34+
targetWavFn = [subjName, '_RLR_T.wav'];
35+
runFunction(referenceWavFn, targetWavFn);
36+
37+
end
38+
39+
function runFunction (referenceWavFn, targetWavFn)
40+
% This Script takes a file (targetWavFn) and equates its rms with
41+
% another reference audio file (referenceWavFn) amd gives the equated
42+
% wav file as an output ('final_wave.wav')
43+
44+
% Get the rms of the original sound
45+
[referenceWav, referenceFs] = audioread(referenceWavFn);
46+
referenceRMS = rms(referenceWav);
47+
disp('rms of the reference wav file');
48+
disp(referenceRMS);
49+
50+
% Get the rms for the edited combined sound (static)
51+
[targetWav, ~] = audioread(targetWavFn);
52+
targetRms = rms(targetWav);
53+
disp('rms of the target wav file');
54+
disp(targetRms);
55+
56+
% correct for the rms differences in each channel
57+
finalWav = [targetWav(:, 1) * (referenceRMS(1) / targetRms(1)) ...
58+
targetWav(:, 2) * (referenceRMS(2) / targetRms(2))];
59+
60+
% check that the rms of the final is similar to the original
61+
finalRms = rms(finalWav);
62+
disp('rms of the final wav file');
63+
disp(finalRms);
64+
65+
audiowrite([targetWavFn(1:end - 4), '_rms.wav'], finalWav, eferenceFs);
66+
67+
%% plot the reference wav and final wav files
68+
figure();
69+
subplot(2, 1, 1);
70+
plot(referenceWav(:, 1), 'r');
71+
hold on;
72+
plot(referenceWav(:, 2), 'b');
73+
title('Reference wav file');
74+
75+
subplot(2, 1, 2);
76+
plot(finalWav(:, 1), 'r');
77+
hold on;
78+
plot(finalWav(:, 2), 'b');
79+
title('Final wav file');
80+
81+
end

lib/CPP_BIDS

lib/CPP_PTB

setParameters.m

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
%% Debug mode settings
1414

15-
cfg.debug.do = false; % To test the script out of the scanner, skip PTB sync
15+
cfg.debug.do = true; % To test the script out of the scanner, skip PTB sync
1616
cfg.debug.smallWin = false; % To test on a part of the screen, change to 1
1717
cfg.debug.transpWin = false; % To test with trasparent full size screen
1818

@@ -21,7 +21,7 @@
2121
%% Engine parameters
2222

2323
cfg.testingDevice = 'mri';
24-
cfg.eyeTracker.do = true;
24+
cfg.eyeTracker.do = false;
2525
cfg.audio.do = true;
2626

2727
cfg = setMonitor(cfg);
@@ -40,7 +40,8 @@
4040
% cfg.design.motionType = 'radial';
4141
cfg.design.motionType = 'translation';
4242
cfg.design.names = {'static'; 'motion'};
43-
cfg.design.motionDirections = [-1 -1 1 1];
43+
% 0: L--R--L; 180: R--L--R;
44+
cfg.design.motionDirections = [0 0 180 180];
4445
cfg.design.nbRepetitions = 14;
4546
cfg.design.nbEventsPerBlock = 12;
4647

subfun/doAuditoryMotion.m

+18-12
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,33 @@
1818
%% Get parameters
1919

2020
direction = thisEvent.direction(1);
21-
isTarget = thisEvent.target(1);
21+
isFixationTarget = thisEvent.fixationTarget(1);
2222
targetDuration = cfg.target.duration;
2323

24+
% % % WIP % % %
25+
26+
% isSoundTarget = thisEvent.soundTarget(1);
27+
28+
% % % WIP % % %
29+
2430
soundData = cfg.soundData;
2531

2632
switch direction
2733
case -1
2834
fieldName = 'S';
29-
case 90
30-
fieldName = 'U';
31-
case 270
32-
fieldName = 'D';
3335
case 0
34-
fieldName = 'R';
36+
fieldName = 'LRL';
3537
case 180
36-
fieldName = 'L';
38+
fieldName = 'RLR';
3739
end
3840

39-
if isTarget == 1
40-
fieldName = [fieldName '_T'];
41-
end
41+
% % % WIP % % %
42+
43+
% if isSoundTarget == 1
44+
% fieldName = [fieldName '_T'];
45+
% end
46+
47+
% % % WIP % % %
4248

4349
sound = soundData.(fieldName);
4450

@@ -51,7 +57,7 @@
5157
% ideally we would want to synch that first time stamp and the sound start
5258
thisFixation.fixation = cfg.fixation;
5359
thisFixation.screen = cfg.screen;
54-
if isTarget == 1
60+
if isFixationTarget == 1
5561
thisFixation.fixation.color = cfg.fixation.colorTarget;
5662
end
5763
drawFixation(thisFixation);
@@ -62,7 +68,7 @@
6268
% set default cross cross color but update if target time is not
6369
% finished
6470
thisFixation.fixation.color = cfg.fixation.color;
65-
if GetSecs < (onset + targetDuration) && isTarget == 1
71+
if GetSecs < (onset + targetDuration) && isFixationTarget == 1
6672
thisFixation.fixation.color = cfg.fixation.colorTarget;
6773
end
6874

subfun/loadAudioFiles.m

+16-32
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,34 @@
1919
soundData.S = soundData.S';
2020

2121
% motion input
22-
fileName = fullfile('input', 'Motion', subjName, ['rms_', subjName, '_U.wav']);
23-
[soundData.U, freq2] = audioread(fileName);
24-
soundData.U = soundData.U';
22+
fileName = fullfile('input', 'Motion', subjName, [subjName, '_LRL_rms.wav']);
23+
[soundData.LRL, freq2] = audioread(fileName);
24+
soundData.LRL = soundData.LRL';
2525

26-
fileName = fullfile('input', 'Motion', subjName, ['rms_', subjName, '_D.wav']);
27-
[soundData.D, freq3] = audioread(fileName);
28-
soundData.D = soundData.D';
29-
30-
fileName = fullfile('input', 'Motion', subjName, ['rms_', subjName, '_R.wav']);
31-
[soundData.R, freq4] = audioread(fileName);
32-
soundData.R = soundData.R';
33-
34-
fileName = fullfile('input', 'Motion', subjName, ['rms_', subjName, '_L.wav']);
35-
[soundData.L, freq5] = audioread(fileName);
36-
soundData.L = soundData.L';
26+
fileName = fullfile('input', 'Motion', subjName, [subjName, '_RLR_rms.wav']);
27+
[soundData.RLR, freq3] = audioread(fileName);
28+
soundData.RLR = soundData.RLR';
3729

3830
%% Targets
3931

4032
% static Stimuli
4133
fileName = fullfile('input', 'Static', 'Static_T.wav');
42-
[soundData.S_T, freq6] = audioread(fileName);
34+
[soundData.S_T, freq4] = audioread(fileName);
4335
soundData.S_T = soundData.S_T';
4436

4537
% motion Stimuli
46-
fileName = fullfile('input', 'Motion', subjName, ['rms_', subjName, '_U_T.wav']);
47-
[soundData.U_T, freq7] = audioread(fileName);
48-
soundData.U_T = soundData.U_T';
49-
50-
fileName = fullfile('input', 'Motion', subjName, ['rms_', subjName, '_D_T.wav']);
51-
[soundData.D_T, freq8] = audioread(fileName);
52-
soundData.D_T = soundData.D_T';
53-
54-
fileName = fullfile('input', 'Motion', subjName, ['rms_', subjName, '_R_T.wav']);
55-
[soundData.R_T, freq9] = audioread(fileName);
56-
soundData.R_T = soundData.R_T';
38+
fileName = fullfile('input', 'Motion', subjName, [subjName, '_LRL_T_rms.wav']);
39+
[soundData.LRL_T, freq5] = audioread(fileName);
40+
soundData.LRL_T = soundData.LRL_T';
5741

58-
fileName = fullfile('input', 'Motion', subjName, ['rms_', subjName, '_L_T.wav']);
59-
[soundData.L_T, freq10] = audioread(fileName);
60-
soundData.L_T = soundData.L_T';
42+
fileName = fullfile('input', 'Motion', subjName, [subjName, '_RLR_T_rms.wav']);
43+
[soundData.RLR_T, freq6] = audioread(fileName);
44+
soundData.RLR_T = soundData.RLR_T';
6145

62-
if length(unique([freq1 freq2 freq3 freq4 freq5 freq6 freq7 freq8 freq9 freq10])) > 1
63-
error ('Sounds dont have the same frequency');
46+
if length(unique([freq1 freq2 freq3 freq4 freq5 freq6])) > 1
47+
error ('Sounds do not have the same frequency');
6448
else
65-
freq = unique([freq1 freq2 freq3 freq4 freq5 freq6 freq7 freq8 freq9 freq10]);
49+
freq = unique([freq1 freq2 freq3 freq4 freq5 freq6]);
6650
end
6751

6852
cfg.soundData = soundData;

0 commit comments

Comments
 (0)