%% Real-Time Audio in MATLAB®

frameLength = 1024;

fileReader = dsp.AudioFileReader( ...
    'Counting-16-44p1-mono-15secs.wav', ...
    'SamplesPerFrame',frameLength);
deviceWriter = audioDeviceWriter( ...
    'SampleRate',fileReader.SampleRate);

scope = dsp.TimeScope( ...
    'SampleRate',fileReader.SampleRate, ...
    'TimeSpan',2, ...
    'BufferLength',fileReader.SampleRate*2*2, ...
    'YLimits',[-1,1], ...
    'TimeSpanOverrunAction',"Scroll");

reverb = reverberator( ...
    'SampleRate',fileReader.SampleRate, ...
    'PreDelay',0.5, ...
    'WetDryMix',0.4);

while ~isDone(fileReader)
    signal = fileReader();
    reverbSignal = reverb(signal);
    deviceWriter(reverbSignal);
    scope([signal,mean(reverbSignal,2)])
end

release(fileReader)
release(deviceWriter)
release(reverb)
release(scope)

% Copyright 2016 The MathWorks, Inc.