필터 지우기
필터 지우기

Resample and convert into PCM

조회 수: 23 (최근 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 CenterFile Exchange에서 PCM에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by