A strange problem about audio play using MATLAB (Maybe a bug in MATLAB!)

7 views (last 30 days)
I have record an audio segment from computer audio input port and save the audio segment with the .wav format. The sample rate is 44.1kHz and the length is 3'30". Then I downsampled the audio segment and make its sample rate 1000Hz using MATLAB, then saved the downsampled audio segment as .wav file using 'wavwrite' command in MATLAB. The downsampled audio file is 3'30" if played by Audition(an audio softwave),but if played by MATLAB command 'sound' or 'audioplayer',the time is just 3'!

Accepted Answer

Daniel Shub
Daniel Shub on 19 Jul 2011
The wav file format supports arbitrary sample rates. I think the sample rates must be positive integers less than 2^32, but 1000 Hz is a valid sample rate for a wav file. Audition reads the wav file header and therefore displays the correct duration. The reason your playback is wrong is that the soundcard does not support the sample rate. Most soundcards have a few native sample rates and then interpolate to get to the requested sample rate. In some cases, like yours, if the sample rate is too high or too low, the sound card chokes and behaves unpredictably (in your case dropping back to the default of 44.1kHz).
I would not recommend using any sample other than 44.1kHz. If you really want a different sample rate stick with something between 8192 Hz and 196 kHz.

More Answers (3)

Walter Roberson
Walter Roberson on 18 Jul 2011
See sound(): "If you do not specify a sample rate, sound plays at 8192 Hz."
And wavwrite() assumes 8000 Hz if you do not provide Fs.
My guess is that you are not saving the correct Fs with wavwrite() and that you are providing the assumed (but incorrect) Fs for sound().
  1 Comment
Susan
Susan on 18 Jul 2011
Thank you very much!
I have specified the Fs in wavwrite() command.
I use audioplayer() playing the audio segment, and in this command I still provide Fs. And both Fs are 1000Hz.

Sign in to comment.


Susan
Susan on 18 Jul 2011
In the question, I said that if the downsampled audio segment was played by the Audition software, the playing time was as long as the original file. But I tested just now and I found that the Auditon software displaying time was not right, the actual time is 3' too!

Susan
Susan on 18 Jul 2011
I have found the answer. Maybe the Fs of downsampled audio file is too low. If the Fs of downsampled audio file is 8000Hz, there is no problem.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!