function HelperAudioEffectsiOS(blk, sys, action)
% Helper function for audioeffectsiOS model

% Copyright 2016 The MathWorks, Inc.

    switch action
        case 'EffectChoice'
            EffectChoice = get_param(blk, 'EffectChoice');
            if strcmp(EffectChoice, 'Echo') == 1
                set_param(strcat(sys, '/Host Program and Playback/Manual Variant Source'), 'OverrideUsingVariant', 'V_1');
                set_param(strcat(sys, '/iOS Program and Playback/Manual Variant Source'), 'OverrideUsingVariant', 'V_1');
            elseif strcmp(EffectChoice, 'Reverberation') == 1
                set_param(strcat(sys, '/Host Program and Playback/Manual Variant Source'), 'OverrideUsingVariant', 'V_2');
                set_param(strcat(sys, '/iOS Program and Playback/Manual Variant Source'), 'OverrideUsingVariant', 'V_2');
            end
            
        case 'DeviceChoice'
            DeviceChoice = get_param(blk, 'DeviceChoice');
            maskObj = Simulink.Mask.get(blk);
            hostInputSelectorParam = maskObj.Parameters(3);
            iOSInputSelectorParam = maskObj.Parameters(4);

            if strcmp(DeviceChoice, 'Run on host') == 1
                set_param(strcat(blk, '/Manual Variant Sink'), 'OverrideUsingVariant', 'V_1');
                iOSInputSelectorParam.set('Visible', 'off');
                hostInputSelectorParam.set('Visible', 'on');
                HelperAudioEffectsiOS(blk, sys, 'InputChoice');
                set_param(sys, 'SimulationMode', 'normal');
                set_param(sys, 'HardwareBoard', 'None');
                set_param(sys, 'IsERTTarget','off');
                
            elseif strcmp(DeviceChoice, 'Run on Apple iOS device') == 1
                set_param(strcat(blk, '/Manual Variant Sink'), 'OverrideUsingVariant', 'V_2');
                hostInputSelectorParam.set('Visible', 'off');
                iOSInputSelectorParam.set('Visible', 'on');
                HelperAudioEffectsiOS(blk, sys, 'InputChoice');
                set_param(sys, 'SimulationMode', 'external');
                set_param(sys, 'HardwareBoard', 'Apple iOS Device');
                set_param(sys, 'IsERTTarget','on');
        
                % update sample rate and frame size for iOS blocks, since we disable iOS
                % block sample rate and frame size update when user doesn't have iOS
                % support package installed
                samplingFreq = get_param(blk, 'SamplingFreq');
                set_param(strcat(sys, '/Audio Capture'), 'sampleFreq_', samplingFreq);
                set_param(strcat(sys, '/iOS Program and Playback/Audio Playback'), 'sampleFreq_', samplingFreq);
                if strcmp(samplingFreq, '44100') == 1
                    set_param(strcat(sys, '/Audio Capture'), 'frameSize_', '2205');
                elseif strcmp(samplingFreq, '48000') == 1
                    set_param(strcat(sys, '/Audio Capture'), 'frameSize_', '2400');
                end
            end
            
        case 'InputChoice'
            if strcmp(get_param(blk, 'DeviceChoice'), 'Run on host') == 1
                if strcmp(get_param(blk, 'HostInputSelector'), 'Signal From Workspace') == 1
                    set_param(strcat(blk, '/Manual Variant Source'), 'OverrideUsingVariant', 'V_1');
                elseif strcmp(get_param(blk, 'HostInputSelector'), 'Host Microphone') == 1
                    set_param(strcat(blk, '/Manual Variant Source'), 'OverrideUsingVariant', 'V_2');
                end
            elseif strcmp(get_param(blk, 'DeviceChoice'), 'Run on Apple iOS device') == 1
                if strcmp(get_param(blk, 'iOSInputSelector'), 'Signal From Workspace') == 1
                    set_param(strcat(blk, '/Manual Variant Source'), 'OverrideUsingVariant', 'V_1');
                elseif strcmp(get_param(blk, 'iOSInputSelector'), 'iOS Device Microphone') == 1
                    set_param(strcat(blk, '/Manual Variant Source'), 'OverrideUsingVariant', 'V_3');
                end
            end

        case 'SetSampleRate'
            samplingFreq = get_param(blk, 'SamplingFreq');
            set_param(strcat(sys, '/Signal From Workspace'), 'Fs', samplingFreq);
            set_param(strcat(sys, '/Audio Device Reader'), 'SampleRate', samplingFreq);
            set_param(strcat(sys, '/Host Program and Playback/Echo'), 'SampleRate', samplingFreq);
            set_param(strcat(sys, '/Host Program and Playback/Audio Device Writer'), 'SampleRate', samplingFreq);
            
            
            if strcmp(samplingFreq, '44100') == 1
                set_param(strcat(sys, '/Signal From Workspace'), 'nsamps', '2205');
                set_param(strcat(sys, '/Audio Device Reader'), 'SamplesPerFrame', '2205');
            elseif strcmp(samplingFreq, '48000') == 1
                set_param(strcat(sys, '/Signal From Workspace'), 'nsamps', '2400');
                set_param(strcat(sys, '/Audio Device Reader'), 'SamplesPerFrame', '2400');
            end
            
            deviceChoice = get_param(blk, 'DeviceChoice');
            if strcmp(deviceChoice, 'Run on Apple iOS device') == 1
                set_param(strcat(sys, '/Audio Capture'), 'sampleFreq_', samplingFreq);
                set_param(strcat(sys, '/iOS Program and Playback/Audio Playback'), 'sampleFreq_', samplingFreq);
                if strcmp(samplingFreq, '44100') == 1
                    set_param(strcat(sys, '/Audio Capture'), 'frameSize_', '2205');
                elseif strcmp(samplingFreq, '48000') == 1
                    set_param(strcat(sys, '/Audio Capture'), 'frameSize_', '2400');
                end
            end
            
        case 'Bypass'
            bypass = get_param(blk, 'Bypass');
            if strcmp(bypass, 'on') == 1
                set_param(strcat(sys, '/Bypass'), 'Gain', '1');
            else
                set_param(strcat(sys, '/Bypass'), 'Gain', '0');
            end
    end
end