%% Reduce Latency due to Output Device Buffer
% Latency due to the output device buffer is the time delay of writing one frame of data. Modify default properties of your audioDeviceWriter System object™ to reduce latency due to device buffer size.
% Create a dsp.AudioFileReader System object to read an audio file with default settings.

fileReader = dsp.AudioFileReader('speech_dft.mp3');

%
% Create an audioDeviceWriter System object and specify the sample rate to match that of the audio file reader.

deviceWriter = audioDeviceWriter(...
    'SampleRate',fileReader.SampleRate);

%
% Calculate the latency due to your device buffer, in seconds.

bufferLatency = fileReader.SamplesPerFrame/deviceWriter.SampleRate %#ok

%
% Set the SamplesPerFrame property of your dsp.AudioFileReader System object to 256. Calculate the buffer latency in seconds.

fileReader.SamplesPerFrame = 256;
bufferLatency = fileReader.SamplesPerFrame/deviceWriter.SampleRate

% Copyright 2012 The MathWorks, Inc.