音频/ FFT库设计 [英] Audio/FFT Library Design
问题描述
我有记录的实时音频和计算实时FFT数据为音频库。客户端必须调用start方法来启动录音,停止的方法来结束录制。
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:
- 有一个名为
的getData(INT大小)方法
客户端将定期召集他们已经开始录制了。它会返回到尺寸音频样本,或尽可能多的数据是可用的。我对这种想法是,客户端将运行一个的AsyncTask
来定期调用更多的数据。这种方法的问题是它是非常低效率的,并且是用于在客户端更复杂,但它确实允许他们有当它们接收多少数据更多的控制。 - 您也可以在输出流客户端传递到我的start方法,而我只想尽快,因为我有它发送数据。这是简单的,但更多的限制。
- 同样的,而不是一个输出流,在某种像一个结构
的ArrayList
的客户端传递,这也只是我们之间,我将推动数据共享到。 - 最后,我曾经想过有我的起步方法返回一个输出流(或
的ArrayList
类似),客户端将只读取。
- 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.
从客户端查看的角度来看,这将您preFER,为什么?还是有,我完全可以俯瞰一些其他的选择吗?任何投入将是AP preciated,谢谢!
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定期调用检查数据的getData code>将客户端效率低下,更复杂,所以我不推荐这个。
1- Checking for data periodically by calling getData
will make the client inefficient and more complex, so I would not recommend this.
2 - 使用共享的MemoryStream
是一个可以研究的解决方案
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
这篇关于音频/ FFT库设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!