itaRavenProject.m 248 KB
Newer Older
1
classdef itaRavenProject < handle
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
    %RavenProject - The class for working with RAVEN.
    % This class allows you to create configurations of settings, to
    % run simulations and to retrieve the results.
    %
    % Using:
    %   rpf = itaRavenProject(raven_project_file)
    %
    % Public Properties:
    %   Enter this command to get the properties:
    %   >> properties itaRavenProject
    %
    % Public Methods:
    %   Enter this command to get the methods:
    %   >> methods itaRavenProject
    %
    %   Enter this command to get more info of method:
    %   >> help itaRavenProject/methodname
    %
    %
    %
    % Example:
    %   rpf = itaRavenProject();
    %   rpf.SetModel('cave.ac')
    %   rpf.run()
    %   rpf.getReverbTime()
    %
    %
    % Author:         Soenke Pelzer (spe@akustik.rwth-aachen.de)
	%				  Lukas Aspck (las@akustik.rwth-aachen.de)
    % Version:        0.1
    % First release:  01.11.10
33
    % Last revision:  12.09.16
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
    % Copyright:      Institute of Technical Acoustics, RWTH Aachen University
    %

% <ITA-Toolbox>
% This file is part of the application Raven for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>

    
    properties(Constant)
        
        % CONSTANTS
        freqLabel3rd = { '   20 Hz', '   25 Hz', '   31 Hz', '   40 Hz', '   50 Hz', '   63 Hz', '   80 Hz', '  100 Hz', '  125 Hz', '  160 Hz', '  200 Hz', ...
                                     '  250 Hz', '  315 Hz', '  400 Hz', '  500 Hz', '  630 Hz', '  800 Hz', '   1 kHz', '1.25 kHz', ' 1.6 kHz', '   2 kHz', ...
                                     ' 2.5 kHz', '3.15 kHz', '   4 kHz', '   5 kHz', ' 6.3 kHz', '   8 kHz', '  10 kHz', '12.5 kHz', '  16 kHz', '  20 kHz'};
        freqLabelOct = { '   31 Hz', '   63 Hz', '  125 Hz', '  250 Hz', '  500 Hz', '   1 kHz', '   2 kHz', '   4 kHz', '   8 kHz', '  16 kHz'};        
        freqVector3rd = [20 25 31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000];
        freqVectorOct = [31.5 63 125 250 500 1000 2000 4000 8000 16000];
        MODE_BSP   = 0;
        MODE_HASH  = 1;
        MODE_BRUTE = 2;
        COORD_TRAFO_SKETCHUP2RAVEN = [1 3 -2];
        COORD_TRAFO_RAVEN2SKETCHUP = [1 -3 2];
     end
    
    properties (GetAccess = 'public', SetAccess = 'private')
        % raven
61

62 63 64
        ravenExe
        ravenLogFile = 'RavenLog.txt'
        ravenProjectFile
65
        ravenIniFile
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
        projectName
        
        % general
        sampleRate = 44100
        
        % paths
        pathResults
        pathDirectivities
        pathMaterials
        fileHRTF
        fileSpeakers
        
        % model
        modelFileList = []
        model = []
        
        % [Global]
        simulationTypeIS
        simulationTypeRT
        generateRIR
        generateBRIR
        generateISHOA
        generateRTHOA
        generateISVBAP
        generateRTVBAP
        exportFilter
        exportHistogram
        exportWallHitLog
        exportPlaneWaveList
        accelerationType
        logPerformance
        
        % [PrimarySources] %
        sourceNames
        sourceDirectivity
        sourcePositions
        sourceViewVectors
        sourceUpVectors
        sourceSoundStates
        sourceSoundLevels
        
        % [Receiver] %
        receiverNames
        receiverPositions
        receiverViewVectors
        receiverUpVectors
        receiverStates
        
        % [ImageSources] %
        ISOrder_PS
        ISOrder_SS
        ISSkipDirectSound
        
        % [RayTracing] %
        numParticles_Sphere
        numParticles_Portal
        energyLoss_Sphere
        energyLoss_Portal
        filterLength
        timeSlotLength
        radiusSphere
        fixReflectionPattern
        
        % [Filter] %
        fixPoissonSequence
        poissonSequenceNumber
        filterResolution
        ambisonicsOrder
        numberSpreadedSources
        spreadingStdDeviation
        fftDegreeForWallFilterInterpolation

        % [PlaneWaveLists] %
        planeWaveList_IS = []
        planeWaveList_RT = []
		
        % [Performance]
        performance = struct('ISFilterMonaural',[],'ISFilterBinaural',[],'RTFilterMonaural',[],'RTFilterBinaural',[],'ISGenerateImageSources',[],'ISTransformationMatrix',[],'ISAudibilityTest',[],'RTTotal',[],'RTBands',[]);
        
    end
    
    properties (GetAccess = 'public', SetAccess = 'public')	
        % [WallHitLogs] %
        wallHitLog_IS = []
        wallHitLog_RT = []
        initialParticleEnergy = []
    end
	
    properties (GetAccess = 'private', SetAccess = 'private')
155 156 157 158
        
        ravenExe64 = '..\bin64\RavenConsole64.exe'
        ravenExe32 = '..\bin32\RavenConsole.exe'
        
159
        rpf_ini
160
        raven_ini
161 162 163 164 165 166 167
        projectID
        projectTag
        
        projectLoaded = false
        simulationDone = false
        
        keepOutputFiles
168
        plotModelHandle = [];
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        
        % [PrimarySources] %
        sourceNameString
        sourceDirectivityString
        
        % [Receiver] %
        receiverNameString
        uniformReceiverGridX = []
        uniformReceiverGridY = []
        uniformReceiverGridZ = []
        
        % RESULTS %
        monauralIR = []
        monauralIR_IS = []
        monauralIR_RT = []
        binauralIR = []
        binauralIR_IS = []
        binauralIR_RT = []
        ambisonicsIR = []
        ambisonicsIR_IS = []
        ambisonicsIR_RT = []
        vbapIR = []
        vbapIR_IS = []
        vbapIR_RT = []
        histogram = []
        histogramRT = []
    end
    
    
    %---------------------- PUBLIC METHODS -------------------------------%
    methods
        %------------------------------------------------------------------
201
        function obj = itaRavenProject(raven_project_file)
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
            %RavenProject - constructor
            % To Create a new project with empty default configuration.
            %
            % Using:
            %   rpf = RavenProject(raven_project_file)
            %
            % Input:
            %   [optional] existing raven project file
            %
            % Output:
            %   obj - an instance of class RavenProject
            %
            
            if strcmp(computer('arch'), 'win32')
                obj.ravenExe = obj.ravenExe32;
            elseif strcmp(computer('arch'), 'win64')
                obj.ravenExe = obj.ravenExe64;
            else
                error('Only Windows OS are supported.');
            end
            
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
            itaRavenProjectPath = which('itaRavenProject.m');
            obj.ravenIniFile = [ itaRavenProjectPath(1:end-9) '.ini'];
            
            ravenIniExists = exist(obj.ravenIniFile,'file');
            
            if (ravenIniExists)
                    % load path from itaRaven.ini
                    obj.raven_ini = IniConfig();
                    obj.raven_ini.ReadFile(obj.ravenIniFile);
                    obj.ravenExe         = obj.raven_ini.GetValues('Global', 'PathRavenExe', obj.ravenExe);
                    obj.raven_ini.WriteFile(obj.ravenIniFile);
            end        
                    
            if (~exist(obj.ravenExe,'file'))

                    % neither the default raven console or the path in
                    % itaRaven.ini was not found, try to locate
                    % RavenConsole
                    locatedRavenExe = which(obj.ravenExe(10:end));
        
                    if isempty(locatedRavenExe) 
                        disp('[itaRaven]: No raven binary was found! Please select path to RavenConsole.exe!');
                        [ selectedRavenExe, selectedRavenPath] = uigetfile('*.exe',' No raven binary was found! Please select path to RavenConsole.exe');
                        obj.ravenExe = [ selectedRavenPath selectedRavenExe];
                    else
                        obj.ravenExe = locatedRavenExe;
                    end
                    
                    if (~ravenIniExists)
                        obj.raven_ini = IniConfig();
%                         obj.raven_ini.ReadFile(obj.ravenIniFile);
                        obj.raven_ini.AddSections({'Global'});
                        obj.raven_ini.AddKeys('Global', {'PathRavenExe'}, {obj.ravenExe});
                    else
                        obj.raven_ini.SetValues('Global', {'PathRavenExe'}, {obj.ravenExe});
                    end
                    obj.raven_ini.WriteFile(obj.ravenIniFile);
                       
            end
                      
            % check if raven project file exists
264 265 266 267 268 269 270
            if (nargin > 0) && exist(raven_project_file, 'file')
                obj.loadRavenConfig(raven_project_file);
            else
                error('No raven project file given or file not found.');
            end
        end
        
271 272 273 274
        function delete(obj)
            obj.deleteResultsInRavenFolder();
        end
        
275 276 277
        %------------------------------------------------------------------
        function setRavenExe(obj, newRavenExe)
            obj.ravenExe = newRavenExe;
278 279 280 281 282 283 284 285 286 287

            if (exist(obj.ravenIniFile,'file'))
                obj.raven_ini.SetValues('Global', {'PathRavenExe'}, {obj.ravenExe});
                obj.raven_ini.WriteFile(obj.ravenIniFile);
            else
                obj.raven_ini = IniConfig();
                obj.raven_ini.AddSections({'Global'});
                obj.raven_ini.AddKeys('Global', {'PathRavenExe'}, {obj.ravenExe});
            end
                                            
288 289 290 291 292 293 294
        end
        
        %------------------------------------------------------------------
        function loadRavenConfig(obj, filename)
            %loadRavenConfig - Reads an existing raven project file
            %
            
