www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ProcessAudioDataUsingSystemObjectsExample.m
%% Process Audio Data Using System Objects % This example shows how to write System objects code for reading audio data. % % The code uses System objects from the DSP System Toolbox(TM) software % to read audio data from a file, filter it, and then play the filtered % audio data. This code produces the same result as the MATLAB(R) code shown % previously, allowing you to compare approaches. %% % Locate source audio file. fname = 'speech_dft_8kHz.wav'; %% % Define the System object to read the file. audioIn = dsp.AudioFileReader(fname,'OutputDataType','single'); %% % Define the System object to filter the data. filtLP = dsp.FIRFilter('Numerator',fir1(160,.15)); %% % Define the System object to play the filtered audio data. audioOut = audioDeviceWriter('SampleRate',audioIn.SampleRate); %% % Define the while loop to process the audio data. while ~isDone(audioIn) audio = audioIn(); % Read audio source file y = filtLP(audio); % Filter the data audioOut(y); % Play the filtered data end %% % This System objects code avoids the issues present in the MATLAB-only % code. Without requiring explicit indexing, the file reader object manages % the data frame sizes while the filter manages the states. The audio % device writer object plays each audio frame as it is processed.