Store a .wav file in a partice photon device

Hi!,
i’m sorry if this question is a basic issue, but, could anyone help me on how to store a .wav file (around 65KB) on a particle photon device and later stream it? … thanks!
best regards

You could add an SD card to the Photon.
There is a library for it on the Web IDE.

Hi ScruffR … since the expected file size is not excessive, could it be possible to store it on the on-board flash memory, or even try to store it in the RAM memory?. thanks again!!!

RAM is a precious good on these things :wink:
It depends on the RAM needs of your application, if there will be enough space to store it there, but you can easily try by declaring an array that size or allocating that size chunck on the heap.

Flash will be a bit tricky, but might be possible. You might need to look into the memory map of the Photon.

@fbt, the Photon has about 120KB of usable user “flash” and about 80KB of user RAM (YMMV). Storing a 65KB wav file in RAM requires it to be first stored in flash first or downloaded via TCP/UPD/Cloud each time you reset the Photon. It is easy to store in flash only by creating a const array which will be stored directly to the user flash. The P1 module has 1MB of external flash which can be used with the (fantastic) flashee eeprom library. You have options so chose wisely young padawan :wink:

As @ScruffR pointed out, microcontroller resources are nothing like an RPi or PC so careful management is necessary. Try things and when you get stuck, post your code and we’ll try and help!

1 Like

The simplest way is to use the tool xxd to convert the binary to a C array.

xxd -i my.wav

produces

unsigned char my_wav[] = { .... }
unsigned int my_wav_len = 12345;

You can then paste this into your application source code. EDIT: And add const to the declarations to they remain in flash.

The WAV will be stored in flash you can read from the array directly and so stream directly from flash.

I hope that helps. :smile:

2 Likes

@mdma, let’s not forget the const cast or the array will be copied to RAM! :wink:

2 Likes

Thank you all for your valuable help, as usual! best regards