Skip to content

Commit

Permalink
database handling improved: SOFAdbPath mirrors http://sofacoustics.or…
Browse files Browse the repository at this point in the history
…g/data now.

Warning: directory structure of HRTFs/SOFA changed!
All demo_s adapted accordingly.
  • Loading branch information
petibub committed May 11, 2015
1 parent 95e4f54 commit 1ff7b74
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 104 deletions.
18 changes: 7 additions & 11 deletions API_MO/SOFAdbPath.m
@@ -1,9 +1,8 @@
function [dbPath,f]=SOFAdbPath(newPath)
% [dbPath,f]=SOFAdbPath
function dbPath=SOFAdbPath(newPath)
% dbPath=SOFAdbPath
%
% [dbPath,f]=SOFAdbPath returns the path to the directory containing
% HRTFs for demos and applications. It also returns the system-specific
% file separator for creating file names.
% dbPath=SOFAdbPath returns the path to the directory containing
% HRTFs for demos and applications. The default path is: this_directory/../HRTFs/SOFA
%
% [...]=SOFAdbPath(Path) sets the path to the directory for further calls
% of SOFAdbPath.
Expand All @@ -16,16 +15,13 @@
% Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and limitations under the License.

f=filesep;

persistent CachedPath;

if exist('newPath','var')
CachedPath=newPath;
elseif isempty(CachedPath)
basepath=which('SOFAstart');
basepath=basepath(1:end-length('SOFAstart')-3); % Kill the function name from the path.
CachedPath=fullfile(basepath, '..', 'HRTFs');
elseif isempty(CachedPath)
% default: 'this_directory/../HRTFs/SOFA'
CachedPath=fullfile(fileparts(fileparts(mfilename('fullpath'))),'HRTFs','SOFA');
end
dbPath=CachedPath;

Expand Down
4 changes: 2 additions & 2 deletions API_MO/SOFAdbURL.m
Expand Up @@ -2,7 +2,7 @@
% dbURL=SOFAdbURL
%
% dbURL=SOFAdbURL returns the internet URL to the directory containing
% HRTFs.
% HRTFs. The default URL is http://www.sofacoustics.org/data.
%
% dbURL=SOFAdbURL(newURL) sets the internet URL to the newURL for further calls
% of SOFAdbURL.
Expand All @@ -20,6 +20,6 @@
if exist('dbURL','var')
CachedURL=dbURL;
elseif isempty(CachedURL)
CachedURL='http://www.sofacoustics.org/data/sofa_api_mo';
CachedURL='http://www.sofacoustics.org/data';
end
dbURL=CachedURL;
7 changes: 3 additions & 4 deletions API_MO/demos/demo_ARI2SOFA.m
Expand Up @@ -10,16 +10,15 @@

%% Define parameters
% Subject index of the file to convert
if ~exist('subjectID','var'); subjectID='NH4'; end;
subjectID='NH4';
% File name of the ARI file
ARIfile='hrtf_M_dtf 256';
% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time


%% Load ARI file
f=filesep;
ARIfn=[SOFAdbPath f 'ARI' f subjectID f ARIfile '.mat'];
ARIfn=fullfile(fileparts(SOFAdbPath), 'ARI', subjectID, [ARIfile '.mat']);
disp(['Loading: ' ARIfn]);
ARI=load(ARIfn);

Expand All @@ -32,6 +31,6 @@
Obj.GLOBAL_AuthorContact = 'piotr@majdak.com';

%% save SOFA file
SOFAfn=[SOFAdbPath f 'SOFA' f 'ARI_' subjectID '_' ARIfile '.sofa'];
SOFAfn=fullfile(SOFAdbPath,'sofa_api_mo_test',['ARI_' subjectID '_' ARIfile '.sofa']);
disp(['Saving: ' SOFAfn]);
Obj=SOFAsave(SOFAfn, Obj, compression);
6 changes: 3 additions & 3 deletions API_MO/demos/demo_BTDEI2SOFA.m
Expand Up @@ -23,8 +23,8 @@

