To convert audio and image file into C array we need two tools
- Audacity
- bin2c
Audacity
you can download this tool from here–>
Is Audacity is free?
Yes! It is a free tool to record audio and can playback the recorded audio, it has features to edit audio, noise cancellation
Audacity record computer audio?
Yes! It records laptop or computer audio with the help of built-in microphone which we have in our laptop
Record audio in Audacity and convert audio file to raw file
- open Audacity tool
- press the red button to start recording audio
- after recording the audio stop the recording
- click on file option–> Export Audio
- your file name.raw –>save as: other uncompressed files –>Header: Raw(header-less) –> Encoding: unsigned 8-bit Pcm–>Save–>ok
- view the recorded audio in the document folder –> Audacity
bin2c
bin2c is a tool which will convert the raw audio file and image file into C Array
you can download this tool from here–>
how to use bin2c
- download bin2c and extract zip files
- copy and paste bin2c application on Desktop
- win+r and type CMD to open the command terminal
- type the command cd Desktop
- then type command bin2c
- copy and paste the raw file of Audacity on Desktop
- then type the command bin2c -o sample.h sample.raw
- C array file will be formed on the Desktop
convert image to C array
the process to convert image is same as audio just need to change the file name
type the command bin2c -o sample.h sample.jpg
Example of c array generated by bin2c
const long int imx_raw_size = 14048;
const unsigned char imx_raw[14048] = {
0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x80, 0x80, 0x80, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x80, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x80,
0x80, 0x80, 0x80, 0x80, 0x7F, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x80, 0x7F, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x80, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x80,
0x7F, 0x7F, 0x7F, 0x7F, 0x80, 0x80,
};
how to convert 16 bit audio format wav file?