%% Apply Split-Band De-Essing
% De-essing is the process of diminishing sibilant sounds in an audio signal. Sibilance refers to the s, z, and sh sounds in speech, which can be disproportionately emphasized during recording. es sounds fall under the category of unvoiced speech with all consonants and have a higher frequency than voiced speech. In this example, you apply split-band de-essing to a speech signal by separating the signal into high and low frequencies, applying an expander to diminish the sibilant frequencies, and then remixing the channels.
% Create a dsp.AudioFileReader object and an audioDeviceWriter object to read from a sound file and write to an audio device. Listen to the unprocessed signal. Then release the file reader and device writer.

fileReader = dsp.AudioFileReader( ...
    'Sibilance.wav');
deviceWriter = audioDeviceWriter;

while ~isDone(fileReader)
    audioIn = fileReader();
    deviceWriter(audioIn);
end

release(deviceWriter)
release(fileReader)

%
% Create an expander System object to de-ess the audio signal. Set the sample rate of the expander to the sample rate of the audio file. Create a two-band crossover filter with a crossover of 3000 Hz. Sibilance is usually found in this range. Set the crossover slope to 12. Plot the frequency response of the crossover filter to confirm your design visually.

dRExpander = expander( ...
    'Threshold',-50, ...
    'AttackTime', 0.05, ...
    'ReleaseTime',0.05, ...
    'HoldTime',0.005, ...
    'SampleRate',fileReader.SampleRate);

crossFilt = crossoverFilter( ...
    'NumCrossovers',1, ...
    'CrossoverFrequencies',3000, ...
    'CrossoverSlopes',12);
visualize(crossFilt)

%
%
% Create a dsp.TimeScope System object to visualize the original and processed audio signals.

scope = dsp.TimeScope( ...
    'SampleRate',fileReader.SampleRate, ...
    'TimeSpanOverrunAction','Scroll', ...
    'TimeSpan',4, ...
    'BufferLength',fileReader.SampleRate*8, ...
    'YLimits',[-1,1], ...
    'ShowGrid',true, ...
    'ShowLegend',true, ...
    'ChannelNames',{'Original','Processed'});

%
% In an audio stream loop:
% Read in a frame of the audio file.
% Split the audio signal into two bands.
% Apply dynamic range expansion to the upper band.
% Remix the channels.
% Write the processed audio signal to your audio device for listening.
% Visualize the processed and unprocessed signals on a time scope.
% As a best practice, release your objects once done.

while ~isDone(fileReader)
    audioIn = fileReader();
    
    [band1,band2] = crossFilt(audioIn);
    
    band2processed = dRExpander(band2);
    
    procAudio  = band1 + band2processed;
    
    deviceWriter(procAudio);
    
    scope([audioIn procAudio]);
end

release(deviceWriter)
release(fileReader)
release(scope)
release(crossFilt)
release(dRExpander)

% Copyright 2012 The MathWorks, Inc.