Resample and convert into PCM
Show older comments
Hello,
First of all I'm using rMATLAB2018.
I'm trying to resample an audio file with sampling rate 44100 Hz to 22050 Hz and then convert the last one into a PCM with 16 bits.
The resample was an easy step but I'm struggling to convert to PCM 16 bits...
This is my attempt:
[x, fs] = audioread(a_filename);
% resample:
fsin = fs;
fsout = 22050;
m = lcm(fsin,fsout);
up = m/fsin;
down = m/fsout;
x_22 = resample(x, up, down);
audiowrite([a_filename,'_22050','.wav'], x_22, fsout);
% convert to PCM 16 bit
fid = fopen([a_filename,'_22050','.wav'], 'r'); % Open wav file
wF = fread (fid, inf, 'int16');% 16-bit signed integer
fwrite(wF,'short');
fclose(fid);
I'm getting this error message:
Error using fwrite
Invalid file identifier. Use fopen to generate a valid file identifier.
What am I doing wrong here? Thank you.
Accepted Answer
More Answers (0)
Categories
Find more on PCM in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!