-
Notifications
You must be signed in to change notification settings - Fork 0
/
HRTFContainer.cpp
126 lines (107 loc) · 3.2 KB
/
HRTFContainer.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "HRTFContainter.h"
HRTFContainer::HRTFContainer(){
if(load_data(HRIR_L_DIR, HRIR_R_DIR, ITD_DIR) != 0){
cout << "Error loading HRTF Data" << endl;
}
}
int HRTFContainer::load_data(string hrir_l_dir, string hrir_r_dir, string ITD_DIR){
int success = 0;
success += load_hrir_l(hrir_l_dir);
success += load_hrir_r(hrir_r_dir);
success += load_ITD(ITD_DIR);
return success;
}
int HRTFContainer::load_hrir_l(string hrir_l_dir){
fstream file;
file.open(hrir_l_dir, ios::in);
string open_bracket = "";
string closed_bracket = "";
string value = "";
if(!file){
cout << "hrir_l file not found" << endl;
return -1;
}
else{
for(int i = 0; i < 25; i++){
getline(file, open_bracket, '[');
for(int j = 0; j < 50; j++){
getline(file, open_bracket, '[');
for(int k = 0; k < 200; k++){
getline(file, open_bracket, '[');
getline(file, value, ']');
stringstream ss(value);
ss >> hrir_l[i][j][k];
//cout << hrir_l[i][j][k] << endl;
}
getline(file, closed_bracket, ']');
}
getline(file, closed_bracket, ']');
}
}
return 0;
}
int HRTFContainer::load_hrir_r(string hrir_r_dir){
fstream file;
file.open(hrir_r_dir, ios::in);
string open_bracket = "";
string closed_bracket = "";
string value = "";
if(!file){
cout << "hrir_r file not found" << endl;
return -1;
}
else{
for(int i = 0; i < 25; i++){
getline(file, open_bracket, '[');
for(int j = 0; j < 50; j++){
getline(file, open_bracket, '[');
for(int k = 0; k < 200; k++){
getline(file, open_bracket, '[');
getline(file, value, ']');
stringstream ss(value);
ss >> hrir_r[i][j][k];
//cout << hrir_l[i][j][k] << endl;
}
getline(file, closed_bracket, ']');
}
getline(file, closed_bracket, ']');
}
}
return 0;
}
int HRTFContainer::load_ITD(string ITD_dir){
fstream file;
file.open(ITD_dir, ios::in);
string open_bracket = "";
string closed_bracket = "";
string value = "";
if(!file){
cout << "ITD file not found" << endl;
return -1;
}
else{
for(int i = 0; i < 25; i++){
getline(file, open_bracket, '[');
for(int j = 0; j < 50; j++){
getline(file, open_bracket, '[');
getline(file, value, ']');
stringstream ss(value);
ss >> ITD[i][j];
}
getline(file, closed_bracket, ']');
}
}
return 0;
}
float* HRTFContainer::get_hrir_l(int az, int elevation){
float* value = hrir_l[az][elevation];
return value;
}
float* HRTFContainer::get_hrir_r(int az, int elevation){
float* value = hrir_r[az][elevation];
return value;
}
float HRTFContainer::get_ITD(int az, int elevation){
float value = ITD[az][elevation];
return value;
}