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

%   Copyright 2015-2016 The MathWorks, Inc.

%#codegen

persistent flanger
if isempty(flanger)
    flanger = audioexample.Flanger;
    flanger.SampleRate = Fs;
end

if tuningUIStruct.ValuesChanged
    param = tuningUIStruct.TuningValues;
    % Tune parameters if needed
    flanger.Delay = param(1);
    flanger.Depth = param(2);
    flanger.Rate = param(3);
    flanger.FeedbackLevel = param(4);
    flanger.WetDryMix = param(5);
end

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

% Generate output
audioOut = flanger(audioIn);