ita_din18041_reverberation_times.m 3.41 KB
Newer Older
1 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 33 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 61 62 63 64 65 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
function varargout = ita_din18041_reverberation_times(varargin)
%ITA_DIN18041_REVERBERATION_TIMES - calculates recommended reverbertion times for different room types, according to DIN18041
%
%  Call: itaAudio = ita_din18041_reverberation_times('V',room_volume,'purpose', room_purpose, 'add_to', itaAudio)
%
%       Options (default):
%           V ([]) - room volume
%           'purpose' ('speech') - what is the room used for? Known: 'speech' 'music' 'education'
%           'add_to' [] - if you supply an itaAudio, the reverberation times will be added as channels
%
%   See also ita_roomacoustics, ita_roomacoustics_reverberation_time
%
%   Reference page in Help browser 
%        <a href="matlab:doc ita_din18041_reverberation_times">doc ita_din18041_reverberation_times</a>

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


% Author: Roman Scharrer -- Email: rsc@akustik.rwth-aachen.de
% Created:  16-Feb-2009 


%% Initialization and Input Parsing
sArgs        = struct('v',[],'purpose','speech','add_to', 'itaAudioFrequency');
narginchk(1,6);
sArgs = ita_parse_arguments(sArgs,varargin);
type = lower(sArgs.purpose);

if isempty(sArgs.v)
   error( ' I really need the volume of the room!'); 
elseif sArgs.v > 5000
    ita_verbose_info('ITA_DIN18041: Careful, norm only valid for small to medium size rooms!',1);
elseif sArgs.v > 30000
    ita_verbose_info('ITA_DIN18041: Carefull, norm only valid for small to medium size rooms! Room volume far out of range',0);
end


if isempty(sArgs.add_to) || strcmpi(sArgs.add_to, 'itaAudioFrequency')
    fs = 44100;
    f = linspace(0,fs/2,2^10+1);
else
    fs = sArgs.add_to.samplingRate;
    f = sArgs.add_to.freqVector;
end

%% +++Body - Your Code here+++ 'result' is an audioObj and is given back
switch type
    case {'musik','music'}
        a = 0.45;
        b = 0.07;
    case {'sprache','speech'}
        a = 0.37;
        b = -0.14;
    case {'unterricht','education'}
        a = 0.32;
        b = -0.17;
    otherwise
        error('room type unknown');
end

t_soll = a*log10(sArgs.v)+b; %General reverberation time

t_60 = zeros(2,length(f));

% frequency dependent reverberation time
if strcmp(type,'musik') || strcmp(type,'music')
    t_60(1,f<=250) = (-log10(f(f<=250))+log10(250))*0.7+0.8;
    t_60(1,f>250) = 0.8;
    t_60(1,f>=2000) = (-log10(f(f>=2000))+log10(2000))*0.5+0.8;
    t_60(2,:) = t_60(1,:) *1.2/0.8;
    t_60(2,f>=2000) = 1.2;    
else %Sprache, Unterricht
    t_60(1,f<=250) = (log10(f(f<=250))-log10(250))*0.5+0.8;
    t_60(1,f>250) = 0.8;
    t_60(1,f>=2000) = (-log10(f(f>=2000))+log10(2000))*0.5+0.8;
    t_60(2,:) = 1.2;
end

t_60 = t_60 .* t_soll;

t_60(t_60<0.000001)=0.000001;

result = itaAudio();
result.spk = t_60;
result.samplingRate = fs;
result.channelNames = {'Minimum recommended reverberation time' 'Maximum recommended reverberation time'};
result.channelUnits = {'s' 's'};
result.comment = 'Recommended reverberation times according to DIN18041';
result.signalType = 'energy';

%% Add history line
result = ita_metainfo_add_historyline(result,'ita_din18041_reverberation_times',varargin);

%% Check header
%result = ita_metainfo_check(result);

%% Find output parameters
if ~(isempty(sArgs.add_to)  || strcmpi(sArgs.add_to, 'itaAudioFrequency'))
    result = ita_merge(sArgs.add_to,result);
end
varargout(1) = {result};
%end function
end