Obviously, with a 30kbyte/sec max flash file system write speed, I need to make sure the bit rate is well below that.
That translates to a 240kbps audio stream, which is very very high quality - the very top end of "hifi" unless you are into $1000 interconnects and 100x oversampled 24 bit DACs
So that in itself should be ok.
One challenge I see is that the ADC sampling, which has to be
synchronous for any audio encoding, would need to be inside an ISR, or driven from a timer -> ADC -> DMA so a periodically running RTOS thread can process a whole load of ADC samples in one go. I haven't looked yet at how that ST lib does it (it is 240MB).
The end file has to be mp3, for general compatibility, even if the required quality is relatively crap.
My flash file system sector writes are currently blocking (for complicated reasons which I posted about, to do with the file system being accessed by USB (MSC) while the internal software is messing in there, but I can make the write non-blocking, so the sector write is about 20us and the next 15ms is the internal flash write cycle. A sector read, not relevant to this project, is just 200us (DMA transfer of 512 bytes via 21MHz SPI).
As for closing the file at power-down, I can build this with plenty of capacitance on the PSU. Action cams seem to have no trouble closing off a video file when the battery goes flat, and that's a lot more complicated (some big blocks have to be written at the end, AIUI).
If I drive the ADC from timer+DMA, at say 22kHz, that will generate 44kB of data per second, so a leisurely RTOS thread, getting around to this every 100ms or less, will need just 4.4kB of RAM, which is trivial. So no need for any ISR at all. Just set up a timer to drive the ADC and use DMA. I have already built a waveform generator that way. Use a circular RAM buffer so it never needs to stop, and reset the DMA pointer whenever the data has been extracted.
I get the feeling that the hardest bit will be structuring the code so it all streams nicely.