function audioOut =HelperApplyEcho(audioIn, tuningUIStruct, Fs)
%HELPERAPPLYECHO Use echo object on input audio
%
% This function HelperApplyEcho is only in support of
% audioDelayEffectsExampleApp. It may change in a future release.

%   Copyright 2015-2016 The MathWorks, Inc.

%#codegen
persistent echo
if isempty(echo)
    echo = audioexample.Echo;
    echo.SampleRate = Fs;
end

% Tune parameters 
if tuningUIStruct.ValuesChanged
    param = tuningUIStruct.TuningValues;
    echo.Delay = param(1);
    echo.Gain = param(2);
    echo.FeedbackLevel = param(3);
    echo.WetDryMix = param(4);
end
if tuningUIStruct.Reset % reset System object
   reset(echo);
end
    
% Generate output
audioOut = echo(audioIn);