-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcursor2audio_freq.m
53 lines (48 loc) · 1.36 KB
/
cursor2audio_freq.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function freq = cursor2audio_freq(cursor, cal)
%Cursor is the neural control signal. From old work, this would be:
%sumE2-sumE1
%
%Auditory feedback calculation
%freq = a*exp(b*(cursor_trunc-cursor_min))
% freq_min = a = a*exp(0)
% freq_max = a*exp(b*(cursor_max-cursor_min))
% b = log(freq_max/a)/(cursor_max-cursor_min)
%param: cursor_min, cursor_max
%%
%If params.fb.target_low_freq == 1, then we negate cursor and cursor_min,
%cursor_max
%
%This is because cursor is E2-E1. Our target is gonna be positive.
%%
% %Debug:
% cal.fb.target_low_freq = 1;
% cal.fb.freq_max = 19000;
% cal.fb.freq_min = 6000;
%
% cal.fb.cursor_min = -1;
% cal.fb.cursor_max = 1;
% cal.fb.cursor_range = 2;
%
% cal.fb.a = cal.freq_min;
% cal.fb.b = (log(cal.freq_max) - log(cal.a))/cal.cursor_range;
%
% cursor = -4:0.1:2;
%%
%Handle target -> freq:
if cal.fb.target_low_freq == 1
%This means cursor up makes auditory freq go down:
cursor = -cursor;
cursor_min = -cal.fb.cursor_max;
cursor_max = -cal.fb.cursor_min;
else
%This means cursor up makes auditory freq go up:
cursor_min = cal.fb.cursor_min;
cursor_max = cal.fb.cursor_max;
end
%%
cursor_trunc = max(cursor, cursor_min);
cursor_trunc = min(cursor_trunc, cursor_max);
freq = cal.fb.a*exp(cal.fb.b*(cursor_trunc-cursor_min));
freq = double(freq);
% h = figure;
% plot(cursor, freq);