function audioOut = HelperAudioReverberation(audioIn, tuningUIStruct, Fs)
%HELPERAUDIOREVERBERATION Use reverberator object on input audio
%
% This function HelperAudioReverberation is only in support of
% audioReverberationCompilerExample. It may change in a future release.

%   Copyright 2015-2016 The MathWorks, Inc.

%#codegen
persistent reverb
if isempty(reverb)
    reverb = reverberator;
    reverb.SampleRate = Fs;
end

if tuningUIStruct.ValuesChanged
    paramNew = tuningUIStruct.TuningValues;
    reverb.PreDelay = paramNew(1);
    reverb.HighCutFrequency = paramNew(2);
    reverb.Diffusion = paramNew(3);
    reverb.DecayFactor = paramNew(4);
    reverb.HighFrequencyDamping = paramNew(5);
    reverb.WetDryMix = paramNew(6);
end

if tuningUIStruct.Reset % reset System object
   reset(reverb);
end

% Generate output
audioOut = reverb(audioIn);