%% load BTDEI file \ load database structure data
f=filesep;
BTDEI_hp_add=fullfile(SOFAdbPath,'BTDEI',hp,'headphones_info.mat');
BTDEI_add=fullfile(SOFAdbPath,'BTDEI',hp,subject,setm,BTDEIfold,'MAT',[hp '-' subject '_btdei.mat']);
BTDEI_hp_add=fullfile(fileparts(SOFAdbPath),'BTDEI',hp,'headphones_info.mat');
BTDEI_add=fullfile(fileparts(SOFAdbPath),'BTDEI',hp,subject,setm,BTDEIfold,'MAT',[hp '-' subject '_btdei.mat']);
disp(['Loading BT-DEI data']);

try
Expand Down Expand Up @@ -57,6 +57,6 @@
Obj.GLOBAL_Comment = SOFAappendText(Obj,'GLOBAL_Comment',BTDEIfold);

%% save SOFA file
SOFAfn=fullfile(SOFAdbPath,'SOFA',['BTDEI-hp_' hp '-subj_' subject '-' setm '-' BTDEIfold '.sofa']);
SOFAfn=fullfile(SOFAdbPath,'sofa_api_mo_test',['BTDEI-hp_' hp '-subj_' subject '-' setm '-' BTDEIfold '.sofa']);
disp(['Saving: ' SOFAfn])
SOFAsave(SOFAfn, Obj, compression);
7 changes: 3 additions & 4 deletions API_MO/demos/demo_CIPIC2SOFA.m
Expand Up @@ -9,16 +9,15 @@

%% Define parameters
% Subject index of the file to convert
if ~exist('subject','var'), subject=3; end;
subjectID=3;
% File name of the CIPIC file
CIPICfile='hrir_final';
% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time


%% load CIPIC file
f=filesep;
CIPICfn=[SOFAdbPath f 'CIPIC' f 'subject_' sprintf('%03d',subject) f CIPICfile '.mat'];
CIPICfn=fullfile(fileparts(SOFAdbPath), 'CIPIC', ['subject_' sprintf('%03d',subjectID)], [CIPICfile '.mat']);
disp(['Loading: ' CIPICfn]);
CIPIC=load(CIPICfn);

Expand All @@ -29,6 +28,6 @@
Obj.GLOBAL_ApplicationVersion = SOFAgetVersion('API');

%% save SOFA file
SOFAfn=[SOFAdbPath f 'SOFA' f 'CIPIC_' 'subject_' sprintf('%03d',subject) '_' CIPICfile '.sofa'];
SOFAfn=fullfile(SOFAdbPath,'sofa_api_mo_test', ['CIPIC_' 'subject_' sprintf('%03d',subjectID) '_' CIPICfile '.sofa']);
disp(['Saving: ' SOFAfn])
SOFAsave(SOFAfn, Obj, compression);
6 changes: 3 additions & 3 deletions API_MO/demos/demo_FHK2SOFA.m
Expand Up @@ -10,14 +10,14 @@

%% Define parameters
% Get a file name of the FHK directory
d=dir(fullfile(SOFAdbPath,'FHK','HRIR_*.mat'));
d=dir(fullfile(fileparts(SOFAdbPath),'FHK','HRIR_*.mat'));
fn=d(1).name;
% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time


%% Load FHK file
FHKfn=fullfile(SOFAdbPath, 'FHK', fn);
FHKfn=fullfile(fileparts(SOFAdbPath), 'FHK', fn);
disp(['Loading: ' FHKfn]);
FHK=load(FHKfn);
FHKvar=fieldnames(FHK);
Expand All @@ -30,6 +30,6 @@
Obj.GLOBAL_ApplicationVersion = SOFAgetVersion('API');

%% save SOFA file
SOFAfn=fullfile(SOFAdbPath, 'SOFA', ['FHK_' FHKname '.sofa']);
SOFAfn=fullfile(SOFAdbPath, 'sofa_api_mo_test', ['FHK_' FHKname '.sofa']);
disp(['Saving: ' SOFAfn]);
Obj=SOFAsave(SOFAfn, Obj, compression);
7 changes: 1 addition & 6 deletions API_MO/demos/demo_HpIR.m
Expand Up @@ -14,12 +14,7 @@
subjectID='NH5';

