How can I convert *.pcm
audio file to *.wav
audio File in MATLAB-Code?
I just need to insert a header, but how it is work?
Thank you very much!
Asked
Active
Viewed 1,403 times
1

Fracture
- 105
- 3
- 14
-
one way is to use ffmpeg from within matlab. [Can ffmpeg convert audio from raw PCM to WAV?](https://stackoverflow.com/questions/11986279/can-ffmpeg-convert-audio-from-raw-pcm-to-wav) – user10502344 Oct 14 '18 at 10:51
-
Thanks, and this ffmpeg is a external script? – Fracture Oct 15 '18 at 14:01
-
Can you try AUDIOREAD to read in the file and AUDIOWRITE to write out WAV files? – Dinesh Iyer Oct 16 '18 at 04:19
-
`Error using audioread (line 88) File could not be read due to an unexpected error. Reason: Unable to pop the top most message from the bus Error in readdata3 (line 49) [y,Fs] = audioread('15_10_2018_110044.pcm');` – Fracture Oct 18 '18 at 07:02
-
I don't find a function to read pcm-File in MATLAB - to use "audioread" is not possible - **The file type is not supported** to use `fid = fopen ('15_10_2018_110044.pcm','r');` is possible, but i dont know, how can I exploring this File! Can you help me please? – Fracture Oct 18 '18 at 07:33
-
Maybe, another issue - i,m saving a *.PCM with QTCreator AudioRecorder. Maybe, I can chose another recording codec, to able to use Audioread with MATLAB!? – Fracture Oct 18 '18 at 07:41
1 Answers
1
Since you didn't specify it, I'm assuming you are using Matlab 2018b, so I will point you to the most recent documentation about audioread:
As you can see, PCM is not on the supported format list.
You should try to look if you can parameter your AudioRecorder to record your audio to another format within the ones in the supported list: .wav, .ogg, .flac, .au, .aif, .aifc, mp3, .mp4...
An alternative option, without using audioread
, would be to import pcm data like any other data file, then convert it to 16 bit wav. I assume sample rate is 44100 Hz.
fid = fopen('audioFile.pcm'); % Open raw pcm file
audio = int16(fread(fid, Inf, 'int16')); % Convert data into 16 bit
fclose(fid); % Close pcm file
audiowrite('audioFile.wav', audio, 44100,'BitsPerSample', 16); % Write wav

alpereira7
- 1,522
- 3
- 17
- 30
-
Hei Bebs, thank you, I have read a MATLAB documentation. The Problem is to create one of this format with QT Creator - for example FLAC. Do you have example code for it, just change 'setCodec' from PCM to FLAC don't works – Fracture Oct 25 '18 at 07:57
-
@Fracture, that would be another question, not related with Matlab, but with QT Creator. I would recommend you to close this question, and write a new one with appropriate title and tags: it will increase the chances of having an answer. – alpereira7 Oct 25 '18 at 08:01