classdef itaRavenProject < handle
%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
%
%
%
% Examples:
% rpf = itaRavenProject();
% rpf.SetModel('cave.ac');
% rpf.getEquationBasedReverbTime(); returns reverb time based on
% sabine equation
% rpf.run(); run simulation
% rpf.getT30(); get T30 based on simulation
% rpf.plotMaterialsAbsorption(); plots absorption coefficients
%
% Author: Soenke Pelzer (spe@akustik.rwth-aachen.de)
% Lukas Aspöck (las@akustik.rwth-aachen.de)
%
% Version: 0.3
% First release: 01.11.10
% Last revision: 24.06.20
% Copyright: Institute of Technical Acoustics, RWTH Aachen University
%
%
% 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.
%
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
ravenExe
ravenLogFile = 'RavenLog.txt'
ravenProjectFile
ravenIniFile
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
detectionSphereAziResolution
detectionSphereEleResolution
filterLength
timeSlotLength
radiusSphere
fixReflectionPattern
% [Filter] %
fixPoissonSequence
poissonSequenceNumber
filterResolution
maxReflectionDensity
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')
ravenExe64 = '..\bin64\RavenConsole64.exe'
ravenExe32 = '..\bin32\RavenConsole.exe'
rpf_ini
raven_ini
projectID
projectTag
projectLoaded = false
simulationDone = false
keepOutputFiles
plotModelHandle = [];
% [PrimarySources] %
sourceNameString
sourceDirectivityString
% [Receiver] %
receiverNameString
uniformReceiverGridX = []
uniformReceiverGridY = []
uniformReceiverGridZ = []
% RESULTS %
monoIR = []
monoIR_IS = []
monoIR_RT = []
binauralIR = []
binauralIR_IS = []
binauralIR_RT = []
ambisonicsIR = []
ambisonicsIR_IS = []
ambisonicsIR_RT = []
vbapIR = []
vbapIR_IS = []
vbapIR_RT = []
histogram = []
histogramRT = []
end
%---------------------- PUBLIC METHODS -------------------------------%
methods
%------------------------------------------------------------------
function obj = itaRavenProject(raven_project_file)
%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
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);
if (ischar(obj.ravenExe) && exist(obj.ravenExe,'file'))
obj.raven_ini.WriteFile(obj.ravenIniFile);
end
end
if (~exist(obj.ravenExe,'file'))
% neither the default relative raven console path nor the path in
% itaRaven.ini was found, try to locate RavenConsole
locatedRavenExe = which(obj.ravenExe(10:end));
% try default raven exe path after instalation
if isempty(locatedRavenExe)
if strcmp(computer('arch'), 'win32')
defaultInstallationPathRavenExe = 'C:\ITASoftware\Raven\bin32\RavenConsole.exe';
elseif strcmp(computer('arch'), 'win64')
defaultInstallationPathRavenExe = 'C:\ITASoftware\Raven\bin64\RavenConsole64.exe';
else
error('Only Windows OS are supported.');
end
if exist(defaultInstallationPathRavenExe,'file')
locatedRavenExe = defaultInstallationPathRavenExe;
obj.ravenExe = defaultInstallationPathRavenExe;
end
end
if isempty(locatedRavenExe)
disp('[itaRaven]:');
disp('No RAVEN binary was found! Please select path to the RAVEN console application (RavenConsole.exe/RavenConsole64.exe)!');
disp('To run RAVEN simulations, an installation of the RAVEN software is required. ');
disp('Individual licenses for academic purposes are available on request.');
disp('Please contact: las@akustik.rwth-aachen.de');
[ selectedRavenExe, selectedRavenPath] = uigetfile('*.exe',' No RAVEN binary was found! Please select path to RavenConsole.exe');
if (ischar(selectedRavenExe)&& ischar(selectedRavenPath))
obj.ravenExe = [ selectedRavenPath selectedRavenExe];
else
warning('WARNING: RAVEN binary path was set to default, but binary was not found. Please specify the correct path in itaRaven.ini');
obj.ravenExe = defaultInstallationPathRavenExe;
end
end
if (~ravenIniExists)
obj.raven_ini = IniConfig();
obj.raven_ini.AddSections({'Global'});
obj.raven_ini.AddKeys('Global', {'PathRavenExe'}, {obj.ravenExe});
obj.raven_ini.WriteFile(obj.ravenIniFile);
else
obj.raven_ini.SetValues('Global', {'PathRavenExe'}, {obj.ravenExe});
obj.raven_ini.WriteFile(obj.ravenIniFile);
end
end
% check if raven project file exists
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
function delete(obj)
obj.deleteResultsInRavenFolder();
end
%------------------------------------------------------------------
function setRavenIniPath(obj, newPath)
obj.ravenIniFile = newPath;
end
%------------------------------------------------------------------
function copyProjectToNewRPFFile(obj, newPath)
if (exist(fileparts(newPath),'dir'))
obj.ravenProjectFile = newPath;
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
else
error('itaRavenProject/copyProjectToNewRPFFile: invalid path');
end
end
%------------------------------------------------------------------
function setRavenExe(obj, newRavenExe)
if (exist(newRavenExe,'file'))
obj.ravenExe = newRavenExe;
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
else
error('[itaRaven]: Error: Path to new Raven binary not found!');
end
end
%------------------------------------------------------------------
function loadRavenConfig(obj, filename)
%loadRavenConfig - Reads an existing raven project file
%
% change relative to absolute path
if (~strcmp(filename(2),':'))
obj.ravenProjectFile = [pwd '\' filename];
else
obj.ravenProjectFile = filename;
end
obj.rpf_ini = IniConfig();
obj.rpf_ini.ReadFile(filename);
% [Global] %
obj.projectName = obj.rpf_ini.GetValues('Global', 'ProjectName', 'Matlab');
obj.projectTag = obj.projectName;
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);
% 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
end
% [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
if obj.ravenExe(2) == ':' % convert to absolute path
if (strcmp(obj.modelFileList(1:2),'..')), obj.modelFileList = [ ravenBasePath obj.modelFileList(3:end) ]; end
end
end
% [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 rückgängig 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 rückgängig 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 rückgängig 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);
%% check input data files (HRTF, source directivity, room model)
% HRTF (also shows if DAFF file is v15 or v17)
if (exist(obj.fileHRTF,'file') == 0)
warning('HRTF file not found at the specified location.');
else
if (contains(obj.fileHRTF,'.v17.daff'))
disp('itaRavenProject: Loaded DAFFv17 HRTF file');
end
if (contains(obj.fileHRTF,'.v15.daff'))
disp('itaRavenProject: Loaded DAFFv15 HRTF file');
end
end
% Source directivity (only checks first directivity file)
if (~isempty(obj.sourceDirectivity)) % first check if any directivity was defined
if (exist([ obj.pathDirectivities '\' obj.sourceDirectivity{1}],'file') == 0)
warning('Source directivity file not found at the specified location.');
else
if (contains(obj.sourceDirectivity{1},'.v17.daff'))
disp('itaRavenProject: Loaded DAFFv17 source directivity file');
end
if (contains(obj.sourceDirectivity{1},'.v15.daff'))
disp('itaRavenProject: Loaded DAFFv15 source directivity file');
end
end
end
% room model
if (numel(obj.modelFileList) == 0 )
warning('No room model file (*.ac) specified in project file.');
end
if (numel(obj.modelFileList) == 1 && exist(obj.modelFileList,'file') == 0)
warning('Room model file (*.ac) not found at the specified location.');
end
obj.projectLoaded = true;
end
%------------------------------------------------------------------
function reloadRavenConfig(obj, filename)
if nargin < 2
filename = obj.ravenProjectFile;
end
obj.loadRavenConfig(filename);
end
%------------------------------------------------------------------
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
%------------------------------------------------------------------
function run(obj)
if numel(obj.projectName) > 70
warning('Long project name. This might cause an error while writing output files. Consider resetting your project name!')
end
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);
% run the simulation
disp(['Running simulation... (' obj.ravenExe ')']);
if exist(obj.ravenLogFile, 'file')
delete(obj.ravenLogFile);
end
% system([obj.ravenExe ' "' obj.ravenProjectFile '" >> ' obj.ravenLogFile]);
if (~exist(obj.ravenExe,'file'))
error('[itaRaven]: Error: Cannot find Raven binary file! Please check itaRaven.ini file!');
end
prevPath = pwd;
cd(fileparts(obj.ravenExe));
dos(['"' obj.ravenExe '"' ' "' obj.ravenProjectFile '"'],'-echo');
cd(prevPath);
% restore the initial project name
obj.setProjectName(savedProjectName);
% gather results
disp('[R] Simulation seems to be finished. Getting results...');
[ numIRs, numOutputOther ] = obj.gatherResults();
disp([ '[R] Done. Result report: ' num2str(numIRs) ' room impulse response files and ' num2str(numOutputOther) ' other output files were found.']);
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
%------------------------------------------------------------------
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]);
prevPath = pwd;
cd(fileparts(obj.ravenExe));
dos(['"' obj.ravenExe '"' ' "' obj.ravenProjectFile '"'],'-echo');
disp('Done.');
cd(prevPath);
% 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
%------------------------------------------------------------------
function keepImpulseResponseFiles(obj, keepFiles)
% keepImpulseResponseFiles
%
% By default, RAVEN Impulse Responses are deleted from the hard disk
% after simulation and are only available in your rpf project
%
% By setting keepOutFiles to 1 / true, results are kept in
% the Output-Folder (obj.pathResults)
obj.keepOutputFiles = keepFiles;
obj.rpf_ini.SetValues('Global', 'keepOutputFiles', keepFiles);
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
end
%------------------------------------------------------------------
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
%------------------------------------------------------------------
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} = itaAc3dModel(obj.modelFileList{iRoom});
end
roommodel = obj.model{roomID + 1};
else
obj.model = itaAc3dModel(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 [outputFilePath] = setModelToShoebox(obj, length,width,height)
% setModelToShoebox
% creates a shoebox room model and automatically sets the model
% of the current project to the defined shoebox room.
% The shoebox room has 6 materials assigned (matShoebox1 ..
% matShoebox6), which can be set using
% rpf.setMaterial(matShoebox1,abs,scat)
%
% surface order:
% (1) floor, (2) ceiling,
% (3) larger wall (length x height; left, view from origin)
% (4) smaller wall (width x height; front)
% (5) larger wall (length x height; right)
% (6) smaller wall (width x height; back)
%
% Using:
% outputFileName = rpf.setModelToShoebox(myLength,myWidth,myHeight);
%
% see ita_raven_demo_shoebox for more details on usage
%
% Input:
% length, width, height (all in meters)
%
% Output:
% outputFilePath: full path of save ac3d model
%
outputFileName = ['Shoebox_' num2str(length) 'x' num2str(width) 'x' num2str(height) '.ac' ];
if strfind(obj.modelFileList,'RavenModels')
outputFilePath = [ obj.modelFileList(1:strfind(obj.modelFileList,'RavenModels')+10) '\' outputFileName ];
else
% if model wasn't stored in RavenModels folder, save it in
% the folder of the current rpf file.
outputFilePath = [ fileparts(obj.ravenProjectFile) '\' outputFileName ];
end
fid = fopen(outputFilePath,'w');
fprintf(fid,'AC3Db\n');
for iMat=1:6
fprintf(fid,['MATERIAL "matShoebox' num2str(iMat) '" rgb ' num2str(0.0) ' ' num2str(0.0) ' ' num2str(0.1*iMat) ' amb 0.2 0.2 0.2 emis 0 0 0 spec 0.2 0.2 0.2 shi 128 trans 0 \n']);
end
fprintf(fid,'OBJECT world\n');
fprintf(fid,'kids 6\n');
lS=sprintf('%1.4f',length);
wS=sprintf('%1.4f',-width);
hS=sprintf('%1.4f',height);
for iWall=1:6
fprintf(fid,'OBJECT poly\n');
fprintf(fid,'name "polygon_object"\n');
fprintf(fid,'numvert 4\n');
if iWall==1
fprintf(fid,'0 0 0\n');
fprintf(fid,[lS ' 0 0\n']);
fprintf(fid,[lS ' 0 ' wS '\n']);
fprintf(fid,['0 0 ' wS '\n']);
end
if iWall==2
fprintf(fid,[lS ' ' hS ' 0\n']);
fprintf(fid,['0 ' hS ' 0\n']);
fprintf(fid,['0 ' hS ' ' wS '\n']);
fprintf(fid,[lS ' ' hS ' ' wS '\n']);
end
if iWall==3
fprintf(fid,[lS ' 0 0\n']);
fprintf(fid,'0 0 0\n');
fprintf(fid,['0 ' hS ' 0\n']);
fprintf(fid,[lS ' ' hS ' 0\n']);
end
if iWall==4
fprintf(fid,'0 0 0\n');
fprintf(fid,['0 0 ' wS '\n']);
fprintf(fid,['0 ' hS ' ' wS '\n']);
fprintf(fid,['0 ' hS ' 0\n']);
end
if iWall==5
fprintf(fid,['0 0 ' wS '\n']);
fprintf(fid,[lS ' 0 ' wS '\n']);
fprintf(fid,[lS ' ' hS ' ' wS '\n']);
fprintf(fid,['0 ' hS ' ' wS '\n']);
end
if iWall==6
fprintf(fid,[lS ' 0 ' wS '\n']);
fprintf(fid,[lS ' 0 0\n']);
fprintf(fid,[lS ' ' hS ' 0\n']);
fprintf(fid,[lS ' ' hS ' ' wS '\n']);
end
fprintf(fid,'numsurf 1\n');
fprintf(fid,'SURF 0x10\n');
fprintf(fid,['mat ' num2str(iWall-1) '\n']);
fprintf(fid,'refs 4\n');
fprintf(fid,'3 0 0\n');
fprintf(fid,'2 0 0\n');
fprintf(fid,'1 0 0\n');
fprintf(fid,'0 0 0\n');
fprintf(fid,'kids 0\n');
end
fclose(fid);
obj.setModel(outputFilePath);
end
%------------------------------------------------------------------
function [outputFilePath] = setModelToFaces(obj,points,faces,materials)
% setModelToFaces
% creates a room model using points and faces and automatically
% sets the model of the current project to the so defined room.
% The room has one material assigned to each face (mat1 ..
% mat6), which can be set using
% rpf.setMaterial(mat1,abs,scat)
%
% Using:
% outputFileName = rpf.setModelToFaces(points,faces,materials);
%
% see ita_raven_demo_faces_room for more details on usage
%
% Input:
% points (matrix Nx3 in meters, columns represnt x, y, and z)
% faces (cell array, faces are defined pointing to the rows
% of matrix points) the first element points the material
% materials (cell array) This array does not necesarlly match
% the number of surfaces
% Output:
% FilePath: full path of save ac3d model
%
nW=length(faces);
outputFileName = ['room_' num2str(nW) '_faces'];
if strfind(obj.modelFileList,'RavenModels')
outputFilePath = [ obj.modelFileList(1:strfind(obj.modelFileList,'RavenModels')+10) '\' outputFileName ];
else
% if model wasn't stored in RavenModels folder, save it in
% the folder of the current rpf file.
outputFilePath = [ fileparts(obj.ravenProjectFile) '\' outputFileName ];
end
fn = floor(size(points,2)/4); % first element of a three elements point
if size(points,2)>3
idx = (points(:,1));
else
idx=1:size(points,1);
end
fid = fopen(outputFilePath,'w');
fprintf(fid,'AC3Db\n');
for iW=1:nW
fprintf(fid,['MATERIAL "' materials{faces{iW}(1)} '" rgb ' num2str(0.0) ' ' num2str(0.0) ' ' num2str(0.9/nW*iW) ' amb 0.2 0.2 0.2 emis 0 0 0 spec 0.2 0.2 0.2 shi 128 trans 0 \n']);
end
fprintf(fid,'OBJECT world\n');
fprintf(fid,['kids ' num2str(nW) '\n']);
for iW=1:nW
nP=length(faces{iW})-1;
fprintf(fid,'OBJECT poly\n');
fprintf(fid,'name "polygon_object"\n');
fprintf(fid,['numvert ' num2str(nP) '\n']);
for iP=1:nP
fprintf(fid,[sprintf('%1.4f %1.4f %1.4f',points(faces{iW}(iP+1)==idx,fn+(1:3))) '\n']);
end
fprintf(fid,'numsurf 1\n');
fprintf(fid,'SURF 0x10\n');
fprintf(fid,['mat ' num2str(iW-1) '\n']);
fprintf(fid,'refs 4\n');
fprintf(fid,'3 0 0\n');
fprintf(fid,'2 0 0\n');
fprintf(fid,'1 0 0\n');
fprintf(fid,'0 0 0\n');
fprintf(fid,'kids 0\n');
end
fclose(fid);
obj.setModel(outputFilePath);
end
%------------------------------------------------------------------
function figureHandle=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 = [1 -3 2];
end
if nargin < 2
if (ishandle(obj.plotModelHandle))
tgtAxes = obj.plotModelHandle;
else
figure;
tgtAxes = gca;
end
end
obj.plotModelHandle = tgtAxes;
if isempty(obj.model)
if iscell(obj.modelFileList)
for iRoom = 1 : numel(obj.modelFileList)
obj.model{iRoom} = itaAc3dModel(obj.modelFileList{iRoom});
obj.model{iRoom}.plotModel(tgtAxes, comp2axesMapping, wireframe);
hold on;
end
else
obj.model = itaAc3dModel(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
% get and transform source and receiver data
invertAxes = sign(comp2axesMapping);
comp2axesMapping = abs(comp2axesMapping);
spos = obj.getSourcePosition;
spos = spos(:, comp2axesMapping).*repmat(invertAxes,size(spos,1),1);
sview = obj.getSourceViewVectors;
sview = sview(:, comp2axesMapping).*repmat(invertAxes,size(sview,1),1);
sup = obj.getSourceUpVectors;
sup = sup(:, comp2axesMapping).*repmat(invertAxes,size(sup,1),1);
snames = obj.getSourceNames;
rpos = obj.getReceiverPosition;
rpos = rpos(:, comp2axesMapping).*repmat(invertAxes,size(rpos,1),1);
rview = obj.getReceiverViewVectors;
rview = rview(:, comp2axesMapping).*repmat(invertAxes,size(rview,1),1);
rup = obj.getReceiverUpVectors;
rup = rup(:, comp2axesMapping).*repmat(invertAxes,size(rup,1),1);
rnames = obj.getReceiverNames;
% plot source and receivers
plot3(spos(:,1),spos(:,2),spos(:,3),'marker','o','markersize',9,'linestyle','none','linewidth',1.5)
% hold on; view(0,90);
plot3(rpos(:,1),rpos(:,2),rpos(:,3),'marker','x','markersize',9,'linestyle','none','linewidth',1.5)
% plot view vectors (red) of sources
quiver3(spos(:,1),spos(:,2),spos(:,3),sview(:,1),sview(:,2),sview(:,3),0,'color','r','maxheadsize',1.5,'linewidth',1.5);
% plot view/up vectors (red) of receivers
quiver3(rpos(:,1),rpos(:,2),rpos(:,3),rview(:,1),rview(:,2),rview(:,3),0,'color','r','maxheadsize',1.5,'linewidth',1.5);
% plot up vectors (green) of sources and receivers )
quiver3(spos(:,1),spos(:,2),spos(:,3),0.5*sup(:,1),0.5*sup(:,2),0.5*sup(:,3),0,'color','g','maxheadsize',1.5,'linewidth',1.5);
quiver3(rpos(:,1),rpos(:,2),rpos(:,3),0.5*rup(:,1),0.5*rup(:,2),0.5*rup(:,3),0,'color','g','maxheadsize',1.5,'linewidth',1.5);
% plot names
text(spos(:,1)-0.2,spos(:,2),spos(:,3),snames,'FontName','Times','FontSize',20,'HorizontalAlignment','right')
text(rpos(:,1)+0.2,rpos(:,2),rpos(:,3),rnames,'FontName','Times','FontSize',20)
figureHandle=gca;
end
%------------------------------------------------------------------
function tgtAxes = plotModelRoom(obj, tgtAxes, comp2axesMapping, wireframe)
% identical to plotModel, without sound sources and receivers
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 = [1 -3 2];
end
if nargin < 2
if (ishandle(obj.plotModelHandle))
tgtAxes = obj.plotModelHandle;
else
figure;
tgtAxes = gca;
end
end
obj.plotModelHandle = tgtAxes;
if isempty(obj.model)
if iscell(obj.modelFileList)
for iRoom = 1 : numel(obj.modelFileList)
obj.model{iRoom} = itaAc3dModel(obj.modelFileList{iRoom});
obj.model{iRoom}.plotModel(tgtAxes, comp2axesMapping, wireframe);
hold on;
end
else
obj.model = itaAc3dModel(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
end
%------------------------------------------------------------------
function plotMaterialsAbsorption(obj, exportPlot, fileType, outputPath)
if nargin < 2
exportPlot = false;
end
if nargin < 3
fileType='png';
end
if nargin < 4
outputPath= obj.pathResults;
end
% strip final slash or backslash
if ( strcmp(outputPath(end),'\') || strcmp(outputPath(end),'/') )
outputPath = outputPath(1:end-1);
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 iMat=1:numberMaterials
[absorp scatter ] = obj.getMaterial(allMaterials{iMat});
currentMaterial.freqData = [ currentMaterial.freqData absorp' ];
currentSurfaceArea = obj.getSurfaceAreaOfMaterial(allMaterials{iMat});
allMaterials{iMat} = strrep(allMaterials{iMat},'_',' ');
allMaterials{iMat} = [ allMaterials{iMat} ' (S = ' num2str(currentSurfaceArea,'%5.2f') ' m² ;'];
allMaterials{iMat} = [ allMaterials{iMat} ' A (Eyring, f=1000 Hz) = ' num2str(-currentSurfaceArea*log(1-currentMaterial.freqData(18,iMat)),'%5.2f') ' m² )'];
end
currentMaterial.channelNames = allMaterials;
currentMaterial.allowDBPlot = false;
currentPlot = ita_plot_freq(currentMaterial,'LineWidth',2);
myAxes = gca;
for iMat=1:numberMaterials
myAxes.Children(iMat+2).Marker = 's';
end
% change format of plot
title('');
ylabel('Absorption coefficient');
xlabel('Frequency in Hz');
set(myAxes,'XLim',[20 20000]);
set(myAxes,'YLim',[0 1.05]);
leg = findobj(gcf,'Tag','legend');
set(leg,'Location','NorthWest');
set(leg,'FontSize',12);
% remove [1] in legend entry
for iMat=1:numberMaterials
leg.String{iMat} = leg.String{iMat}(1:end-4);
end
% export plot to raven output
if (exportPlot)
[pathstr,name,ext] = fileparts(obj.ravenProjectFile);
dateTimeStr = datestr(now,30);
dateTimeStr = strrep(dateTimeStr,'T','_');
fileNamePNG = [ outputPath '\Absorption_' name '_' dateTimeStr '.png'];
fileNamePDF = [ outputPath '\Absorption_' name '_' dateTimeStr '.pdf'];
set(gcf,'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'PaperUnits','inches','PaperPosition',1.34*[0 0 8 5]);
if strcmpi(fileType,'pdf')
set(gcf,'PaperUnits','centimeters','PaperSize',[25.7, 16.5]);
print('-dpdf','-r200', fileNamePDF);
close(currentPlot);
else
if ~strcmpi(fileType,'png')
warning('plotMaterialsAbsorption: Specified fileType not supported. Using PNG.');
end
print('-dpng','-r200', fileNamePNG);
end
end
end
%------------------------------------------------------------------
function averageRoomScattering = plotMaterialsScattering(obj, exportPlot, fileType, outputPath)
if nargin < 2
exportPlot = false;
end
if nargin < 3
fileType='png';
end
if nargin < 4
outputPath= obj.pathResults;
end
% strip final slash or backslash
if ( strcmp(outputPath(end),'\') || strcmp(outputPath(end),'/') )
outputPath = outputPath(1:end-1);
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 = [];
averageRoomScattering = zeros(1,31);
for i=1:numberMaterials
[absorp scatter ] = obj.getMaterial(allMaterials{i});
currentMaterial.freqData = [ currentMaterial.freqData scatter' ];
currentSurfaceArea = obj.getSurfaceAreaOfMaterial(allMaterials{i});
allMaterials{i} = strrep(allMaterials{i},'_',' ');
allMaterials{i} = [ allMaterials{i} ' (S = ' num2str(currentSurfaceArea,'%5.2f') ' m² )'];
averageRoomScattering = averageRoomScattering + (scatter)*currentSurfaceArea;
end
averageRoomScattering = averageRoomScattering / obj.getRoomSurfaceArea;
currentMaterial.channelNames = allMaterials;
currentMaterial.allowDBPlot = false;
currentPlot=ita_plot_freq(currentMaterial,'LineWidth',2);
myAxes = gca;
for iMat=1:numberMaterials
myAxes.Children(iMat+2).Marker = 's';
end
% change format of plot
title('');
ylabel('Scattering coefficient');
xlabel('Frequency in Hz');
set(myAxes,'XLim',[20 20000]);
set(myAxes,'YLim',[0 1.05]);
leg = findobj(gcf,'Tag','legend');
set(leg,'Location','NorthWest');
set(leg,'FontSize',12);
% remove [1] in legend entry
for iMat=1:numberMaterials
leg.String{iMat} = leg.String{iMat}(1:end-4);
end
% export plot to raven output
if (exportPlot)
[pathstr,name,ext] = fileparts(obj.ravenProjectFile);
dateTimeStr = datestr(now,30);
dateTimeStr = strrep(dateTimeStr,'T','_');
fileNamePNG = [ outputPath '\Scattering_' name '_' dateTimeStr '.png'];
fileNamePDF = [ outputPath '\Scattering_' name '_' dateTimeStr '.pdf'];
set(gcf,'units','normalized','outerposition',[0 0 1 1]);
set(gcf,'PaperUnits','inches','PaperPosition',1.34*[0 0 8 5]);
if strcmpi(fileType,'pdf')
set(gcf,'PaperUnits','centimeters','PaperSize',[25.7, 16.5]);
print('-dpdf','-r200', fileNamePDF);
close(currentPlot);
else
if ~strcmpi(fileType,'png')
warning('plotMaterialsScattering: Specified fileType not supported. Using PNG.');
end
print('-dpng','-r200', fileNamePNG);
end
end
end
% [Global] %
%------------------------------------------------------------------
function setProjectName(obj, projectName)
obj.projectName = projectName;
obj.rpf_ini.SetValues('Global', 'ProjectName', projectName);
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
end
function setPathMaterials(obj, pathMaterials)
obj.pathMaterials = pathMaterials;
obj.rpf_ini.SetValues('Global', 'ProjectPath_MaterialDB', pathMaterials);
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
%------------------------------------------------------------------
function airAbsEnabled = getAirAbsorptionEnabled(obj)
airAbsEnabled = ~obj.rpf_ini.GetValues('Rooms', 'noAirAbsorption', 0);
end
% [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 rückgängig 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 rückgängig 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 rückgängig 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;
if ~isempty(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 rückgängig gemacht
end
end
obj.rpf_ini.SetValues('PrimarySources', 'sourceDirectivity', obj.sourceDirectivityString);
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
end
%------------------------------------------------------------------
function setSourceDirectivityPath(obj, myPath)
%
% setSourceDirectivityPath(path)
%
% Set the RAVEN source directivity database path. Here all
% directivities (.daff files) should be located
%
% To generate new files, check out opendaff in the
% \applications\VirtualAcoustics\openDAFF\
%
% RAVEN currently only supports OpenDAFFv1.5 files
%
obj.pathDirectivities = myPath;
obj.rpf_ini.SetValues('Global', 'ProjectPath_DirectivityDB', myPath);
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 rückgängig 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)
% setISOrder_PS
% sets image source order
% -1 = disabled
% 0 = direct sound only
% N = for N>1 : image source calculation up to order N
% Do not set above 4, especially for complex models
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 setFixReflectionPattern(obj, fixit)
obj.fixReflectionPattern = fixit;
obj.rpf_ini.SetValues('RayTracing', 'fixReflectionPattern', fixit);
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
end
%------------------------------------------------------------------
function setScatterModel(obj, diffuseOrHit)
%setFilterResolution(obj, diffuseOrHit)
% 0 = Diffuse Rain (or 'diffuse'), 1 = Hit Oriented (or 'hit')
if ~isnumeric(diffuseOrHit)
diffuseOrHit = double(strcmp(diffuseOrHit, 'hit'));
end
%obj.scatterModel = diffuseOrHit;
obj.rpf_ini.SetValues('RayTracing', 'scatterModel_DetectionSphere', diffuseOrHit);
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
end
%------------------------------------------------------------------
function setScatterModel_Portal(obj, diffuseOrHit)
%setFilterResolution(obj, diffuseOrHit)
% 0 = Diffuse Rain (or 'diffuse'), 1 = Hit Oriented (or 'hit')
if ~isnumeric(diffuseOrHit)
diffuseOrHit = double(strcmp(diffuseOrHit, 'hit'));
end
%obj.scatterModel_Portal = diffuseOrHit;
obj.rpf_ini.SetValues('RayTracing', 'scatterModel_Portal', diffuseOrHit);
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
end
%------------------------------------------------------------------
function setEnergyLoss(obj, energyloss)
% setEnergyLoss
% Define maximum energy loss for ray tracing (in dB)
% typical value 60 dB
% (for room acoustic parameter evaluation)
% Increase to ~70-80 dB if high quality auralizations are desired
% significantly increases simulation time (ray tracing)
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
%------------------------------------------------------------------
function setTimeSlotLength(obj, slotlength)
% setTimeSlotLength
% set timeslot lengt in ms
% (histogram resolution, for raytracing algorithm)
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
%------------------------------------------------------------------
function setDetectionSphereResolutionAzimuth(obj, resAzi)
% setDetectionSphereResolutionAzimuth
% set detection sphere azimuth resolution in degree
% default value = 10
% samples sphere into grid, creating "directivity groups"
% see Phd thesis by Dirk Schröder for details
obj.detectionSphereAziResolution = resAzi;
obj.rpf_ini.SetValues('RayTracing', 'resolutionAzimuth_DetectionSphere', resAzi);
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
end
%------------------------------------------------------------------
function setDetectionSphereResolutionElevation(obj, resEle)
% setDetectionSphereResolutionElevation
% set detection sphere elevation resolution in degree
% default value = 10
% samples sphere into grid, creating "directivity groups"
% see Phd thesis by Dirk Schröder for details
obj.detectionSphereEleResolution = resEle;
obj.rpf_ini.SetValues('RayTracing', 'resolutionElevation_DetectionSphere', resEle);
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
end
%------------------------------------------------------------------
function setFilterLength(obj, filter_length)
% set filter length 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 = itaAc3dModel(obj.modelFileList{roomID + 1});
else
roommodel = obj.model{roomID + 1};
end
else
if isempty(obj.model)
roommodel = itaAc3dModel(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
% [Filter] %
%------------------------------------------------------------------
function setSamplingFrequency(obj, samplingRate)
obj.sampleRate = samplingRate;
obj.rpf_ini.SetValues('Filter', 'samplingFrequency', samplingRate);
obj.rpf_ini.WriteFile(obj.ravenProjectFile);
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 setMaximumReflectionDensity(obj, maxReflectionDensity)
% setMaximumReflectionDensity
% sets the maxium reflection density for filter synthesis. Default
% value is 20000. Typical values between 10000 and 20000
% for details see Diss Dirk Schröder or Aspöck @ DAGA 2013 / DAGA 2017
obj.maxReflectionDensity = maxReflectionDensity;
obj.rpf_ini.SetValues('Filter', 'maximumReflectionDensity', maxReflectionDensity);
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 setOutputPath(obj, path)
%
% setOutputPath(path)
%
% Set the RAVEN output path. If you keep the output files
% (cf. keepOutputFiles variable / method keepOutputFiles),
% Impulse Responses as wave files are stored here :
% //