%% Resample and Play an Audio Signal
% 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.
% This example shows how to resample and play an audio signal from 48 kHz to 32 kHz on a Windows® platform.

afr = dsp.AudioFileReader('audio48kHz.wav', ...
    'OutputDataType', 'single', ...
    'SamplesPerFrame', 300);
adw = audioDeviceWriter(32000);

%
% Create an FIRRateConverter System object with interpolation factor = 2, decimation factor = 3. Default FIR filter coefficients define a lowpass filter with normalized cutoff frequency of 1/3.

firrc = dsp.FIRRateConverter(2,3);

while ~isDone(afr)
    audio1 = afr();
    audio2 = firrc(audio1);
    adw(audio2);
end

release(afr);
release(adw);