播放声音每隔N毫秒 [英] Play a sound every N milliseconds

查看:227
本文介绍了播放声音每隔N毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个节拍器应用程序。用户可以在运行时BPM的选择,而我的应用程序将扮演嘀声相应。 嘀是一个节拍器枪毙(MP3)。我尝试使用处理器和MediaPlayer的实现它,但是节拍器不是precise的。 于是我想到了改变整个方法:当用户选择一个新的BPM值,我合成一个新的声音重复蜱声音X次每隔N毫秒,然后循环在这个创建运行时的声音。 这是一个有效的替代方案?怎么能在Android中实施?

I'm developing a metronome application. The user can select at runtime the bpm, and my app will play the "tick" sound accordingly. The "tick" is a single metronome "shot" (mp3). I tried implementing it using Handler and MediaPlayer, but the metronome is not precise at all. So I thought about changing the whole approach: when the user choose a new bpm value, I synthesize a new sound by repeating the tick sound X times every N milliseconds, then looping over this runtime created sound. Is this a valid alternative? How can it be implemented in Android?

推荐答案

通过合成声音循环的替代似乎是最好的选择了。有一个的伟大的会话有关的音频在谷歌I / O 2013所谓的高性能音频的,我一定会建议看具有对系统如何工作的,有什么问题的开发商将面临在与音频延迟处理有更深的了解。在有关视频的17:00,有图形显示抖动与回调。在不存在完美的世界(真的吗?),抖动是零所做的全部计划的音频回调。但事实并非如此,因为有信号不稳定高达35毫秒或甚至更高,为图中的数据是用非特定ICS装置,由也肯定有比这更糟糕的情况。

The alternative of looping through a synthesized sound seems to be the best choice for now. There was a great session about audio on Google I/O 2013 called High Performance Audio that I would certainly advice watching for having a deeper understanding on how the system works and what problems the developers will face when dealing with the audio latency. At about the 17:00 of the video, there is graph that shows jitter versus callbacks. In the perfect world that does not exist (oh really?), the jitter would be zero for all the scheduled audio callbacks made. But that is not the case, for there are jitters as high as 35 milliseconds or even greater, for the data in the graph was made using an unspecified ICS device and there are certainly worse scenarios than that.

所以,作为一个节拍器是precision工具,而这些紧张不擅长所有的定时播放方式应该是搁置在一边。使用 AudioTrack 我甚至做了合理realiable节拍器工作,合成声音。

So, as a metronome is a precision tool and these jitters are not good at all, the scheduled playback approach should be left aside. I even made an reasonably realiable metronome work with a synthesized sound using AudioTrack.

希望它可以帮助^^

这篇关于播放声音每隔N毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