%% Load SOFA file
SOFAfn=fullfile(SOFAdbPath, 'SOFA', ['hpir_' lower(subjectID) '.sofa']);
% SOFAfn=fullfile(SOFAdbPath, 'SOFA', 'hrtf_M_hpir.sofa');
if ~exist(SOFAfn,'file')
disp(['Downloading from: http://www.sofacoustics.org/data/headphones/ari']);
urlwrite(['http://www.sofacoustics.org/data/headphones/ari/' 'hpir_' lower(subjectID) '.sofa'], SOFAfn);
end
SOFAfn=fullfile(SOFAdbPath, 'headphones', 'ari', ['hpir_' lower(subjectID) '.sofa']);
disp(['Loading: ' SOFAfn]);
X=SOFAload(SOFAfn);

Expand Down
7 changes: 3 additions & 4 deletions API_MO/demos/demo_LISTEN2SOFA.m
Expand Up @@ -10,16 +10,15 @@

%% Define parameters
% Subject index of the file to convert
if ~exist('subjectID','var'); subjectID='1002'; end;
subjectID='1002'
% File name of the LISTEN file
LISTENfile=['IRC_' subjectID '_C_HRIR'];
% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time


%% Load LISTEN file
f=filesep;
LISTENfn=[SOFAdbPath f 'LISTEN' f 'IRC_' subjectID f 'COMPENSATED' f 'MAT' f 'HRIR' f LISTENfile '.mat'];
LISTENfn=fullfile(fileparts(SOFAdbPath),'LISTEN',['IRC_' subjectID],'COMPENSATED','MAT','HRIR',[LISTENfile '.mat']);
disp(['Loading: ' LISTENfn]);
LISTEN=load(LISTENfn);

Expand All @@ -30,6 +29,6 @@
Obj.GLOBAL_ApplicationVersion = SOFAgetVersion('API');

%% save SOFA file
SOFAfn=[SOFAdbPath f 'SOFA' f 'LISTEN_' subjectID '_' LISTENfile '.sofa'];
SOFAfn=fullfile(SOFAdbPath,'sofa_api_mo_test',['LISTEN_' subjectID '_' LISTENfile '.sofa']);
disp(['Saving: ' SOFAfn]);
SOFAsave(SOFAfn, Obj, compression);
7 changes: 3 additions & 4 deletions API_MO/demos/demo_MIT2SOFA.m
Expand Up @@ -10,15 +10,14 @@

%% Define parameters
% Two ears are available: normal and large. Select one.
if ~exist('pinna','var'); pinna='normal'; end;
pinna='normal';

% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time


%% Define directory
f=filesep;
MITfn=[SOFAdbPath f 'MIT KEMAR'];
MITfn=fullfile(fileparts(SOFAdbPath),'MIT KEMAR');
disp(['Loading: ' MITfn ', pinna:' pinna]);

%% load and convert
Expand All @@ -28,6 +27,6 @@
Obj.GLOBAL_ApplicationVersion = SOFAgetVersion('API');

%% save SOFA file
SOFAfn=[SOFAdbPath f 'SOFA' f 'MIT_KEMAR_' pinna '_pinna.sofa'];
SOFAfn=fullfile(SOFAdbPath, 'sofa_api_mo_test', ['MIT_KEMAR_' pinna '_pinna.sofa']);
disp(['Saving: ' SOFAfn]);
SOFAsave(SOFAfn, Obj, compression);
6 changes: 3 additions & 3 deletions API_MO/demos/demo_SCUT2SOFA.m
Expand Up @@ -10,15 +10,15 @@

%% Define parameters
% Two ears are available: normal and large. Select one.
if ~exist('pinna','var'); pinna='normal'; end;
pinna='normal';

% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time


%% Define directory
SCUTdata = 'nearfield';
SCUTroot=fullfile(SOFAdbPath,'SCUT',SCUTdata);
SCUTroot=fullfile(fileparts(SOFAdbPath),'SCUT',SCUTdata);
disp(['Loading: ' SCUTroot]);

%% Define radii for converting
Expand All @@ -32,6 +32,6 @@