295 296 297 298 299 300
            % change relative to absolute path
            if (~strcmp(filename(2),':'))
                obj.ravenProjectFile = [pwd '\' filename];
            else
                obj.ravenProjectFile = filename;
            end
301 302 303 304 305 306
            
            obj.rpf_ini = IniConfig();
            obj.rpf_ini.ReadFile(filename);
            
            % [Global] %
            obj.projectName         = obj.rpf_ini.GetValues('Global', 'ProjectName', 'Matlab');
307
            obj.projectTag          = obj.projectName;
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
            obj.pathResults         = obj.rpf_ini.GetValues('Global', 'ProjectPath_Output', '..\RavenOutput');
            obj.pathDirectivities   = obj.rpf_ini.GetValues('Global', 'ProjectPath_DirectivityDB', '..\RavenDatabase\DirectivityDatabase');
            obj.pathMaterials       = obj.rpf_ini.GetValues('Global', 'ProjectPath_MaterialDB', '..\RavenDatabase\MaterialDatabase');
            obj.fileHRTF            = obj.rpf_ini.GetValues('Global', 'ProjectPath_HRTFDB', '..\RavenDatabase\HRTF\ITA-Kunstkopf_HRIR_AP11_Pressure_Equalized_3x3_256.daff');
            obj.fileSpeakers        = obj.rpf_ini.GetValues('Global', 'SpeakerConfigFile', 'Speakers.ini');
            obj.simulationTypeIS    = obj.rpf_ini.GetValues('Global', 'simulationTypeIS', 1);
            obj.simulationTypeRT    = obj.rpf_ini.GetValues('Global', 'simulationTypeRT', 1);
            obj.generateRIR         = obj.rpf_ini.GetValues('Global', 'generateRIR', 1);
            obj.generateBRIR        = obj.rpf_ini.GetValues('Global', 'generateBRIR', 1);
            obj.generateISHOA       = obj.rpf_ini.GetValues('Global', 'generateISHOA', 0);
            obj.generateRTHOA       = obj.rpf_ini.GetValues('Global', 'generateRTHOA', 0);
            obj.generateISVBAP      = obj.rpf_ini.GetValues('Global', 'generateISVBAP', 0);
            obj.generateRTVBAP      = obj.rpf_ini.GetValues('Global', 'generateRTVBAP', 0);
            obj.exportFilter        = obj.rpf_ini.GetValues('Global', 'exportFilter', 1);
            obj.exportHistogram     = obj.rpf_ini.GetValues('Global', 'exportHistogram', 1);
            obj.exportWallHitLog    = obj.rpf_ini.GetValues('Global', 'exportWallHitList', 0);
            obj.exportPlaneWaveList = obj.rpf_ini.GetValues('Global', 'exportPlaneWaveList', 0);
            obj.accelerationType    = obj.rpf_ini.GetValues('Global', 'accelerationType', 0);   % default 0 = MODE_BSP
            obj.logPerformance      = obj.rpf_ini.GetValues('Global', 'logPerformance', 0);
            obj.keepOutputFiles     = obj.rpf_ini.GetValues('Global', 'keepOutputFiles', 0);
            
329
            
330 331 332 333 334 335 336 337
            % change relative to absolute paths
            if obj.ravenExe(2) == ':' % absolute path
                ravenBasePath = fileparts(fileparts(obj.ravenExe)); % base path of raven
                
                if (strcmp(obj.pathResults(1:2),'..')), obj.pathResults = [ ravenBasePath obj.pathResults(3:end) ]; end
                if (strcmp(obj.pathDirectivities(1:2),'..')), obj.pathDirectivities = [ ravenBasePath obj.pathDirectivities(3:end) ]; end
                if (strcmp(obj.pathMaterials(1:2),'..')), obj.pathMaterials = [ ravenBasePath obj.pathMaterials(3:end) ]; end
                if (strcmp(obj.fileHRTF(1:2),'..')), obj.fileHRTF = [ ravenBasePath obj.fileHRTF(3:end) ]; end               
338 339
                

340 341
            end
            
342 343 344 345 346 347
            % [Rooms] %
            model_string            = obj.rpf_ini.GetValues('Rooms',  'Model');
            obj.modelFileList       = textscan(model_string, '%s', 'Delimiter' , ',');
            obj.modelFileList       = obj.modelFileList{1}; % textscan implementation issue
            if numel(obj.modelFileList) == 1
                obj.modelFileList = obj.modelFileList{1};   % de-cell if only 1 room given
348 349 350 351
                
                if obj.ravenExe(2) == ':' % convert to absolute path
                    if (strcmp(obj.modelFileList(1:2),'..')), obj.modelFileList = [ ravenBasePath obj.modelFileList(3:end) ]; end   
                end
352 353
            end
            
354

355

356
            
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
            % [PrimarySources] %
            obj.sourceNameString    = obj.rpf_ini.GetValues('PrimarySources', 'sourceNames', 'Sender');
            obj.sourceNames         = textscan(obj.sourceNameString, '%s', 'Delimiter', ',');
            obj.sourceNames         = obj.sourceNames{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            obj.sourceDirectivityString = obj.rpf_ini.GetValues('PrimarySources', 'sourceDirectivity', '');
            if ~isempty(obj.sourceDirectivityString)
                obj.sourceDirectivity   = textscan(obj.sourceDirectivityString, '%s', 'Delimiter', ',');
                obj.sourceDirectivity   = obj.sourceDirectivity{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            else
                obj.sourceDirectivity   = {};
            end
            obj.sourcePositions     = obj.rpf_ini.GetValues('PrimarySources', 'sourcePositions');
            obj.sourcePositions     = reshape(obj.sourcePositions, 3, numel(obj.sourcePositions)/3)';
            obj.sourceViewVectors   = obj.rpf_ini.GetValues('PrimarySources', 'sourceViewVectors', '0, 0, 1');
            obj.sourceViewVectors   = reshape(obj.sourceViewVectors, 3, numel(obj.sourceViewVectors)/3)';
            obj.sourceUpVectors     = obj.rpf_ini.GetValues('PrimarySources', 'sourceUpVectors', '0, 1, 0');
            obj.sourceUpVectors     = reshape(obj.sourceUpVectors, 3, numel(obj.sourceUpVectors)/3)';
            obj.sourceSoundStates   = obj.rpf_ini.GetValues('PrimarySources', 'sourceSoundStates', '1');
            obj.sourceSoundLevels   = obj.rpf_ini.GetValues('PrimarySources', 'sourceSoundLevels', '100');
            
            % [Receiver] %
            obj.receiverNameString  = obj.rpf_ini.GetValues('Receiver', 'receiverNames', 'Receiver');
            obj.receiverNames       = textscan(obj.receiverNameString, '%s', 'Delimiter', ',');
            obj.receiverNames       = obj.receiverNames{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            obj.receiverPositions   = obj.rpf_ini.GetValues('Receiver', 'receiverPositions');
            obj.receiverPositions   = reshape(obj.receiverPositions, 3, numel(obj.receiverPositions)/3)';
            obj.receiverViewVectors = obj.rpf_ini.GetValues('Receiver', 'receiverViewVectors', '1, 0 ,0');
            obj.receiverViewVectors = reshape(obj.receiverViewVectors, 3, numel(obj.receiverViewVectors)/3)';
            obj.receiverUpVectors   = obj.rpf_ini.GetValues('Receiver', 'receiverUpVectors', '0, 1, 0');
            obj.receiverUpVectors   = reshape(obj.receiverUpVectors, 3, numel(obj.receiverUpVectors)/3)';
            
            % [ImageSources] %
            obj.ISOrder_PS          = obj.rpf_ini.GetValues('ImageSources', 'ISOrder_PS', 2);
            obj.ISOrder_SS          = obj.rpf_ini.GetValues('ImageSources', 'ISOrder_SS', 2);
            obj.ISSkipDirectSound   = obj.rpf_ini.GetValues('ImageSources', 'ISSkipDirectSound', 0);
            
            % [RayTracing] %
            obj.numParticles_Sphere = obj.rpf_ini.GetValues('RayTracing', 'numberOfParticles_DetectionSphere', 10000);
            obj.numParticles_Portal = obj.rpf_ini.GetValues('RayTracing', 'numberOfParticles_Portal', 10000);
            obj.energyLoss_Sphere   = obj.rpf_ini.GetValues('RayTracing', 'energyLoss_DetectionSphere', 63);
            obj.energyLoss_Portal   = obj.rpf_ini.GetValues('RayTracing', 'energyLoss_Portal', 63);
            obj.filterLength        = obj.rpf_ini.GetValues('RayTracing', 'filterLength_DetectionSphere', 2000);
            obj.timeSlotLength      = obj.rpf_ini.GetValues('RayTracing', 'timeResolution_DetectionSphere', 6);
            obj.radiusSphere        = obj.rpf_ini.GetValues('RayTracing', 'radius_DetectionSphere', 0.5);
            obj.fixReflectionPattern= obj.rpf_ini.GetValues('RayTracing', 'fixReflectionPattern', 0);
            
            % [Filter] %
            obj.fixPoissonSequence  = obj.rpf_ini.GetValues('Filter', 'setFixPoissonSequence', 0);
            obj.poissonSequenceNumber = obj.rpf_ini.GetValues('Filter', 'poissonSequenceNumber', 9876);
            obj.filterResolution    = obj.rpf_ini.GetValues('Filter', 'filterResolution', 1);   % 1 = Octave, 0 = 3rd Octave
            obj.ambisonicsOrder     = obj.rpf_ini.GetValues('Filter', 'ambisonicsOrder', -1);
            obj.numberSpreadedSources             = obj.rpf_ini.GetValues('Filter', 'numberSpreadedSources', 0);
            obj.spreadingStdDeviation             = obj.rpf_ini.GetValues('Filter', 'spreadingStdDeviation', 0.2);
            obj.fftDegreeForWallFilterInterpolation = obj.rpf_ini.GetValues('Filter', 'fftDegreeForWallFilterInterpolation', 8);
            
            obj.projectLoaded = true;
        end
        
        %------------------------------------------------------------------
        function reloadRavenConfig(obj, filename)
            if nargin < 2
                filename = obj.ravenProjectFile;
            end
            
            obj.loadRavenConfig(filename);
        end
        
424 425 426 427 428 429 430 431 432 433
                %------------------------------------------------------------------
        function saveRavenConfig(obj, filename)
            %saveRavenConfig - Saves the current object in a (different)
            %raven project file. Can be used as a log if various
            %simulations are run with multiple configurations
            %
            obj.rpf_ini.WriteFile(filename);

        end
        
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
        %------------------------------------------------------------------
        function run(obj)
            
            obj.simulationDone = false;
            
            if obj.projectLoaded
                savedProjectName = obj.projectName;
                
                obj.projectID = datestr(now, 30);
                obj.projectTag = [obj.projectName obj.projectID];
                
                % give the project name a date and time string to help to identify the results
                obj.setProjectName(obj.projectTag);
                
                % set filter length to the length of the reverberation
                %                 obj.setFilterLengthToReverbTime();
                
                % run the simulation
                disp(['Running simulation... (' obj.ravenExe ')']);
                if exist(obj.ravenLogFile, 'file')
                    delete(obj.ravenLogFile);
                end
                %                 system([obj.ravenExe ' "' obj.ravenProjectFile '" >> ' obj.ravenLogFile]);
457 458
                prevPath = pwd;
                cd(fileparts(obj.ravenExe));
459
                dos(['"' obj.ravenExe '"' ' "' obj.ravenProjectFile '"'],'-echo');
460
                disp('Done.');
461
                cd(prevPath);
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
                
                % restore the initial project name
                obj.setProjectName(savedProjectName);
                
                % gather results
                disp('Getting results...');
                obj.gatherResults();
                disp('Done.');
                
                obj.simulationDone = true;
                
                % delete results in raven folder structure -> they are copied now into this class
                if (obj.keepOutputFiles == 0)
                    obj.deleteResultsInRavenFolder();
                end
            else
                disp('No projected defined yet.');
            end
            
        end
        
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
        %------------------------------------------------------------------
        function runNoGathering(obj)
            % basicly the same as the run method, but without the call of
            % obj.gatherResults();
            
            obj.simulationDone = false;
            
            if obj.projectLoaded
                savedProjectName = obj.projectName;
                
                obj.projectID = datestr(now, 30);
                obj.projectTag = [obj.projectName obj.projectID];
                
                % give the project name a date and time string to help to identify the results
                obj.setProjectName(obj.projectTag);
                
                % set filter length to the length of the reverberation
                %                 obj.setFilterLengthToReverbTime();
                
                % run the simulation
                disp(['Running simulation... (' obj.ravenExe ')']);
                if exist(obj.ravenLogFile, 'file')
                    delete(obj.ravenLogFile);
                end
                %                 system([obj.ravenExe ' "' obj.ravenProjectFile '" >> ' obj.ravenLogFile]);
508 509 510
                prevPath = pwd;
                cd(fileparts(obj.ravenExe));
                dos(['"' obj.ravenExe '"' ' "' obj.ravenProjectFile '"'],'-echo');
511
                disp('Done.');
512 513
                cd(prevPath);
                
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
                
                % restore the initial project name
                obj.setProjectName(savedProjectName);
                
                % gather results
                disp('This function does _not_ gather the results. Please provide arguments to getWallHitLogBand(band)');
%                 obj.gatherResults();
%                 disp('Done.');
                
                obj.simulationDone = true;
                
                % delete results in raven folder structure -> they are copied now into this class
%                 if (obj.keepOutputFiles == 0)
%                     obj.deleteResultsInRavenFolder();
%                 end
            else
                disp('No projected defined yet.');
            end
            
        end
        
535 536 537 538 539 540 541 542 543 544 545 546 547
                %------------------------------------------------------------------
        function openOutputFolder(obj)
            % opens the output folder in windows explorer
                
            if (exist(obj.pathResults,'dir'))
                dos(['C:\Windows\Explorer.exe ' obj.pathResults]);
            else
                disp('Output Folder does not exist!');
            end
            
        end
        
        
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
        %------------------------------------------------------------------
        function numReceivers = createReceiverArray(obj, xpositions, zpositions, yheight)
            numReceivers = numel(xpositions) * numel(zpositions);
            [obj.uniformReceiverGridX, obj.uniformReceiverGridZ] = meshgrid(xpositions, zpositions);
            obj.uniformReceiverGridY = ones(size(obj.uniformReceiverGridX,1), size(obj.uniformReceiverGridX,2)) * yheight;
            
            rec_names = obj.makeNumberedNames('Array', numReceivers);
            rec_states = str2num(obj.writeXtimes_num(1, numReceivers));
            rec_view = str2num(obj.writeXtimes('1,0,0', numReceivers));
            rec_up = str2num(obj.writeXtimes('0,1,0', numReceivers));
            
            positions = zeros(numReceivers * 3, 1);
            positions(1:3:end) = obj.uniformReceiverGridX(:);
            positions(2:3:end) = obj.uniformReceiverGridY(:);
            positions(3:3:end) = obj.uniformReceiverGridZ(:);
            
            obj.setReceiverNames(rec_names);
            obj.setReceiverPositions(positions);
            obj.setReceiverViewVectors(rec_view);
            obj.setReceiverUpVectors(rec_up);
            obj.setReceiverStates(rec_states);
            
            disp(['Receiver grid created successfully. ' num2str(numReceivers) ' receivers placed.']);
        end
        
        %------------------------------------------------------------------
        function createReceiverArrayAuto(obj, yheight, distance, roomID)
            
            if nargin < 4
                roomID = 0;   % default = first room (ID = 0)
            end
            
            if isempty(obj.model)
                if iscell(obj.modelFileList)
                    for iRoom = 1 : numel(obj.modelFileList)
                        obj.model{iRoom} = load_ac3d(obj.modelFileList{iRoom});
                    end
                    roommodel = obj.model{roomID + 1};
                else
                    obj.model = load_ac3d(obj.modelFileList);
                    roommodel = obj.model;
                end
            else
                if iscell(obj.model)
                    roommodel = obj.model{roomID + 1};
                else
                    roommodel = obj.model;
                end
            end
            
            if nargin < 3
                distance = 1;   % default = 1 meter
            end
            
            if nargin < 2
                yheight = min(roommodel.nodes(:,2)) + 1.2;  % default listener 1.2 meters above ground
                if yheight > max(roommodel.nodes(:,2))
                    yheight = mean(roommodel.nodes(:,2));   % if 1.2 meters is out of ceiling, try putting receivers in the middle between floor and ceiling
                end
            end
            
            xpositions = min(roommodel.nodes(:,1)) + distance/2 : distance : max(roommodel.nodes(:,1)) - distance/2;
            zpositions = min(roommodel.nodes(:,3)) + distance/2 : distance : max(roommodel.nodes(:,3)) - distance/2;
            
            obj.createReceiverArray(xpositions, zpositions, yheight);
        end
        
        %------------------------------------------------------------------
        function rebuildReceiverGrid(obj)
            numReceivers = numel(obj.receiverPositions) / 3;    %xyz
            if numReceivers < 1
                error('No receiver position data present.');
            end
            x = obj.receiverPositions(:,1);
            y = obj.receiverPositions(:,2);
            z = obj.receiverPositions(:,3);
            averageDistance = sqrt((max(x)-min(x))*(max(z)-min(z)) / numReceivers);
            obj.createReceiverArray(min(x) : averageDistance : max(x), min(z) : averageDistance : max(z), mean(y));
        end
        
        %------------------------------------------------------------------
        function setModel(obj, filename)
            
            if (nargin < 2)
                error('Not enough input arguments.')
            end
            
            if ~ischar(filename)
                error('Requires string input.')
            else
                if iscell(filename)
                    obj.modelFileList = obj.cat_cell_of_strings(filename);
                else
                    obj.modelFileList = filename;
                end
                obj.rpf_ini.SetValues('Rooms', 'Model', obj.modelFileList);
            end
            
            obj.model = [];
            
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function plotModel(obj, tgtAxes, comp2axesMapping, wireframe)
            if isempty(obj.modelFileList)
                return;
            end
            
            if nargin < 4
                wireframe = 0;
            else
                if ischar(wireframe)
                    wireframe = isequal(wireframe, 'wireframe');
                end
            end
            if nargin < 3
                comp2axesMapping = [3 1 2];
            end
            if nargin < 2
668 669 670 671 672 673 674
                if (ishandle(obj.plotModelHandle))
                    tgtAxes = obj.plotModelHandle;
                else
                    figure;
                    tgtAxes = gca;
                end
                
675 676
            end
            
677 678
            obj.plotModelHandle = tgtAxes;
            
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
            if isempty(obj.model)
                if iscell(obj.modelFileList)
                    for iRoom = 1 : numel(obj.modelFileList)
                        obj.model{iRoom} = load_ac3d(obj.modelFileList{iRoom});
                        obj.model{iRoom}.plotModel(tgtAxes, comp2axesMapping, wireframe);
                        hold on;
                    end
                else
                    obj.model = load_ac3d(obj.modelFileList);
                    obj.model.plotModel(tgtAxes, comp2axesMapping, wireframe);
                end
            else
                if iscell(obj.model)
                    for iRoom = 1 : numel(obj.model)
                        obj.model{iRoom}.plotModel(tgtAxes, comp2axesMapping, wireframe);
                        hold on;
                    end
                else
                    obj.model.plotModel(tgtAxes, comp2axesMapping, wireframe);
                end
            end
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
            % plot source and receivers
            spos = obj.getSourcePosition;
            snames = obj.getSourceNames;
            
            rpos = obj.getReceiverPosition;
            rnames = obj.getReceiverNames;
            
            plot3(spos(:,3),spos(:,1),spos(:,2),'marker','o','markersize',9,'linestyle','none','linewidth',1.5)
            plot3(rpos(:,3),rpos(:,1),rpos(:,2),'marker','x','markersize',9,'linestyle','none','linewidth',1.5)
            
            % plot view/up vectors (red/green) of receivers
            sview = obj.getSourceViewVectors;
            sup = obj.getSourceUpVectors;
            
            quiver3(spos(:,3),spos(:,1),spos(:,2),0.5*sview(:,3),0.5*sview(:,1),0.5*sview(:,2),'color','r','maxheadsize',1.5,'linewidth',1.5);
            quiver3(spos(:,3),spos(:,1),spos(:,2),0.5*sup(:,3),0.5*sup(:,1),0.5*sup(:,2),'color','g','maxheadsize',1.5,'linewidth',1.5);
            
            % plot view/up vectors (red/green) of receivers
            rview = obj.getReceiverViewVectors;
            rup = obj.getReceiverUpVectors;
            
            quiver3(rpos(:,3),rpos(:,1),rpos(:,2),0.5*rview(:,3),0.5*rview(:,1),0.5*rview(:,2),'color','r','maxheadsize',1.5,'linewidth',1.5);
            quiver3(rpos(:,3),rpos(:,1),rpos(:,2),0.5*rup(:,3),0.5*rup(:,1),0.5*rup(:,2),'color','g','maxheadsize',1.5,'linewidth',1.5);
            
            % plot names
            text(spos(:,3)+0.2,spos(:,1),spos(:,2),snames)
            text(rpos(:,3)+0.2,rpos(:,1),rpos(:,2),rnames)
727 728
        end
        
729 730 731 732
        %------------------------------------------------------------------
        function plotMaterialsAbsorption(obj, exportPlot)
            
            if nargin < 2
733
               exportPlot = false; 
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
            end
            
            freqVector = [20 25 31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000];
            freqLabel3rdVisual = { '', '', '31.5 Hz', '', '', '' '', '  ', '  125 Hz', ' ', ' ', ...
                '', ' ', ' ', '  500 Hz', ' ', '  ', '', '', ' ', '   2 kHz', ...
                ' ', '', '', '', '', '   8 kHz', '  ', '', '', '20 kHz'};

            yticks = { '0.0','', '0.20','','0.40','','0.60','','0.80','','1.0'};

            allMaterials = obj.getRoomMaterialNames;
            numberMaterials = length(allMaterials);

            currentMaterial = itaResult;
            currentMaterial.freqVector = freqVector;
            currentMaterial.freqData = [];

750 751
            for iMat=1:numberMaterials
                [absorp scatter ] = obj.getMaterial(allMaterials{iMat});
752
                currentMaterial.freqData = [ currentMaterial.freqData absorp' ];
753 754 755
                currentSurfaceArea = obj.getSurfaceAreaOfMaterial(allMaterials{iMat});
                allMaterials{iMat} = strrep(allMaterials{iMat},'_',' ');
                allMaterials{iMat} = [ allMaterials{iMat} ' (S = ' num2str(currentSurfaceArea,'%5.2f') ' m ;'];
756
                allMaterials{iMat} = [ allMaterials{iMat} ' A (Eyring, f=1000 Hz) = ' num2str(-currentSurfaceArea*log(1-currentMaterial.freqData(18,iMat)),'%5.2f') ' m )'];
757 758 759 760
            end

            currentMaterial.channelNames = allMaterials;
            currentMaterial.allowDBPlot = false;
761
            ita_plot_freq(currentMaterial,'LineWidth',2);
762 763
            
            % change format of plot
764 765 766 767 768
            title('');
            ylabel('Absorption coefficient');
            xlabel('Frequency in Hz');
            set(gca,'XLim',[63 20000]);
            set(gca,'YLim',[0 1]);
769 770
            leg = findobj(gcf,'Tag','legend');
            set(leg,'Location','NorthWest');
771
            set(leg,'FontSize',12);
772 773 774 775 776 777
            
            % remove [1] in legend entry
            for iMat=1:numberMaterials
                leg.String{iMat} = leg.String{iMat}(1:end-4);
            end
            
778

779
            % export plot to raven output
780
            if (exportPlot)
781 782 783 784 785
              [pathstr,name,ext] = fileparts(obj.ravenProjectFile);
              dateTimeStr = datestr(now,30);
              dateTimeStr = strrep(dateTimeStr,'T','_');
              fileName = [ obj.pathResults '\Absorption_' name '_' dateTimeStr '.png'];
              saveas(gcf,fileName);
786 787 788 789 790
            end
        end
        
        %------------------------------------------------------------------
        function plotMaterialsScattering(obj, exportPlot)
791
                    
792
            if nargin < 2
793
               exportPlot = false; 
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
            end
            
            freqVector = [20 25 31.5 40 50 63 80 100 125 160 200 250 315 400 500 630 800 1000 1250 1600 2000 2500 3150 4000 5000 6300 8000 10000 12500 16000 20000];
            freqLabel3rdVisual = { '', '', '31.5 Hz', '', '', '' '', '  ', '  125 Hz', ' ', ' ', ...
                '', ' ', ' ', '  500 Hz', ' ', '  ', '', '', ' ', '   2 kHz', ...
                ' ', '', '', '', '', '   8 kHz', '  ', '', '', '20 kHz'};

            yticks = { '0.0','', '0.20','','0.40','','0.60','','0.80','','1.0'};

            allMaterials = obj.getRoomMaterialNames;
            numberMaterials = length(allMaterials);

            currentMaterial = itaResult;
            currentMaterial.freqVector = freqVector;
            currentMaterial.freqData = [];

            for i=1:numberMaterials
                [absorp scatter ] = obj.getMaterial(allMaterials{i});
                currentMaterial.freqData = [ currentMaterial.freqData scatter' ];
813 814 815
                                currentSurfaceArea = obj.getSurfaceAreaOfMaterial(allMaterials{i});
                allMaterials{i} = strrep(allMaterials{i},'_',' ');
                allMaterials{i} = [ allMaterials{i} ' (S = ' num2str(currentSurfaceArea,'%5.2f') ' m )'];
816 817 818 819 820
            end

            currentMaterial.channelNames = allMaterials;
            currentMaterial.allowDBPlot = false;
            currentMaterial.pf;
821 822
            
            % change format of plot
823 824 825 826 827
            title('');
            ylabel('Scattering coefficient');
            xlabel('Frequency in Hz');
            set(gca,'XLim',[63 20000]);
            set(gca,'YLim',[0 1]);
828 829 830 831 832 833 834 835
            leg = findobj(gcf,'Tag','legend');
            set(leg,'Location','NorthWest');
            set(leg,'FontSize',9);
            
            % remove [1] in legend entry
            for iMat=1:numberMaterials
                leg.String{iMat} = leg.String{iMat}(1:end-4);
            end
836

837
            % export plot to raven output
838
            if (exportPlot)
839 840 841 842 843
              [pathstr,name,ext] = fileparts(obj.ravenProjectFile);
              dateTimeStr = datestr(now,30);
              dateTimeStr = strrep(dateTimeStr,'T','_');
              fileName = [ obj.pathResults '\Scattering_' name '_' dateTimeStr '.png'];
              saveas(gcf,fileName);
844 845 846 847 848
            end
        end
        
        
        
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
        % [Global] %
        %------------------------------------------------------------------
        function setProjectName(obj, projectName)
            obj.projectName = projectName;
            obj.rpf_ini.SetValues('Global', 'ProjectName', projectName);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSimulationTypeIS(obj, typeIS)
            obj.simulationTypeIS = typeIS;
            obj.rpf_ini.SetValues('Global', 'simulationTypeIS', typeIS);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSimulationTypeRT(obj, typeRT)
            obj.simulationTypeRT = typeRT;
            obj.rpf_ini.SetValues('Global', 'simulationTypeRT', typeRT);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateRIR(obj, genRIR)
            obj.generateRIR = genRIR;
            obj.rpf_ini.SetValues('Global', 'generateRIR', genRIR);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateBRIR(obj, genBRIR)
            obj.generateBRIR = genBRIR;
            obj.rpf_ini.SetValues('Global', 'generateBRIR', genBRIR);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateISHOA(obj, genISHOA)
            obj.generateISHOA = genISHOA;
            obj.rpf_ini.SetValues('Global', 'generateISHOA', genISHOA);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateRTHOA(obj, genRTHOA)
            obj.generateRTHOA = genRTHOA;
            obj.rpf_ini.SetValues('Global', 'generateRTHOA', genRTHOA);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateISVBAP(obj, genISVBAP)
            obj.generateISVBAP = genISVBAP;
            obj.rpf_ini.SetValues('Global', 'generateISVBAP', genISVBAP);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setGenerateRTVBAP(obj, genRTVBAP)
            obj.generateRTVBAP = genRTVBAP;
            obj.rpf_ini.SetValues('Global', 'generateRTVBAP', genRTVBAP);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setExportFilter(obj, exportFilter)
            obj.exportFilter = exportFilter;
            obj.rpf_ini.SetValues('Global', 'exportFilter', exportFilter);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setExportHistogram(obj, exportHisto)
            obj.exportHistogram = exportHisto;
            obj.rpf_ini.SetValues('Global', 'exportHistogram', exportHisto);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setExportWallHitLog(obj, exportWallHitLog)
            obj.exportWallHitLog = exportWallHitLog;
            obj.rpf_ini.SetValues('Global', 'exportWallHitList', exportWallHitLog);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setExportPlaneWaveList(obj, exportPlaneWaveList)
            obj.exportPlaneWaveList = exportPlaneWaveList;
            obj.rpf_ini.SetValues('Global', 'exportPlaneWaveList', exportPlaneWaveList);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setAccelerationType(obj, accelerationType)
            obj.accelerationType = accelerationType;
            obj.rpf_ini.SetValues('Global', 'accelerationType', accelerationType);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setLogPerformance(obj, logPerformance)
            obj.logPerformance = logPerformance;
            obj.rpf_ini.SetValues('Global', 'logPerformance', logPerformance);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setPortals(obj, portalTypes, portalStatus)
            if nargin < 3
                % if only 1 parameter is given (portalTypes), interprete
                % them as portal states! (more likely to be used like this)
                obj.rpf_ini.SetValues('Portals', 'portalStatus', obj.make_proper_string(portalTypes));     % 1 = open, 0 = closed
            else
                obj.rpf_ini.SetValues('Portals', 'portalType', portalTypes);
                obj.rpf_ini.SetValues('Portals', 'portalStatus', obj.make_proper_string(portalStatus));     % 1 = open, 0 = closed
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setTemperature(obj, temp)
            obj.rpf_ini.SetValues('Rooms', 'Temperature', num2str(temp));
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function temp = getTemperature(obj)
            temp = obj.rpf_ini.GetValues('Rooms', 'Temperature', -1);
        end
        
        %------------------------------------------------------------------
        function setHumidity(obj, humid)
            obj.rpf_ini.SetValues('Rooms', 'Humidity', num2str(humid));
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function humid = getHumidity(obj)
            humid = obj.rpf_ini.GetValues('Rooms', 'Humidity', -1);
        end
        
        %------------------------------------------------------------------
        function setPressure(obj, press)
            obj.rpf_ini.SetValues('Rooms', 'Pressure', num2str(press));
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function press = getPressure(obj)
            press = obj.rpf_ini.GetValues('Rooms', 'Pressure', -1);
        end
        
        %------------------------------------------------------------------
        function enableAirAbsorption(obj)
            obj.rpf_ini.SetValues('Rooms', 'noAirAbsorption', 0);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function disableAirAbsorption(obj)
            obj.rpf_ini.SetValues('Rooms', 'noAirAbsorption', 1);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
1013 1014 1015 1016 1017
        %------------------------------------------------------------------
        function airAbsEnabled = getAirAbsorptionEnabled(obj)
            airAbsEnabled = ~obj.rpf_ini.GetValues('Rooms', 'noAirAbsorption', 0);
        end        
        
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
        % [PrimarySources] %
        %------------------------------------------------------------------
        function setSourceNames(obj, sourceNames)
            if iscell(sourceNames)
                obj.sourceNameString = obj.cat_cell_of_strings(sourceNames);
                obj.sourceNames      = sourceNames;
            else
                obj.sourceNameString = sourceNames;
                obj.sourceNames      = textscan(obj.sourceNameString, '%s', 'Delimiter', ',');
                obj.sourceNames      = obj.sourceNames{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            end
            obj.rpf_ini.SetValues('PrimarySources', 'sourceNames', obj.sourceNameString);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function directivityName = getSourceDirectivity(obj, srcID)
            
            readstring = obj.rpf_ini.GetValues('PrimarySources', 'sourceDirectivity', '');
            if ~isempty(readstring)
                
                readstring   = textscan(readstring, '%s', 'Delimiter', ',');
                readstring   = readstring{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
                if nargin<2
                    directivityName=readstring;
                else
                    directivityName=readstring(srcID);
                end
                
            else
                obj.sourceDirectivity   = {};
            end
            
            % %            Original
            %             if iscell(obj.sourceDirectivity)
            %                 directivityName = obj.sourceDirectivity{sourceID + 1};
            %             else
            %                 obj.sourceDirectivity   = textscan(obj.sourceDirectivityString, '%s', 'Delimiter', ',');
            %                 obj.sourceDirectivity   = obj.sourceDirectivity{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            %                 directivityName = obj.sourceDirectivity{sourceID + 1};
            %             end
        end
        
        %------------------------------------------------------------------
        function setSourceDirectivity(obj, directivity)
            if iscell(directivity)
                obj.sourceDirectivityString = obj.cat_cell_of_strings(directivity);
                obj.sourceDirectivity   = directivity;
            else
                obj.sourceDirectivityString = directivity;
                obj.sourceDirectivity   = textscan(obj.sourceDirectivityString, '%s', 'Delimiter', ',');
                obj.sourceDirectivity   = obj.sourceDirectivity{1}; % textscan liefert cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            end
            obj.rpf_ini.SetValues('PrimarySources', 'sourceDirectivity', obj.sourceDirectivityString);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function pos = getSourcePosition(obj, srcID)

            all_pos = obj.rpf_ini.GetValues('PrimarySources', 'sourcePositions');
            if (nargin < 2)
                pos = reshape(all_pos',3,length(all_pos)/3)';
            else
                pos = all_pos((srcID*3 + 1) : (srcID*3 + 3));
            end
        end
        %------------------------------------------------------------------
        function setSourcePositions(obj, pos, coord_trafo)
            %setSourcePositions(pos, [coord_trafo])
            %   coord_trafo: 3-element vector
            %                1. element: which of the given axis to use as x-coordinates
            %                2. element: which of the given axis to use as y-coordinates
            %                3. element: which of the given axis to use as z-coordinates
            
            % if input is string convert to matrix
            if ischar(pos)
                pos = reshape(sscanf(pos, '%f,'), 3, numel(pos)/3)';
            end
            
            % if input is itaCoordinates convert to matrix
            if isa(pos, 'itaCoordinates')
                pos = pos.cart;
            end
            
            % check dimensions
            if size(pos, 2) ~= 3
                error('Positions must be given in vector (1x3) or matrix (Nx3) format.');
            end
            
            % store matrix in RavenProject object
            obj.sourcePositions = pos;
            
            % store positions in .rpf file on disk
            if nargin > 2
                obj.rpf_ini.SetValues('PrimarySources', 'sourcePositions', obj.make_proper_string( ...
                    [sign(coord_trafo(1)) .* pos(:, abs(coord_trafo(1))), ...
                    sign(coord_trafo(2)) .* pos(:, abs(coord_trafo(2))), ...
                    sign(coord_trafo(3)) .* pos(:, abs(coord_trafo(3)))] ));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourcePositions', obj.make_proper_string(pos));
            end
            
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSourceViewVectors(obj, view)
            obj.sourceViewVectors = view;
            if isnumeric(view) || iscell(view)
                obj.rpf_ini.SetValues('PrimarySources', 'sourceViewVectors', obj.make_proper_string(view));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourceViewVectors', view);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSourceUpVectors(obj, up)
            obj.sourceUpVectors = up;
            if isnumeric(up) || iscell(up)
                obj.rpf_ini.SetValues('PrimarySources', 'sourceUpVectors', obj.make_proper_string(up));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourceUpVectors', up);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSourceSoundStates(obj, state)
            obj.sourceSoundStates   = state;
            if isnumeric(state) || iscell(state)
                obj.rpf_ini.SetValues('PrimarySources', 'sourceSoundStates', obj.make_proper_string(state));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourceSoundStates', state);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSourceLevels(obj, levels)
            obj.sourceSoundLevels   = levels;
            if isnumeric(levels) || iscell(levels)
                obj.rpf_ini.SetValues('PrimarySources', 'sourceSoundLevels', obj.make_proper_string(levels));
            else
                obj.rpf_ini.SetValues('PrimarySources', 'sourceSoundLevels', levels);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        % [Receiver] %
        %------------------------------------------------------------------
        function setReceiverNames(obj, rec_names)
            if iscell(rec_names)
                obj.receiverNameString = obj.cat_cell_of_strings(rec_names);
                obj.receiverNames      = rec_names;
            else
                obj.receiverNameString = rec_names;
                obj.receiverNames      = textscan(obj.receiverNameString, '%s', 'Delimiter', ',');
                obj.receiverNames      = obj.receiverNames{1}; % textscan liefer cell array in nochmal einer zelle, diese doppelkapselung wird hier rckgngig gemacht
            end
            obj.rpf_ini.SetValues('Receiver', 'receiverNames', obj.receiverNameString);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function pos = getReceiverPosition(obj, recID)
            all_pos = obj.rpf_ini.GetValues('Receiver', 'receiverPositions');
            if (nargin < 2)
                pos = reshape(all_pos',3,length(all_pos)/3)';
            else
                pos = all_pos((recID*3 + 1) : (recID*3 + 3));
            end
        end
        
        %------------------------------------------------------------------
        function rvv = getReceiverViewVectors(obj, recID)
          
            all_pos = obj.rpf_ini.GetValues('Receiver', 'receiverViewVectors');
            if (nargin < 2)
                rvv=reshape(all_pos',3,length(all_pos)/3)';
            else
                rvv = all_pos((recID*3 + 1) : (recID*3 + 3));
            end
        end
        
        %------------------------------------------------------------------
        function ruv = getReceiverUpVectors(obj, recID)
          
            all_pos = obj.rpf_ini.GetValues('Receiver', 'receiverUpVectors');
            if (nargin < 2)
                ruv = reshape(all_pos',3,length(all_pos)/3)';
            else
                ruv = all_pos((recID*3 + 1) : (recID*3 + 3));
            end
        end
        
        %------------------------------------------------------------------
         function rss = getReceiverStates(obj,recID)
            rss = obj.rpf_ini.GetValues('Receiver', 'receiverStates', -1);
            if nargin==2
                rss=rss(recID);
            end
         end
        
         %------------------------------------------------------------------
        function rn = getReceiverNames(obj,recID)
            rn = obj.rpf_ini.GetValues('Receiver', 'receiverNames', -1);
            rn = textscan(rn, '%s', 'Delimiter', ',');
            rn = rn{1};
            if nargin==2
                rn=rn{1}{recID};
            end
        end
        
        %------------------------------------------------------------------
        function setReceiverPositions(obj, pos, coord_trafo)
            %setReceiverPositions(pos, coord_trafo)
            %   coord_trafo: 3-element vector
            %                1. element: which of the given axis to use as x-coordinates
            %                2. element: which of the given axis to use as y-coordinates
            %                3. element: which of the given axis to use as z-coordinates
            
            % if input is string convert to matrix
            if ischar(pos)
                pos = reshape(sscanf(pos, '%f,'), 3, numel(pos)/3)';
            end
            
            % if input is itaCoordinates convert to matrix
            if isa(pos, 'itaCoordinates')
                pos = pos.cart;
            end
            
            % check dimensions
            if size(pos, 2) ~= 3
                error('Positions must be given in vector (1x3) or matrix (Nx3) format.');
            end
            
            % store matrix in RavenProject object
            obj.receiverPositions = pos;
            
            % store positions in .rpf file on disk
            if nargin > 2
                obj.rpf_ini.SetValues('Receiver', 'receiverPositions', obj.make_proper_string( ...
                    [sign(coord_trafo(1)) .* pos(:, abs(coord_trafo(1))), ...
                    sign(coord_trafo(2)) .* pos(:, abs(coord_trafo(2))), ...
                    sign(coord_trafo(3)) .* pos(:, abs(coord_trafo(3)))] ));
            else
                obj.rpf_ini.SetValues('Receiver', 'receiverPositions', obj.make_proper_string(pos));
            end
            
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setReceiverViewVectors(obj, view)
            obj.receiverViewVectors = view;
            if isnumeric(view) || iscell(view)
                obj.rpf_ini.SetValues('Receiver', 'receiverViewVectors', obj.make_proper_string(view));
            else
                obj.rpf_ini.SetValues('Receiver', 'receiverViewVectors', view);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setReceiverUpVectors(obj, up)
            obj.receiverUpVectors   = up;
            if isnumeric(up) || iscell(up)
                obj.rpf_ini.SetValues('Receiver', 'receiverUpVectors', obj.make_proper_string(up));
            else
                obj.rpf_ini.SetValues('Receiver', 'receiverUpVectors', up);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setReceiverStates(obj, states)
            obj.receiverStates = states;
            if isnumeric(states) || iscell(states)
                obj.rpf_ini.SetValues('Receiver', 'receiverStates', obj.make_proper_string(states));
            else
                obj.rpf_ini.SetValues('Receiver', 'receiverStates', states);
            end
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function directivityName = getReceiverHRTF(obj)
            directivityName = obj.rpf_ini.GetValues('Global', 'ProjectPath_HRTFDB');
        end
        
        %------------------------------------------------------------------
        function setReceiverHRTF(obj, HRTF)
            [pathHRTF,~,~] = fileparts(obj.fileHRTF);
            newFile = fullfile(pathHRTF, HRTF);
            
            % check if file path is absolute or relative path 
            % (if ':" is in path, path is absolute)
            if ~isempty(strfind(HRTF, ':'))
                newFile = HRTF;
            else
                newFile = fullfile(pathHRTF, HRTF);
            end
            
            if exist(newFile, 'file')
                obj.fileHRTF = newFile;
                obj.rpf_ini.SetValues('Global', 'ProjectPath_HRTFDB', obj.fileHRTF);
                obj.rpf_ini.WriteFile(obj.ravenProjectFile);
            else
                error(['File not found: ' newFile]);
            end
        end
        
        % [ImageSources] %
        %------------------------------------------------------------------
        function setISOrder_PS(obj, is_order)
            obj.ISOrder_PS          = is_order;
            obj.rpf_ini.SetValues('ImageSources', 'ISOrder_PS', is_order);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setISOrder_SS(obj, is_order)
            obj.ISOrder_SS          = is_order;
            obj.rpf_ini.SetValues('ImageSources', 'ISOrder_SS', is_order);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSkipDirectSound(obj, skipit)
            obj.ISSkipDirectSound   = skipit;
            obj.rpf_ini.SetValues('ImageSources', 'ISSkipDirectSound', skipit);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        % [RayTracing] %
        %------------------------------------------------------------------
        function setNumParticles(obj, num_particles)
            obj.numParticles_Sphere = num_particles;
            obj.rpf_ini.SetValues('RayTracing', 'numberOfParticles_DetectionSphere', num_particles);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setNumParticles_Portal(obj, num_particles)
            obj.numParticles_Portal = num_particles;
            obj.rpf_ini.SetValues('RayTracing', 'numberOfParticles_Portal', num_particles);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setEnergyLoss(obj, energyloss)
            obj.energyLoss_Sphere = energyloss;
            obj.rpf_ini.SetValues('RayTracing', 'energyLoss_DetectionSphere', energyloss);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setEnergyLoss_Portal(obj, energyloss)
            obj.energyLoss_Portal = energyloss;
            obj.rpf_ini.SetValues('RayTracing', 'energyLoss_Portal', energyloss);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end        
        
        %------------------------------------------------------------------
1384
        function setTimeSlotLength(obj, slotlength)   % set timeslot lengt in ms !
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542
            obj.timeSlotLength = slotlength;
            obj.rpf_ini.SetValues('RayTracing', 'timeResolution_DetectionSphere', slotlength);
            obj.rpf_ini.SetValues('RayTracing', 'timeResolution_Portal', slotlength);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setRadiusDetectionSphere(obj, radius)
            obj.radiusSphere        = radius;
            obj.rpf_ini.SetValues('RayTracing', 'radius_DetectionSphere', radius);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        % [Filter] %
        %------------------------------------------------------------------
        function setFilterLength(obj, filter_length)    % filter length parameter needed in [ms]
            if filter_length < 3
                filter_length = filter_length * 1000;
                filter_length = fix(filter_length);
                disp(['Filter length should be set in milliseconds. Filter Length now set to ' num2str(filter_length) ' ms.']);
            else
                filter_length = fix(filter_length);
            end
            
            obj.filterLength = filter_length;
            obj.rpf_ini.SetValues('RayTracing', 'filterLength_DetectionSphere', filter_length);
            obj.rpf_ini.SetValues('RayTracing', 'filterLength_Portal', filter_length);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setFilterLengthToReverbTime(obj, roomID)
            % get approximate reverberation time and set filter length accordingly
            if iscell(obj.modelFileList)
                if (nargin < 2)
                    disp('Please define which room should be used. Now using the first room (roomID = 0).');
                    roomID = 0;
                end
                if isempty(obj.model)
                    roommodel = load_ac3d(obj.modelFileList{roomID + 1});
                else
                    roommodel = obj.model{roomID + 1};
                end
            else
                if isempty(obj.model)
                    roommodel = load_ac3d(obj.modelFileList);
                else
                    roommodel = obj.model;
                end
            end
            
            RT = roommodel.getReverbTime(obj.pathMaterials);
            filter_length = max(RT) * 1.2 * 1000;     % filter length parameter needed in [ms] and 20% additional headroom
            obj.setFilterLength(filter_length);
        end
        
        %------------------------------------------------------------------
        function setFixPoissonSequence(obj, fixit)
            obj.fixPoissonSequence = fixit;
            obj.rpf_ini.SetValues('Filter', 'setFixPoissonSequence', fixit);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setPoissonSequenceNumber(obj, number)
            obj.poissonSequenceNumber = number;
            obj.rpf_ini.SetValues('Filter', 'poissonSequenceNumber', number);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setFilterResolution(obj, octOr3rd)
            %setFilterResolution(obj, octOr3rd)
            % 1 = Octave (or 'oct'), 0 = 3rd Octave (or '3rd')
            if ~isnumeric(octOr3rd)
                octOr3rd = double(strcmp(octOr3rd, 'oct'));
                if ~octOr3rd
                    octOr3rd = double(strcmp(octOr3rd, '3rd'));
                end
            end
            obj.filterResolution = octOr3rd;
            obj.rpf_ini.SetValues('Filter', 'filterResolution', octOr3rd);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setFixReflectionPattern(obj, fixit)
            obj.fixReflectionPattern = fixit;
            obj.rpf_ini.SetValues('RayTracing', 'fixReflectionPattern', fixit);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setAmbisonicsOrder(obj, order)
            obj.ambisonicsOrder = order;
            obj.rpf_ini.SetValues('Filter', 'ambisonicsOrder', order);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setNumberSpreadedSources(obj, numberSpreadedSrc)
            obj.numberSpreadedSources = numberSpreadedSrc;
            obj.rpf_ini.SetValues('Filter', 'numberSpreadedSources', numberSpreadedSrc);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setSpreadingStdDeviation(obj, spreadingStdDev)
            obj.spreadingStdDeviation = spreadingStdDev;
            obj.rpf_ini.SetValues('Filter', 'spreadingStdDeviation', spreadingStdDev);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setFftDegreeForWallFilterInterpolation(obj, fft_degree)
            obj.fftDegreeForWallFilterInterpolation = fft_degree;
            obj.rpf_ini.SetValues('Filter', 'fftDegreeForWallFilterInterpolation', fft_degree);
            obj.rpf_ini.WriteFile(obj.ravenProjectFile);
        end
        
        %------------------------------------------------------------------
        function setMaterial(obj, materialname, alpha, scatter, roomID)
            %
            %   setMaterial(materialname, alpha, scatter, roomID)
            %
            %       materialname can be the filename of the .mat file (without
            %           extension or a number to address the material ID if the
            %           current room (can be further specified by roomID).
            %
            %       alpha and scatter have to be size of
            %           - 31 elements (for one-third octave resolution)
            %           - 10 elements (for octave resolution)
            %           - or a single number (flat spectrum)
            
            if nargin < 4
                scatter = 0.3;
            end
            
            % check if a material ID was given instead of a material name
            if isnumeric(materialname)
                % addressing by material ID (which is dependent on the room that is currently loaded!)
                matID = materialname;
                if nargin < 5
                    roomID = 0;
                end
                materialsInCurrentRoom = obj.getRoomMaterialNames(roomID);
                matname = materialsInCurrentRoom{matID + 1};
            else
                matname = materialname;
            end
            
            mat_filename = fullfile(obj.pathMaterials, [matname '.mat']);
            
            % open file for writing
            fid = fopen(mat_filename, 'wt');
            % print header
            fprintf(fid, '[Material]\r\n');
            fprintf(fid, ['name=' matname '\r\n']);
1543
            fprintf(fid, ['notes=Generated/Modified by MATLAB script (' datestr(now) ')\r\n']);
1544 1545 1546 1547 1548
            
            % parse input data
            if length(alpha) == 1
                alpha = ones(1,31) * alpha;
            elseif length(alpha) ~= 31 && length(alpha) ~= 10
1549
                disp('ERROR! alpha has to be a vector with the length 1,10, or 31.');
1550 1551 1552 1553 1554
                return;
            end
            if length(scatter) == 1
                scatter = ones(1,31) * scatter;
            elseif length(scatter) ~= 31 && length(scatter) ~= 10
1555
                disp('ERROR! scatter has to be a vector with the length 1,10, or 31.');
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882
                return;
            end
            
            % print absorption values
            if length(alpha)==31
                fprintf(fid, ['absorp=' num2str(alpha(1), '%2.4f')]);
                for i = 1 : 30
                    fprintf(fid, [', ' num2str(alpha(i+1), '%2.4f')]);
                end
            else
                fprintf(fid, ['absorp=' num2str(alpha(1), '%2.4f')]);
                for i = 1 : 30
                    fprintf(fid, [', ' num2str(alpha(int32(i+1)/3), '%2.4f')]);
                end
            end
            fprintf(fid, '\r\n');
            
            % print scattering values
            if length(scatter)==31
                fprintf(fid, ['scatter=' num2str(scatter(1), '%2.4f')]);
                for i = 1 : 30
                    fprintf(fid, [', ' num2str(scatter(i+1), '%2.4f')]);
                end
            else
                fprintf(fid, ['scatter=' num2str(scatter(1), '%2.4f')]);
                for i = 1 : 30
                    fprintf(fid, [', ' num2str(scatter(int32(i+1)/3), '%2.4f')]);
                end
            end
            fprintf(fid, '\r\n');
            
            % print interpolation values
            if length(alpha)==31
                fprintf(fid, 'interpol=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\r\n');
            else
                fprintf(fid, 'interpol=1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1\r\n');
            end
            
            % close file
            fclose(fid);
        end
        
        %------------------------------------------------------------------
        function order = getAmbisonicsOrder(obj)
            order = obj.rpf_ini.GetValues('Filter', 'ambisonicsOrder', -1);
        end
        
        %------------------------------------------------------------------
        function numberSpreadedSources = getNumberSpreadedSources(obj)
            numberSpreadedSources = obj.rpf_ini.GetValues('Filter', 'numberSpreadedSources', 0);
        end
        
        %------------------------------------------------------------------
        function spreadingStdDeviation = getSpreadingStdDeviation(obj)
            spreadingStdDeviation = obj.rpf_ini.GetValues('Filter', 'spreadingStdDeviation', 0.2);
        end
        
        %------------------------------------------------------------------
        function sourceviewvectors = getSourceViewVectors(obj,srcID)
            
            all_pos = obj.rpf_ini.GetValues('PrimarySources', 'sourceViewVectors');
            if (nargin < 2)
                sourceviewvectors=reshape(all_pos',3,length(all_pos)/3)';
            else
                sourceviewvectors = all_pos((srcID*3 + 1) : (srcID*3 + 3));
            end
        end
        
        %------------------------------------------------------------------
        function suv = getSourceUpVectors(obj,srcID)
            
            all_pos = obj.rpf_ini.GetValues('PrimarySources', 'sourceUpVectors');
            
            if (nargin < 2)
                suv = reshape(all_pos',3,length(all_pos)/3)';
            else
                suv = all_pos((srcID*3 + 1) : (srcID*3 + 3));
            end
            
        end
        
        %------------------------------------------------------------------
        function sss = getSourceSoundStates(obj,srcID)
            sss = obj.rpf_ini.GetValues('PrimarySources', 'sourceSoundStates', -1);
            if nargin==2
                sss=sss(srcID);
            end
        end
        
        %------------------------------------------------------------------
        function ssl = getSourceSoundLevels(obj,srcID)
            ssl = obj.rpf_ini.GetValues('PrimarySources', 'sourceSoundLevels', -1);
            if nargin==2
                ssl=ssl(srcID);
            end
        end
        
        %------------------------------------------------------------------
        function sn = getSourceNames(obj,srcID)
            sn = obj.rpf_ini.GetValues('PrimarySources', 'sourceNames', -1);
            sn = textscan(sn, '%s', 'Delimiter', ',');
            sn = sn{1};
            if nargin==2
                sn=sn{1}{srcID};
            end
        end
        
        %------------------------------------------------------------------
        function [absorp, scatter] = getMaterial(obj, materialName, roomID)
            % check if a material ID was given instead of a material name
            if isnumeric(materialName)
                % addressing by material ID (which is dependent on the room that is currently loaded!)
                matID = materialName;
                if nargin < 3
                    roomID = 0;
                end
                materialsInCurrentRoom = obj.getRoomMaterialNames(roomID);
                matname = materialsInCurrentRoom{matID + 1};
            else
                if (numel(materialName) > 4) && isequal(materialName(end-3:end), '.mat')
                    materialName = materialName(1:end-4);
                end
                matname = materialName;
            end
            
            ini = IniConfig();
            ini.ReadFile(fullfile(obj.pathMaterials, [matname '.mat']));
            
            absorp = ini.GetValues('Material', 'absorp');
            
            if nargout > 1
                scatter = ini.GetValues('Material', 'scatter');
            end
        end
        
        %------------------------------------------------------------------
        function monauralIR = getMonauralImpulseResponse(obj)
            if isempty(obj.monauralIR)
                error('No monaural impulse response present.');
            end
            
            if numel(obj.monauralIR) > 1
                monauralIR = obj.monauralIR;
            else
                monauralIR = obj.monauralIR{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function monauralIRitaAudio = getMonauralImpulseResponseItaAudio(obj)
            if isempty(obj.monauralIR)
                error('No monaural impulse response present.');
            end
            
            monauralIRitaAudio = itaAudio(size(obj.monauralIR));
            
            for iSrc = 1 : size(obj.monauralIR, 1)
                for iRec = 1 : size(obj.monauralIR, 2)
                    monauralIRitaAudio(iSrc,iRec).timeData = obj.monauralIR{iSrc,iRec};
                    monauralIRitaAudio(iSrc,iRec).samplingRate = obj.sampleRate;
                    monauralIRitaAudio(iSrc,iRec).signalType = 'energy';
                    monauralIRitaAudio(iSrc,iRec).channelNames{1} = obj.receiverNames{iRec};
                end
            end
        end
        
        %------------------------------------------------------------------
        function monauralIR_IS = getMonauralImpulseResponseImageSources(obj)
            if isempty(obj.monauralIR_IS)
                error('No monaural image source impulse response present.');
            end
            
            if numel(obj.monauralIR_IS) > 1
                monauralIR_IS = obj.monauralIR_IS;
            else
                monauralIR_IS = obj.monauralIR_IS{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function monauralIR_RT = getMonauralImpulseResponseRayTracing(obj)
            if isempty(obj.monauralIR_RT)
                error('No monaural ray tracing impulse response present.');
            end
            
            if numel(obj.monauralIR_RT) > 1
                monauralIR_RT = obj.monauralIR_RT;
            else
                monauralIR_RT = obj.monauralIR_RT{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function monauralIRitaAudio = getMonauralImpulseResponseImageSourcesItaAudio(obj)
            if isempty(obj.monauralIR_IS)
                error('No monaural image source impulse response present.');
            end
            
            monauralIRitaAudio = itaAudio(size(obj.monauralIR_IS));
            
            for iSrc = 1 : size(obj.monauralIR_IS, 1)
                for iRec = 1 : size(obj.monauralIR_IS, 2)
                    monauralIRitaAudio(iSrc,iRec).timeData = obj.monauralIR_IS{iSrc,iRec};
                    monauralIRitaAudio(iSrc,iRec).samplingRate = obj.sampleRate;
                    monauralIRitaAudio(iSrc,iRec).signalType = 'energy';
                    monauralIRitaAudio(iSrc,iRec).channelNames{1} = obj.receiverNames{iRec};
                end
            end
        end
        
        %------------------------------------------------------------------
        function monauralIRitaAudio = getMonauralImpulseResponseRayTracingItaAudio(obj)
            if isempty(obj.monauralIR_RT)
                error('No monaural ray tracing impulse response present.');
            end
            
            monauralIRitaAudio = itaAudio(size(obj.monauralIR_RT));
            
            for iSrc = 1 : size(obj.monauralIR_RT, 1)
                for iRec = 1 : size(obj.monauralIR_RT, 2)
                    monauralIRitaAudio(iSrc,iRec).timeData = obj.monauralIR_RT{iSrc,iRec};
                    monauralIRitaAudio(iSrc,iRec).samplingRate = obj.sampleRate;
                    monauralIRitaAudio(iSrc,iRec).signalType = 'energy';
                    monauralIRitaAudio(iSrc,iRec).channelNames{1} = obj.receiverNames{iRec};
                end
            end
        end
        
        %------------------------------------------------------------------
        function binauralIR = getBinauralImpulseResponse(obj)
            if isempty(obj.binauralIR)
                error('No binaural impulse response present.');
            end
            
            if numel(obj.binauralIR) > 1
                binauralIR = obj.binauralIR;
            else
                binauralIR = obj.binauralIR{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function binauralIRitaAudio = getBinauralImpulseResponseItaAudio(obj)
            if isempty(obj.binauralIR)
                error('No binaural impulse response present.');
            end
            
            binauralIRitaAudio = itaAudio(size(obj.binauralIR));
            
            for iSrc = 1 : size(obj.binauralIR, 1)
                for iRec = 1 : size(obj.binauralIR, 2)
                    binauralIRitaAudio(iSrc,iRec).timeData = obj.binauralIR{iSrc,iRec};
                    binauralIRitaAudio(iSrc,iRec).samplingRate = obj.sampleRate;
                    binauralIRitaAudio(iSrc,iRec).signalType = 'energy';
                    binauralIRitaAudio(iSrc,iRec).channelNames{1} = [obj.receiverNames{iRec} '_Left'];
                    binauralIRitaAudio(iSrc,iRec).channelNames{2} = [obj.receiverNames{iRec} '_Right'];
                end
            end
        end
        
        %------------------------------------------------------------------
        function binauralIR_IS = getBinauralImpulseResponseImageSources(obj)
            if isempty(obj.binauralIR_IS)
                error('No binaural image source impulse response present.');
            end
            
            if numel(obj.binauralIR_IS) > 1
                binauralIR_IS = obj.binauralIR_IS;
            else
                binauralIR_IS = obj.binauralIR_IS{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function binauralIRitaAudio = getBinauralImpulseResponseImageSourcesItaAudio(obj)
            if isempty(obj.binauralIR_IS)
                error('No binaural image source impulse response present.');
            end
            
            binauralIRitaAudio = itaAudio(size(obj.binauralIR_IS));
            
            for iSrc = 1 : size(obj.binauralIR_IS, 1)
                for iRec = 1 : size(obj.binauralIR_IS, 2)
                    binauralIRitaAudio(iSrc,iRec).timeData = obj.binauralIR_IS{iSrc,iRec};
                    binauralIRitaAudio(iSrc,iRec).samplingRate = obj.sampleRate;
                    binauralIRitaAudio(iSrc,iRec).signalType = 'energy';
                    binauralIRitaAudio(iSrc,iRec).channelNames{1} = [obj.receiverNames{iRec} '_Left'];
                    binauralIRitaAudio(iSrc,iRec).channelNames{2} = [obj.receiverNames{iRec} '_Right'];
                end
            end
        end
        
        %------------------------------------------------------------------
        function binauralIR_RT = getBinauralImpulseResponseRayTracing(obj)
            if isempty(obj.binauralIR_RT)
                error('No binaural ray tracing impulse response present.');
            end
            
            if numel(obj.binauralIR_RT) > 1
                binauralIR_RT = obj.binauralIR_RT;
            else
                binauralIR_RT = obj.binauralIR_RT{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function binauralIRitaAudio = getBinauralImpulseResponseRayTracingItaAudio(obj)
            if isempty(obj.binauralIR_RT)
                error('No binaural image source impulse response present.');
            end
            
            binauralIRitaAudio = itaAudio(size(obj.binauralIR_RT));
            
            for iSrc = 1 : size(obj.binauralIR_RT, 1)
                for iRec = 1 : size(obj.binauralIR_RT, 2)
                    binauralIRitaAudio(iSrc,iRec).timeData = obj.binauralIR_RT{iSrc,iRec};
                    binauralIRitaAudio(iSrc,iRec).samplingRate = obj.sampleRate;
                    binauralIRitaAudio(iSrc,iRec).signalType = 'energy';
                    binauralIRitaAudio(iSrc,iRec).channelNames{1} = [obj.receiverNames{iRec} '_Left'];
                    binauralIRitaAudio(iSrc,iRec).channelNames{2} = [obj.receiverNames{iRec} '_Right'];
                end
            end
        end
        
        %------------------------------------------------------------------
        function binauralPoissonSequenceitaAudio = getBinauralPoissonSequenceItaAudio(obj)
            
1883
            data = load([ obj.pathResults '\binauralPoissonNoiseProcess.txt']);
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739
            
            binauralPoissonSequenceitaAudio = itaAudio;
            binauralPoissonSequenceitaAudio.samplingRate = obj.sampleRate;
            binauralPoissonSequenceitaAudio.signalType = 'energy';
            binauralPoissonSequenceitaAudio.timeData = data;
            binauralPoissonSequenceitaAudio.channelNames{1} = [obj.receiverNames{end} '_Left'];
            binauralPoissonSequenceitaAudio.channelNames{2} = [obj.receiverNames{end} '_Right'];
        end
        
        %------------------------------------------------------------------
        function binauralImpulseResponse = generateBinauralImpulseResponseItaAudio(obj)
            % get noise process (containing poisson distributed HRIRs without temporal or spectral weighting)
            poisson = obj.getBinauralPoissonSequenceItaAudio();
            
            % add white noise to poisson sequence (for more realistic simulaitons
            %             noiseLevel = 10^(-20/10) * max(max(poisson.timeData));
            %             addNoise = ita_generate('whitenoise', noiseLevel, poisson.samplingRate, poisson.fftDegree);
            %             addNoise.timeData(:,2) = addNoise.timeData(:,1);    % add second channel
            %             poisson = poisson + addNoise;
            
            % get ray tracing results
            %             histo = obj.getHistogramRayTracing();
            histo = obj.histogramRT();
            if iscell(histo)
                if numel(histo) > 1
                    disp('WARNING! Generating binaural impulse response only for the last receiver!')
                end
                histo = histo{end};
            end
            
            % low pass late part of the histogram to avoid bubble sound
            histo.data = obj.applyLowPassToLatePartOfHistogram(histo.data);
            
            % convert added energy histogram to sound pressure envelope histogram and
            % time-interpolate time slot quantized histogram to full number of samples length
            histoInterpolatedToSamples = interp1(histo.timevector, sqrt(histo.data), poisson.timeVector, 'cubic');
            histoInterpolatedToSamples(histoInterpolatedToSamples < 0) = 0;
            
            %             energyScalingFactor = sum(histo.data) ./ sum(histoInterpolatedToSamples); % is vector of frequencies, sums up the time slots
            %             energyScalingFactor(isnan(energyScalingFactor)) = 0;
            %             histoInterpolatedToSamples = histoInterpolatedToSamples .* repmat(energyScalingFactor, poisson.nSamples, 1);
            
            % band-pass poisson sequence
            if size(histo.data, 2) == 10
                poissonFilteredLeft = ita_mpb_filter(poisson.ch(1), 'oct', 1, 'order', 6);
                poissonFilteredRight = ita_mpb_filter(poisson.ch(2), 'oct', 1, 'order', 6);
            else
                poissonFilteredLeft = ita_mpb_filter(poisson.ch(1), 'oct', 3, 'order', 6);
                poissonFilteredRight = ita_mpb_filter(poisson.ch(2), 'oct', 3, 'order', 6);
                % toolbox 30 thirdocts vs. ravens 31 thirdocts, delete 20 Hz data
                histoInterpolatedToSamples(:, 1) = [];
            end
            
            % temporal shaping of the poisson sequence using the sound presssure envelope from the histogram
            poissonFilteredLeft.timeData(:, :) = poissonFilteredLeft.timeData(:,:) .* histoInterpolatedToSamples;
            poissonFilteredRight.timeData(:, :) = poissonFilteredRight.timeData(:, :) .* histoInterpolatedToSamples;
            
            % create new itaAudio to store resulting filter
            binauralImpulseResponse = itaAudio;
            binauralImpulseResponse.samplingRate = obj.sampleRate;
            binauralImpulseResponse.signalType = 'energy';
            binauralImpulseResponse.timeData(:,:) = [sum(poissonFilteredLeft.timeData, 2) sum(poissonFilteredRight.timeData, 2)];
            
            % total energy scaling (total energy histogram == total energy impulse response of one channel)
            % convert averaged energy histogram to added energy histogram
            histo.data = obj.powerSpectrum2energySpectrum(histo.data);
            totalEnergyHistogram = sum(sum(histo.data,2));
            numTimeSlots = size(histo.data, 1);
            maxEnergyHistogram = (1 * numTimeSlots);    % 1 == EnergyAdded for one timeslot if all frequencyies are = 1
            maxEnergyPoisson = sum(poisson.timeData.^2);    % vector(2) for left and right channel
            totalEnergyImpulseResponse = sum(binauralImpulseResponse.timeData.^2);  % vector(2) for left and right channel
            binauralImpulseResponse.timeData = binauralImpulseResponse.timeData .* sqrt((maxEnergyPoisson / totalEnergyImpulseResponse) * (totalEnergyHistogram / maxEnergyHistogram));
            
            % add image sources
            BRIR_IS = obj.getBinauralImpulseResponseImageSourcesItaAudio();
            [BRIR_IS, binauralImpulseResponse] = ita_extend_dat(BRIR_IS, binauralImpulseResponse);
            binauralImpulseResponse = BRIR_IS + binauralImpulseResponse;
        end
        
        %------------------------------------------------------------------
        function ambisonicsIR = getAmbisonicsImpulseResponse(obj)
            if isempty(obj.ambisonicsIR)
                error('No ambisonics b-format impulse response present.');
            end
            
            if numel(obj.ambisonicsIR) > 1
                ambisonicsIR = obj.ambisonicsIR;
            else
                ambisonicsIR = obj.ambisonicsIR{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function ambisonicsIRita = getAmbisonicsImpulseResponseItaAudio(obj)
            if isempty(obj.ambisonicsIR)
                error('No ambisonics b-format impulse response present.');
            end
            
            ambisonicsIRita = itaAudio(size(obj.ambisonicsIR));
            
            for iSrc = 1 : size(obj.ambisonicsIR, 1)
                for iRec = 1 : size(obj.ambisonicsIR, 2)
                    ambisonicsIRita(iSrc,iRec).timeData = obj.ambisonicsIR{iSrc,iRec};
                    ambisonicsIRita(iSrc,iRec).samplingRate = obj.sampleRate;
                    ambisonicsIRita(iSrc,iRec).signalType = 'energy';
                    for linInd = 1 : ambisonicsIRita(iSrc,iRec).nChannels
                        [deg, ord] = ita_sph_linear2degreeorder(linInd);
                        ambisonicsIRita(iSrc,iRec).channelNames{linInd} = [obj.receiverNames{iRec} '_Degree(' num2str(deg) ')_Order(' num2str(ord) ')'];
                    end
                end
            end
        end
        
        %------------------------------------------------------------------
        function ambisonicsIR_IS = getAmbisonicsImpulseResponseImageSources(obj)
            if isempty(obj.ambisonicsIR_IS)
                error('No image sources ambisonics b-format impulse response present.');
            end
            
            if numel(obj.ambisonicsIR_IS) > 1
                ambisonicsIR_IS = obj.ambisonicsIR_IS;
            else
                ambisonicsIR_IS = obj.ambisonicsIR_IS{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function ambisonicsIRita = getAmbisonicsImpulseResponseImageSourcesItaAudio(obj)
            if isempty(obj.ambisonicsIR_IS)
                error('No image sources ambisonics b-format impulse response present.');
            end
            
            ambisonicsIRita = itaAudio(size(obj.ambisonicsIR_IS));
            
            for iSrc = 1 : size(obj.ambisonicsIR_IS, 1)
                for iRec = 1 : size(obj.ambisonicsIR_IS, 2)
                    ambisonicsIRita(iSrc,iRec).timeData = obj.ambisonicsIR_IS{iSrc,iRec};
                    ambisonicsIRita(iSrc,iRec).samplingRate = obj.sampleRate;
                    ambisonicsIRita(iSrc,iRec).signalType = 'energy';
                    for linInd = 1 : ambisonicsIRita(iSrc,iRec).nChannels
                        [deg, ord] = ita_sph_linear2degreeorder(linInd);
                        ambisonicsIRita(iSrc,iRec).channelNames{linInd} = [obj.receiverNames{iRec} '_Degree(' num2str(deg) ')_Order(' num2str(ord) ')'];
                    end
                end
            end
        end
        
        %------------------------------------------------------------------
        function ambisonicsIR_RT = getAmbisonicsImpulseResponseRayTracing(obj)
            if isempty(obj.ambisonicsIR_RT)
                error('No ray tracing ambisonics b-format impulse response present.');
            end
            
            if numel(obj.ambisonicsIR_RT) > 1
                ambisonicsIR_RT = obj.ambisonicsIR_RT;
            else
                ambisonicsIR_RT = obj.ambisonicsIR_RT{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function ambisonicsIRita = getAmbisonicsImpulseResponseRayTracingItaAudio(obj)
            if isempty(obj.ambisonicsIR_RT)
                error('No ray tracing ambisonics b-format impulse response present.');
            end
            
            ambisonicsIRita = itaAudio(size(obj.ambisonicsIR_RT));
            
            for iSrc = 1 : size(obj.ambisonicsIR_RT, 1)
                for iRec = 1 : size(obj.ambisonicsIR_RT, 2)
                    ambisonicsIRita(iSrc,iRec).timeData = obj.ambisonicsIR_RT{iSrc,iRec};
                    ambisonicsIRita(iSrc,iRec).samplingRate = obj.sampleRate;
                    ambisonicsIRita(iSrc,iRec).signalType = 'energy';
                    for linInd = 1 : ambisonicsIRita(iSrc,iRec).nChannels
                        [deg, ord] = ita_sph_linear2degreeorder(linInd);
                        ambisonicsIRita(iSrc,iRec).channelNames{linInd} = [obj.receiverNames{iRec} '_Degree(' num2str(deg) ')_Order(' num2str(ord) ')'];
                    end
                end
            end
            
        end
        
        %------------------------------------------------------------------
        function vbapIR = getVBAPImpulseResponse(obj)
            if isempty(obj.vbapIR)
                error('No vbap impulse response present.');
            end
            
            if numel(obj.vbapIR) > 1
                vbapIR = obj.vbapIR;
            else
                vbapIR = obj.vbapIR{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function vbapIRita = getVBAPImpulseResponseItaAudio(obj)
            if isempty(obj.vbapIR)
                error('No vbap impulse response present.');
            end
            
            vbapIRita = itaAudio(size(obj.vbapIR));
            
            for iSrc = 1 : size(obj.vbapIR, 1)
                for iRec = 1 : size(obj.vbapIR, 2)
                    vbapIRita(iSrc,iRec).timeData = obj.vbapIR{iSrc,iRec};
                    vbapIRita(iSrc,iRec).samplingRate = obj.sampleRate;
                    vbapIRita(iSrc,iRec).signalType = 'energy';
                    for linInd = 1 : vbapIRita(iSrc,iRec).nChannels
                        vbapIRita(iSrc,iRec).channelNames{linInd} = [obj.receiverNames{iRec} '_Speaker_' num2str(linInd)];
                    end
                end
            end
        end
        
        %------------------------------------------------------------------
        function vbapIR_IS = getVBAPImpulseResponseImageSources(obj)
            if isempty(obj.vbapIR_IS)
                error('No image sources vbap impulse response present.');
            end
            
            if numel(obj.vbapIR_IS) > 1
                vbapIR_IS = obj.vbapIR_IS;
            else
                vbapIR_IS = obj.vbapIR_IS{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function vbapIRita = getVBAPImpulseResponseImageSourcesItaAudio(obj)
            if isempty(obj.vbapIR_IS)
                error('No image sources vbap impulse response present.');
            end
            
            vbapIRita = itaAudio(size(obj.vbapIR_IS));
            
            for iSrc = 1 : size(obj.vbapIR_IS, 1)
                for iRec = 1 : size(obj.vbapIR_IS, 2)
                    vbapIRita(iSrc,iRec).timeData = obj.vbapIR_IS{iSrc,iRec};
                    vbapIRita(iSrc,iRec).samplingRate = obj.sampleRate;
                    vbapIRita(iSrc,iRec).signalType = 'energy';
                    for linInd = 1 : vbapIRita(iSrc,iRec).nChannels
                        vbapIRita(iSrc,iRec).channelNames{linInd} = [obj.receiverNames{iRec} '_Speaker_' num2str(linInd)];
                    end
                end
            end
        end
        
        %------------------------------------------------------------------
        function vbapIR_RT = getVBAPImpulseResponseRayTracing(obj)
            if isempty(obj.vbapIR_RT)
                error('No ray tracing vbap impulse response present.');
            end
            
            if numel(obj.vbapIR_RT) > 1
                vbapIR_RT = obj.vbapIR_RT;
            else
                vbapIR_RT = obj.vbapIR_RT{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function vbapIRita = getVBAPImpulseResponseRayTracingItaAudio(obj)
            if isempty(obj.vbapIR_RT)
                error('No ray tracing vbap impulse response present.');
            end
            
            vbapIRita = itaAudio(size(obj.vbapIR_RT));
            
            for iSrc = 1 : size(obj.vbapIR_RT, 1)
                for iRec = 1 : size(obj.vbapIR_RT, 2)
                    vbapIRita(iSrc,iRec).timeData = obj.vbapIR_RT{iSrc,iRec};
                    vbapIRita(iSrc,iRec).samplingRate = obj.sampleRate;
                    vbapIRita(iSrc,iRec).signalType = 'energy';
                    for linInd = 1 : vbapIRita(iSrc,iRec).nChannels
                        vbapIRita(iSrc,iRec).channelNames{linInd} = [obj.receiverNames{iRec} '_Speaker_' num2str(linInd)];
                    end
                end
            end
            
        end
        
        %------------------------------------------------------------------
        function histo = getHistogram(obj)
            if isempty(obj.histogram)
                error('No histogram present.');
            end
            
            if numel(obj.histogramRT) > 1
                histo = obj.histogram;
            else
                histo = obj.histogram{1,1};
            end
        end
        
        %------------------------------------------------------------------
        function histo = getHistogram_itaResult(obj)
            histo_data = obj.getHistogram();
            
            if ~iscell(histo_data)
                histo_data = {histo_data};
            end
            
            % pre-alloc multi-instance for all sources and receivers
            histo(size(obj.histogram,1), size(obj.histogram,2)) = itaResult();
            for iHisto = 1 : numel(obj.histogram)
                if ~isempty(obj.histogram{iHisto})
                    histo(iHisto).timeData = histo_data{iHisto}.data;
                    histo(iHisto).timeVector = histo_data{iHisto}.timevector;
                    if obj.filterResolution == 1
                        histo(iHisto).channelNames = strcat('Histogram ', obj.freqLabelOct);
                    else
                        histo(iHisto).channelNames = strcat('Histogram ', obj.freqLabel3rd);
                    end
                end
            end
        end
        
        %------------------------------------------------------------------
        function histo = getHistogramRayTracing(obj)
            if isempty(obj.histogramRT)
                raytracing_histo_files = obj.scan_output_folder(fullfile(obj.pathResults, obj.projectTag), '_RT'