Home > SUpDEq-v5.0.0 > supdeq_writeSOFAobj.m

supdeq_writeSOFAobj

PURPOSE ^

% SUpDEq - Spatial Upsampling by Directional Equalization

SYNOPSIS ^

function SOFAobj = supdeq_writeSOFAobj(HRIR_L, HRIR_R, samplingGrid, fs, earDistance, sourceDistance)

DESCRIPTION ^

% SUpDEq - Spatial Upsampling by Directional Equalization
 
 function SOFAobj = supdeq_writeSOFAobj(HRIR_L, HRIR_R , samplingGrid, fs, earDistance, sourceDistance)

 This function can be used to generate a SOFA object based on a
 pre-defined spherical grid and the corresponding HRIRs.

 Output:
 SOFAobj according to the SOFA convention "SimpleFreeFieldHRIR".
 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
 samplingGrid  - 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Wed 30-Nov-2022 14:15:00 by m2html © 2005