使用 Soundpool 非常快地播放声音
我正在创建一个应用程序,需要每大约 25 毫秒播放一次声音。 (每分钟 300 节拍,每节拍可能有 8 次“播放”)
首先,我使用 SoundPool 来完成此任务。我有 3 个线程。一种是更新 SurfaceView 动画,一种是使用 System.nanoTime() 更新时间,另一种是使用 Soundpool 播放声音 (mp3)。
这可行,但似乎使用了大量的处理器能力,因为每当后台进程运行(例如 WiFi 重新扫描或 GC)时,它就会开始到处跳动,这是不可接受的。
我正在寻找替代解决方案。我研究了混合以及 JET 发动机。
JET 引擎似乎不是一个解决方案,因为它只使用 MIDI。我的应用程序需要高质量的声音(来自实际乐器的录音)。 (如果我错误地认为 midi 质量不高,请纠正我)
使用 Android 混音似乎非常复杂,因为似乎首先您必须获得原始声音(占用大量内存)并在声音之间创建“静音”。我不确定这是否是最优雅的解决方案,因为我的应用程序将具有由用户控制的变速(bpm)。
如果有人在这方面有经验,我将非常感谢任何建议。
谢谢
I am creating an app that requires a sound or sounds to potentially be played every ~25ms. (300beats per minute with potentially 8 "plays" per beat)
At first I used SoundPool to accomplish this. I have 3 threads. One is updating the SurfaceView animation, one is updating the time using System.nanoTime(), and the other is playing the sounds (mp3s) using Soundpool.
This works, but seems to be using a lot of processor power as anytime a background process runs such as the WiFi rescanning, or GC, it starts skipping beats here and there, which is unacceptable.
I am looking for an alternative solution. I've looked at mixing and also the JET engine.
The JET engine doesn't seem like a solution as it only uses MIDIs. My app requires high-quality sounds (recordings from actual instruments). (correct me if I'm wrong on midi not being high quality)
Mixing seems very complicated with Android as it seems first you must get the raw sound (takes up a lot of memory) and also create "silence" in between sounds. I am not sure if this is the most elegant solution as my app will have variable speed (bpm) controlled by the user.
If anyone is experienced in this area, I would GREATLY appreciate any advice.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论