% SUpDEq - Spatial Upsampling by Directional Equalization function SOFAobj = supdeq_writeSOFAobj_SSR(HRIR_L, HRIR_R , viewDirections, fs, earDistance, sourceDistance) This function can be used to generate a SOFA object based on a pre-defined spherical grid and the corresponding HRIRs for the SoundScape Renderer (SSR) Version 'Hornhack'. This SSR Version can read SOFA files. The grid is defined as a BRIR grid in ListenerViewDirections, the source position is defined as [0 0 0]. To keep it short, its a hack that works... Output: SOFAobj according to the SOFA convention "SimpleFreeFieldHRIR" but with coordinates and data which can be used for BRIR rendering in the SSR_Hornhack. Specific attributes and metadata can be added manually afterwards. Use SOFAsave to save SOFA object with specific filename. Input: HRIR_L/R - 2D Array [N X M] with N = Sample point on spherical grid, M = Samples per IR, Example: HRIR_L/R with dimensions [2702x256]--> 2702 HRIRs (according to samplingGrid with 2702 points) with 256 samples per HRIR viewDirections- 2D Array [AZ x EL] with AZ = Azimuth, EL = Elevation in degree [DEG]! fs - Sampling rate Default: 48000 earDistance - earDistance of the receiver, only needed for HRIRs/BRIRs Two receivers (=ears) on a head with radius H (in meter): ReceiverPosition=[0 -H 0; 0 +H 0]. Default: 0.165 sourceDistance- Distance between receiver and source. Only important for measurement-based SOFA files (HRIRs/BRIRs/Array-IRs). Default: 3.00 m - In the far field... Dependencies: SOFA API SOFA conventions - https://www.sofaconventions.org/mediawiki/index.php/SOFA_conventions Standardized SOFA conventions Standardized SOFA conventions are those which have been standardized by the AES. As with AES69-2015, we have: GeneralFIR: General convention with FIR as DataType (no restrictions but DataType) GeneralTF: General convention with TF as DataType (no restrictions but DataType) SimpleFreeFieldHRIR: Free-field HRTFs stored as impulse responses, measured with an omnidirectional source for a single listener. Note: Any modification in one of these conventions changes its status to "stable", i.e., not standardized anymore, unless the modification will be approved the AES. Stable SOFA conventions Stable SOFA conventions are those for which SOFA files are publicly available and can be read/modified by at least one publicly available software package. GeneralFIRE: General convention with FIRE as DataType (no restrictions but DataType). SimpleHeadphoneIR: Conventions to store headphone IRs recorded for each emitter and each ear, single listener and no directionality of emitter/receiver considered. SimpleFreeFieldTF: as SimpleFreeFieldHRIR, but uses TF as DataType covering special needs coming from HRTF simulations. SimpleFreeFieldSOS: as SimpleFreeFieldHRIR, but uses SOS as DataType (second-order sections) covering special needs coming from HRTF rendering. SingleRoomDRIR: directional room impulse responses (DRIRs) measured with an arbitrary number of receivers (such as a microphone array) and an omnidirectional source in a single room. MultiSpeakerBRIR: binaural room impulse responses (BRIRs) measured with an arbitrary number of emitters (such as a loudspeaker array). These conventions, when used often and widely, can be proposed for standardization to the AES. Proposed SOFA conventions SimpleBRIR: Binaural room impulse responses measured with an omnidirectional source in a single reverberant space. Somebody wanted to have this, but the work stopped at the moment. (C) 2018 by JMA, Johannes M. Arend TH Köln - University of Applied Sciences Institute of Communications Engineering Department of Acoustics and Audio Signal Processing
0001 %% SUpDEq - Spatial Upsampling by Directional Equalization 0002 % 0003 % function SOFAobj = supdeq_writeSOFAobj_SSR(HRIR_L, HRIR_R , viewDirections, fs, earDistance, sourceDistance) 0004 % 0005 % This function can be used to generate a SOFA object based on a 0006 % pre-defined spherical grid and the corresponding HRIRs for the 0007 % SoundScape Renderer (SSR) Version 'Hornhack'. This SSR Version can read 0008 % SOFA files. The grid is defined as a BRIR grid in ListenerViewDirections, 0009 % the source position is defined as [0 0 0]. To keep it short, its a hack 0010 % that works... 0011 % 0012 % Output: 0013 % SOFAobj according to the SOFA convention "SimpleFreeFieldHRIR" but with 0014 % coordinates and data which can be used for BRIR rendering in the 0015 % SSR_Hornhack. 0016 % Specific attributes and metadata can be added manually afterwards. 0017 % Use SOFAsave to save SOFA object with specific filename. 0018 % 0019 % Input: 0020 % HRIR_L/R - 2D Array [N X M] with 0021 % N = Sample point on spherical grid, M = Samples per IR, 0022 % Example: HRIR_L/R with dimensions [2702x256]--> 2702 0023 % HRIRs (according to samplingGrid with 2702 points) with 0024 % 256 samples per HRIR 0025 % viewDirections- 2D Array [AZ x EL] with 0026 % AZ = Azimuth, EL = Elevation in degree [DEG]! 0027 % fs - Sampling rate 0028 % Default: 48000 0029 % earDistance - earDistance of the receiver, only needed for HRIRs/BRIRs 0030 % Two receivers (=ears) on a head with radius H (in meter): ReceiverPosition=[0 -H 0; 0 +H 0]. 0031 % Default: 0.165 0032 % sourceDistance- Distance between receiver and source. Only important for 0033 % measurement-based SOFA files (HRIRs/BRIRs/Array-IRs). 0034 % Default: 3.00 m - In the far field... 0035 % 0036 % Dependencies: SOFA API 0037 % 0038 % SOFA conventions - https://www.sofaconventions.org/mediawiki/index.php/SOFA_conventions 0039 % 0040 % Standardized SOFA conventions 0041 % Standardized SOFA conventions are those which have been standardized by the AES. As with AES69-2015, we have: 0042 % GeneralFIR: General convention with FIR as DataType (no restrictions but DataType) 0043 % GeneralTF: General convention with TF as DataType (no restrictions but DataType) 0044 % SimpleFreeFieldHRIR: Free-field HRTFs stored as impulse responses, measured with an omnidirectional source for a single listener. 0045 % Note: Any modification in one of these conventions changes its status to "stable", i.e., not standardized anymore, unless the modification will be approved the AES. 0046 % 0047 % Stable SOFA conventions 0048 % Stable SOFA conventions are those for which SOFA files are publicly available and can be read/modified by at least one publicly available software package. 0049 % GeneralFIRE: General convention with FIRE as DataType (no restrictions but DataType). 0050 % SimpleHeadphoneIR: Conventions to store headphone IRs recorded for each emitter and each ear, single listener and no directionality of emitter/receiver considered. 0051 % SimpleFreeFieldTF: as SimpleFreeFieldHRIR, but uses TF as DataType covering special needs coming from HRTF simulations. 0052 % SimpleFreeFieldSOS: as SimpleFreeFieldHRIR, but uses SOS as DataType (second-order sections) covering special needs coming from HRTF rendering. 0053 % SingleRoomDRIR: directional room impulse responses (DRIRs) measured with an arbitrary number of receivers (such as a microphone array) and an omnidirectional source in a single room. 0054 % MultiSpeakerBRIR: binaural room impulse responses (BRIRs) measured with an arbitrary number of emitters (such as a loudspeaker array). 0055 % These conventions, when used often and widely, can be proposed for standardization to the AES. 0056 % 0057 % Proposed SOFA conventions 0058 % SimpleBRIR: Binaural room impulse responses measured with an omnidirectional source in a single reverberant space. Somebody wanted to have this, but the work stopped at the moment. 0059 % 0060 % (C) 2018 by JMA, Johannes M. Arend 0061 % TH Köln - University of Applied Sciences 0062 % Institute of Communications Engineering 0063 % Department of Acoustics and Audio Signal Processing 0064 0065 function SOFAobj = supdeq_writeSOFAobj_SSR(HRIR_L, HRIR_R, viewDirections, fs, earDistance, sourceDistance) 0066 0067 if nargin < 4 || isempty(fs) 0068 fs = 48000; 0069 end 0070 0071 if nargin < 5 || isempty(earDistance) 0072 earDistance = 0.165; 0073 end 0074 0075 if nargin < 6 || isempty(sourceDistance) 0076 sourceDistance = 3.00; 0077 end 0078 0079 %Write IRs 3D Array 0080 IRs = cat(3,HRIR_L',HRIR_R'); 0081 0082 if size(IRs,2) ~= size(viewDirections,1) 0083 error('Number of IRs must match number to number of sampling grid points!'); 0084 end 0085 0086 0087 %% 0088 %Write SOFA file 0089 disp('Writing "SimpleFreeFieldHRIR" SOFA object for SSR Hornhack.'); 0090 0091 %Get empty SOFA object 0092 SOFAobj = SOFAgetConventions('SimpleFreeFieldHRIR'); 0093 0094 %Get number of grid points 0095 nPoints = size(viewDirections,1); 0096 0097 %Transform grid to SOFA format 0098 viewDirections(:,2) = 90-viewDirections(:,2); 0099 0100 %Fill obj with data 0101 SOFAobj.Data.IR = IRs(:,:,1); %Channel1 - Left 0102 SOFAobj.Data.IR(:,:,2) = IRs(:,:,2); %Channel2 - Right 0103 SOFAobj.Data.IR = shiftdim(SOFAobj.Data.IR,1); % convert from [N M R] to [M R N] 0104 SOFAobj.Data.SamplingRate = fs; 0105 %Fill the mandatory variables (0 -radius 0; 0 radius 0) 0106 SOFAobj.ReceiverPosition = [0 -earDistance/2 0; 0 earDistance/2 0]; 0107 SOFAobj.ListenerPosition = [0 0 0]; 0108 SOFAobj.ListenerUp = [0 0 1]; 0109 SOFAobj.ListenerUp_Type = 'cartesian'; 0110 SOFAobj.ListenerUp_Units = 'metre'; 0111 SOFAobj.ListenerView = [1 0 0]; 0112 SOFAobj.ListenerView = [... 0113 viewDirections(:,1) ... % AZ in DEG 0114 viewDirections(:,2) ... % EL in DEG 0115 sourceDistance*ones(nPoints,1)]; % nPoints source distance in m 0116 SOFAobj.ListenerView_Type = 'spherical'; 0117 SOFAobj.ListenerView_Units = 'degree, degree, metre'; 0118 SOFAobj.SourcePosition = [0 0 0]; 0119 SOFAobj.SourcePosition_Type = 'spherical'; 0120 SOFAobj.SourcePosition_Units = 'degree, degree, metre'; 0121 0122 %Update dimensions 0123 SOFAobj=SOFAupdateDimensions(SOFAobj); 0124 0125 disp('Done...'); 0126 end 0127