%% save SOFA file
str=sprintf('%g,',radius);
SOFAfn=fullfile(SOFAdbPath,'SOFA',['SCUT_KEMAR_radius_' str(1:end-1) '.sofa']);
SOFAfn=fullfile(SOFAdbPath,'sofa_api_mo_test',['SCUT_KEMAR_radius_' str(1:end-1) '.sofa']);
disp(['Saving: ' SOFAfn]);
SOFAsave(SOFAfn, Obj, compression);
7 changes: 3 additions & 4 deletions API_MO/demos/demo_SOFA2ARI.m
Expand Up @@ -10,16 +10,15 @@

%% Define parameters
% Subject index of the file to convert
if ~exist('subjectID','var'); subjectID='NH4'; end;
subjectID='NH4'
% File name of the ARI file
if ~exist('ARIfile','var'); ARIfile='hrtf_M_dtf 256'; end;
ARIfile='hrtf_M_dtf 256';
% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time


%% Load ARI file
f=filesep;
ARIfn=[SOFAdbPath f 'ARI' f subjectID f ARIfile '.mat'];
ARIfn=fullfile(fileparts(SOFAdbPath), 'ARI', subjectID, [ARIfile '.mat']);
disp(['Loading: ' ARIfn]);
ARI=load(ARIfn);

Expand Down
13 changes: 5 additions & 8 deletions API_MO/demos/demo_SOFAHRTF2DTF.m
Expand Up @@ -11,15 +11,12 @@

%% Define parameters
% Subject index of the file to convert
if ~exist('subject','var'), subject=3; end;
% File name of the CIPIC file
CIPICfile='hrir_final';
subject=3;
% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time

%% load SOFA file
f=filesep;
SOFAfn=[SOFAdbPath f 'SOFA' f 'CIPIC_' 'subject_' sprintf('%03d',subject) '_' CIPICfile '.sofa'];
SOFAfn=fullfile(SOFAdbPath, 'database', 'cipic', ['subject_' sprintf('%03d',subject) '.sofa']);
X=SOFAload(SOFAfn);
[D,C]=SOFAhrtf2dtf(X);

Expand Down Expand Up @@ -49,7 +46,7 @@
stepsize=CC.Data.SamplingRate/length(data)*2;
plot(1:stepsize:CC.Data.SamplingRate,data(1:length(data)/2),'r');
title('left');
xlabel('f/Hz'); ylabel('dB');
xlabel('f (in Hz)'); ylabel('dB');
legend('CTF','Avg DTF','Location','Best')

subplot(1,2,2);
Expand All @@ -58,5 +55,5 @@
stepsize=CC.Data.SamplingRate/length(data)*2;
plot(1:stepsize:CC.Data.SamplingRate,data(1:length(data)/2),'r');
title('right');
xlabel('f/Hz'); ylabel('dB');
legend('CTF','Avg DTF','Location','Best')
xlabel('f (in Hz)'); ylabel('dB');
legend('CTF','Avg DTF','Location','Best');
7 changes: 3 additions & 4 deletions API_MO/demos/demo_SOFAexpandcompact.m
Expand Up @@ -12,18 +12,17 @@

%% Define parameters
% Prefix to the files
TUBfile = 'TU-Berlin_QU_KEMAR_anechoic_';
TUBfile = 'qu_kemar_anechoic_';
% Define vector with radii to be merged. Available files: 0.5, 1, 2, and 3 m
if ~exist('radius','var'); radius=[0.5 1 2 3]; end;
radius=[0.5 1 2 3];

% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time

%% Load the objects
f=filesep;
clear Obj;
for ii=1:length(radius)
sourcefn=fullfile(SOFAdbPath,'SOFA',[TUBfile 'radius_' num2str(radius(ii)) 'm.sofa']);
sourcefn=fullfile(SOFAdbPath, 'database', 'tu-berlin', [TUBfile num2str(radius(ii)) 'm.sofa']);
disp(['Loading: ' sourcefn]);
Obj(ii)=SOFAload(sourcefn);
end
Expand Down
3 changes: 1 addition & 2 deletions API_MO/demos/demo_SOFAload.m
Expand Up @@ -7,8 +7,7 @@
% See the License for the specific language governing permissions and limitations under the License.

