title: MATLAB audiorecorder and wavwrite
body: <p>While reading the <a href="http://mathworks.com" rel="nofollow">website of MathWorks</a> I learned that they are discouraging the usage of <code>wavrecord</code> function, because it's going to be deprecated soon, so I decided to use the <code>audiorecorder</code> instead. Everything was fine, even the play function was also playing the recorded audio, but when I use <a href="http://www.mathworks.de/help/techdoc/ref/wavwrite.html" rel="nofollow"><code>wavwrite</code></a> function to write to a wav file it's not sounding well, basically I noticed that the duration is not set properly. </p>
  
  <p>I am showing the program, please suggest me how to make it correct. Thank you.</p>
  
  <pre><code>fs = 44100
  bits = 16
  recObj = audiorecorder(fs, bits, 1);
  %# get(recObj)
  
  %# Collect a sample of your speech with a microphone, and plot the signal data:
  %# Record your voice for 5 seconds.
  recObj = audiorecorder;
  disp('Start speaking.')
  recordblocking(recObj, 5);
  disp('End of Recording.');
  
  %# Play back the recording.
  play(recObj);
  
  %# Store data in double-precision array.
  myRecording = getaudiodata(recObj);
  %disp(size(myRecording));
  
  %# Plot the waveform.
  plot(myRecording);
  
  wavwrite(myRecording, fs, bits,'sample01_6k');
  %#wavplay(myRecording,fs);
  </code></pre>