I have a library which records real time audio and computes real time FFT data for the audio. The client must call a start method to start the recording, and a stop method to end the recording.
My design question is concerning the best way to get this data back to the client. I have considered the following approaches:
- Have a method called
getData(int size)
that the client will call periodically after they have started the recording. It will return up to size audio samples, or as much data as is available. My thought for this is that the client would run anAsyncTask
to periodically call for more data. The problems with this approach is it is much less efficient, and is more complicated for the client, but it does allow for them to have more control over when and how much data they receive. - Have the client pass in an output stream to my start method to which I would just send the data as soon as I have it. This is simpler but is more restrictive.
- Similarly, instead of an output stream, have the client pass in some sort of structure like an
ArrayList
, that would just be shared between us and that I would push data onto. - Lastly, I have thought about having my start method return an output stream (or
ArrayList
similarly) that the client would just read from.
From the client's point of view, which would you prefer and why? Or are there some other alternatives that I am completely overlooking? Any input would be appreciated, thanks!