%% Read and Play an Audio File
% Note:  If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x).
% Note: The dsp.AudioFileReader and audioDeviceWriter System objects are not supported in MATLAB Online.
% Read in an AVI audio file, and play the file back using the standard audio output device.

AFR = dsp.AudioFileReader; % points to a default audio file
AP = audioDeviceWriter('SampleRate',AFR.SampleRate);
while ~isDone(AFR)
  audio = AFR();
  nUnderrun = AP(audio);
  if nUnderrun > 0
    fprintf('Audio player queue underrun by %d samples.\n'...
	     ,nUnderrun);
  end
end
release(AFR);            % close the input file
release(AP);             % close the audio output device