MATLAB Examples

Contents

function AcquireSoundCardDSPMatlabExample

Acquire Acoustic Data from a Sound Card with the DSP System Toolbox Example

This example shows how to acquire and view acoustic data from a sound card using the DSP System Toolbox.

initialize

AR = dsp.AudioRecorder;
AFW = dsp.AudioFileWriter('myspeech.wav','FileFormat', 'WAV');
AP = dsp.AudioPlayer('SampleRate',AR.SampleRate);
fprintf('Speak into microphone now\n');
etic;
audioSave = [];
Speak into microphone now

step

while etoc < 10,
  [audioIn] = step(AR); % acquire one frame of audio
  audioSave = [audioSave; audioIn]; %#ok<AGROW> save audio
  step(AFW,audioIn); % write frame to audio file
end

visualize

if coder.target('matlab') % if running in MATLAB, plot and play audio with sound
    plot(audioSave);
    sound(audioSave,AR.SampleRate); % if generating code, play audio with dsp.AudioPlayer
else
    step(AP,audioSave);
end

cleanup

release(AR);
release(AFW);
fprintf('Recording complete\n');
Recording complete