% "System A" Distortion/Convolution Function by Daniel Natoli 
% Designed for use with distCONV system. 

% This function calls the following .m files (supplied):
    % fft_conv.m
    % my_decay_function.m
    % expdist.m
    % symclip.m
    % tanhdist.m 

function convolved_sum = distconv_systemA(input, IR, fs, distortion_option, dist_value, decayfactor, mix_distortion_dry, mix_distortion_wet)

% This function applies a time-variant distortion to a convolved audio
% signal using FFT convolution. 

    % FFT Convolution 
    input_convolved = fft_conv(IR, input);

    % Apply distortion to the convolved signal
    switch distortion_option  
        case 1
        dist_convolved = tanhdist(input_convolved, dist_value);
        case 2 
        dist_convolved = symclip(input_convolved,dist_value); 
        case 3
        dist_convolved = expdist(input_convolved, dist_value);  
    end 

    % Create a decay curve & inverse decay curve 
    decay_curve = my_decay_function(length(dist_convolved), fs, decayfactor);
    flip_curve = flipud(decay_curve);

    % Apply the decay curve & inverse decay curves to the convolved files 
    decayed_convolved = input_convolved.*decay_curve; 
    distorted_convolved = dist_convolved.*flip_curve;

    % Mix distorted convolution and clean convolution files. 
    convolved_sum = (decayed_convolved*mix_distortion_dry) + (distorted_convolved*mix_distortion_wet);

end