I'm doing pdm to pcm conversion and want output file to be generated in .pcm format currently using .bin file.

20 vues (au cours des 30 derniers jours)
currently im using fwrite to write data in output file with int32 and little endian format in .bin file as .pcm is not available
" fwrite( output_file ,inp_ptr ,'int32' , 'l' ); " for matlab
output:
-----> C and matlab output files are not matching
while my C file command is " fwrite(inp_ptr, sizeof(Word32), 8, output_file); " output file saved as .pcm .
output:
how to get same output as C ?

Réponses (1)

Paras Gupta
Paras Gupta le 17 Déc 2023
Hi Uma,
I understand that the output in MATLAB and C do not match when you try to write data in an output file.
The reason you might be seeing different outputs between the two could be due to several factors:
  1. Endianess: If the MATLAB code explicitly specifies little-endian format but the C code is running on a big-endian system, the bytes will be written in a different order.
  2. Data Type: Make sure that 'Word32' in C is indeed a 32-bit integer ('int32_t' or equivalent). If it's not, the size of the data being written will be different.
  3. File Mode: If the file is not opened in binary mode in C ("wb"), it could cause differences in how the data is written, especially on systems like Windows where text mode and binary mode treat certain characters differently (e.g., newline translation).
  4. Initial File State: If the file pointed to by 'output_file' is not in the same initial state before each write operation (e.g., if it contains different data or is at different positions within the file), the resulting output will differ.
  5. Data in Memory: Ensure that 'inp_ptr' is pointing to the same data with the same values in both the C and MATLAB environments before the write operations.
Moreover, the file extension itself (.bin or .pcm) does not affect the actual content of the file. The difference is purely in the naming convention, which might be used by software to infer the intended use of the file.
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by