%% Path definitions
f=filesep;
SOFAfile=[SOFAdbPath f 'SOFA' f 'TU-Berlin_QU_KEMAR_anechoic_radius_0.5_1_2_3_m.sofa'];
SOFAfile=fullfile(SOFAdbPath, 'database', 'tu-berlin', 'qu_kemar_anechoic_all.sofa');

%% Loading the full object
disp(['Loading full object: ' SOFAfile]);
Expand Down
13 changes: 6 additions & 7 deletions API_MO/demos/demo_SOFAmerge.m
Expand Up @@ -12,18 +12,17 @@

%% Define parameters
% Prefix to the files
TUBfile = 'TU-Berlin_QU_KEMAR_anechoic_';
TUBfile = 'qu_kemar_anechoic_';
% Define vector with radii to be merged. Available files: 0.5, 1, 2, and 3 m
if ~exist('radius','var'); radius=[0.5 1 2 3]; end;
radius=[0.5 1 2 3];

% Data compression (0..uncompressed, 9..most compressed)
compression=1; % results in a nice compression within a reasonable processing time

%% Load the objects to be merged
f=filesep;
clear Obj;
for ii=1:length(radius)
sourcefn=fullfile(SOFAdbPath,'SOFA',[TUBfile 'radius_' num2str(radius(ii)) 'm.sofa']);
sourcefn=fullfile(SOFAdbPath, 'database', 'tu-berlin', [TUBfile num2str(radius(ii)) 'm.sofa']);
disp(['Loading: ' sourcefn]);
Obj(ii)=SOFAload(sourcefn);
end
Expand All @@ -40,7 +39,7 @@
disp([' Memory requirements: ' num2str(round(x.bytes/1024)) ' kb']);

%% save the object as a single SOFA file
SOFAfn=fullfile(SOFAdbPath,'SOFA',[TUBfile 'radius_' sprintf('%g_',radius) 'm.sofa']);
SOFAfn=fullfile(SOFAdbPath,'sofa_api_mo_test',[TUBfile 'radius_' sprintf('%g_',radius) 'm.sofa']);
disp(['Saving: ' SOFAfn]);
tic;
Obj=SOFAsave(SOFAfn, ObjFull, compression);
Expand All @@ -51,8 +50,8 @@
azi=0; ele=0;
idx=find(Obj.SourcePosition(:,1)==azi & Obj.SourcePosition(:,2)==ele);
plot(squeeze(ObjFull.Data.IR(idx,1,:))');
legend(num2str(ObjFull.SourcePosition(idx,2)))
legend(num2str(ObjFull.SourcePosition(idx,3)))
title(['Demo of SOFAmerge:' 10 ...
'IRs for the left ear with radius as parameter retrieved from a merged object']);
xlabel([' index (sample taps)']);
xlabel(' index (sample taps)');
ylabel('Amplitude');
2 changes: 1 addition & 1 deletion API_MO/demos/demo_SOFAplotHRTF.m
Expand Up @@ -7,7 +7,7 @@
% See the License for the specific language governing permissions and limitations under the License.

%% load a SOFA file
SOFAfile=fullfile(SOFAdbPath,'SOFA','ARI_NH2_hrtf_M_dtf 256.sofa');
SOFAfile=fullfile(SOFAdbPath,'database','ari','dtf_nh2.sofa');
Obj=SOFAload(SOFAfile);

% plot ETC horizontal plane
Expand Down
3 changes: 1 addition & 2 deletions API_MO/demos/demo_SOFAsave.m
Expand Up @@ -64,7 +64,6 @@
Obj.GLOBAL_Comment = 'Contains simple pulses for all directions';

%% save the SOFA file
f=filesep;
SOFAfn=fullfile(SOFAdbPath,'SOFA','Pulse.sofa');
SOFAfn=fullfile(SOFAdbPath,'sofa_api_mo_test','Pulse.sofa');
disp(['Saving: ' SOFAfn]);
Obj=SOFAsave(SOFAfn, Obj, compression);

0 comments on commit 1ff7b74

Please sign in to comment.