m5stack / M5Atom

M5Stack Atom Arduino Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to convert a mp3 for use with rawPCM example?

kd8bxp opened this issue · comments

I've googled and can't find how to convert a mp3/wav to a C array - so an example or tutorial of what is needed to convert an mp3 for use with the rawPCM example for the Atom SPK would be very nice to have.

Thanks

Same here!

Found this post from another project: baldram/ESP_VS1053_Library#18
But it gave the information needed.

xxd -i yoursoundfile.wav yoursoundfile.c
which worked for me, with the following conditions:

I used Audacity to convert a mp3 to a wav, and change the bit rate, in the example it's 44100, which creates a rather large array. And from what I can tell the array needs to be pretty small to fit in memory.
in AtomSPK.h there are two lines rated to bit rates (both are in the class ATOMSPK), that need to be changed, and it seems to work well with a lower rate.

The only other thing that I did was at the bottom of the "c" file that xxd creates is the size of the array, and I copied that number and used it when the array gets defined.

As pointed out from the other project xxd is part of VIM, and here is a post that talks about installing VIM for Windows
https://superuser.com/questions/497953/convert-hex-dump-of-file-to-binary-program-file-on-windows#638850

I'm a linux mint 20.2 user and xxd appears to have already been installed, I can only guess other Ubuntu based distros would be the same.