フィルターのクリア

Resample and convert into PCM

34 ビュー (過去 30 日間)
João
João 2019 年 2 月 7 日
回答済み: João 2019 年 2 月 8 日
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.

採用された回答

João
João 2019 年 2 月 8 日
I get it:
% convert to PCM 16 bit
precision = 'int16';
fidr = fopen([a_filename(1:11), '_22050','.wav'], 'r'); % open .wav file to read
fidw = fopen([a_filename(1:11), '_22050','.pcm'], 'wb'); % open .pcm file to write
w = int16(fread(fidr, inf, precision));% read .wav file
fwrite(fidw, w, precision); % write .pcm file
fclose(fidr);
fclose(fidw);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePCM についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by