Question

I want to process audio offline on iOS, but have a query regarding memory usage. If I use AVAssetReader to decompress an MP3 to raw PCM data, the memory footprint would be huge. So how would I go about processing (offline FFT) an mp3 file if decompression would lead to the app using too much memory? I assume I have to stream it somehow, but I don't know how to do this in iOS.

Was it helpful?

Solution

AVAssetReader can write to a file using AVAssetWriter.

To get PCM, you can write a WAV file format, and then skip the RIFF header(s) on read. Then you only need to pull in as much data from the WAV file into memory at any one time as your FFT length requires. This should only cause a memory footprint problem if each FFT is well over 1 million samples long.

You can use C/unix posix calls (fgetc, etc.) to read a file stream under iOS. Or read from an NSInputStream into NSData.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top