How can I get into a wav file to change the sample rate?

user1123936 picture user1123936 · Jun 24, 2012 · Viewed 10.3k times · Source

I have a wav file pulled up in MATLAB, and I can see it's sample rate. All I need to do is change this 1 number. Everything else in the file will remain uncahnged. (The resulting sound would play at a different speed but would have an identical array of sample data.)

The reason I need to do this is because MATLAB seems to freak out when I tell it to open something sampled at anything other than 8k. All I need MATLAB for is to edit the file, so the sample rate really doesn't matter at all, since I'll be putting it back into a wav file when I'm done. So I either need to be able to change the value in the wav file that stores the sample rate, or to get MATLAB to change the sample rate it prefers from 8k to the sample rate that my files were recorded at.

Answer

user1398405 picture user1398405 · Jun 24, 2012

if you just want to change the sampling frequency, here is the code, but it would distort the original wav file. If you decrease the sampling frequency, then the beat and music would be very slow.

Code:
    [y, fs, nbits]=wavread('stego_lab');
    fs2=11025;
    wavwrite(y,fs2,nbits,'stego2_lab.wav');
    sound(y,fs2,nbits)

you can hear it but the samples will remain the same. Hope it helps.