Resample and convert into PCM
显示 更早的评论
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.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 PCM 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!