I have PCM raw audio file and I would like to read it in matlab and play it back. I searched the matlab documentation for some in-built functions but couldn't find any. Also the inbuilt matlab functions like audioread and sound are not compatible with .pcm audio files. So could somebody give some suggestions on how to proceed? Thank you!
Asked
Active
Viewed 4,761 times
1 Answers
1
Matlab doesn't have a build in function to import .pcm.
A .pcm
file, sometimes specified as "raw" usually does not have any information included so it is basically just audio samples in a binary file. Hence you will likely not have these following details:
- Sample rate (sampling frequency)
- Encoding info (e.g. 16bit, 32bit, signed, unsigned...)
You'll need to have this by other means. Once you get that info. You can do:
%% Values not included in the file, needed to be known
%% I took 44100 and 'int16' as example
fs = 44100
precision = 'int16'
%%
fid = fopen('audioFile.pcm'); % Open raw pcm file
audio = int16(fread(fid, Inf, precision)); % Convert data to 16 bit
fclose(fid);
You will have your data stored in audio
.
You can now play it with the build in function audioplayer:
audioplayer(audio, fs);

alpereira7
- 1,522
- 3
- 17
- 30