Domanda

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:

  1. 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 an AsyncTask 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.
  2. 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.
  3. 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.
  4. 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!

È stato utile?

Soluzione

1- Checking for data periodically by calling getData will make the client inefficient and more complex, so I would not recommend this.

2- Using a shared MemoryStream is a solution that can be investigated

Another alternative, and probably simpler, solution is to simply pass a callback object to your library that is called whenever a new data is available i.e. event-driven communication

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top