Audio/FFT Library Design

梦想的初衷 提交于 2019-12-25 07:14:33

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/15165813/audio-fft-library-design

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!