Part 2 Basic Audio Mat Lab
Part 2 Basic Audio Mat Lab
Play the music at different levels. If we change the sample rate during playback, it will affect the time
duration as well as the perceived pitch. In the following example, we shall increase the sample rates
gradually, so you will hear a shorter sound with high-pitch, similiar to the sound of the Disney cartoon
character Donald Fauntleroy Duck.
3. On the other hand, if we lower the sample rate gradually, we shall get longer and lowpitched sounds.
wavplay(y,
wavplay(y,
speed
wavplay(y,
wavplay(y,
1.0*fs, 'sync');
0.9*fs, 'sync');
0.8*fs, 'sync');
0.6*fs, 'sync');
fs=16000;
% Sampling rate
duration=2;
% Recording duration
fprintf('Press any key to start %g seconds of recording...', duration); pause
fprintf('Recording...');
y=wavrecord(duration*fs, fs); % duration*fs is the total number of sample points
fprintf('Finished recording.\n');
fprintf('Press any key to play the recording...'); pause;
fprintf('\n');
wavplay(y,fs);
5. Record from microphone and store as a file
fs=11025;
% Sampling rate
duration=2;
% Recording duration
waveFile='test.wav';
% Wav file to be saved
fprintf('Press any key to start %g seconds of recording...', duration);
pause
fprintf('Recording...');
y=wavrecord(duration*fs, fs);
fprintf('Finished recording.\n');
fprintf('Press any key to save the sound data to %s...', waveFile);
pause
nbits=8;