在android中播放特定频率的声音
我想根据用户输入在android中播放特定频率的声音,有点类似于吉他应用程序。谁能告诉我该怎么做?我需要将所有频率声音放在 res\raw 文件夹中吗?
I want to play a sound of a particular frequency in android based on user input, somewhat similar to guitar application. Can anyone tell me how to do that? Do i need to have all freq sounds in the res\raw folder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,您不需要将其存储在资源中。我认为更好的方法是实时合成音调。为此,您需要以下内容:
No, you do not need to store that in the resources. I think better approach would be to synthesize the tones in a real time. For that purpose you would need the following:
将声音发送到 AudioTrack 实例并动态更改其采样率。
Send the sound to an AudioTrack instance and change its sample rate on the fly.
这是一个极其复杂的问题,尽管看起来并非如此。
当您说“声音”时,您只是指音调(例如正弦波、方波、三角波、锯齿波)还是您希望演奏“真实”乐器(例如吉他、钢琴等)的声音?
如果是第一个(简单的音调),那么 Desiderio 的答案可能是正确的,但如果你想要“真实”的乐器声音,那么你需要在 /res/raw 或 /assets 目录中有一个简短的“样本” 。
您可以将它们加载到 SoundPool 实例中,并使用它以不同的“速率”播放,例如,2 的“速率”将是速度的两倍和频率的两倍,从而增加一个八度。 0.5 的“速率”将是速度的一半,因此将声音降低一个八度。
This is an extremely complex question even though it doesn't seem like it.
When you say 'sound' do you simply mean a tone (sine, square, triangle, sawtooth waves for example) or do you wish to play sounds of 'real' instruments such as guitar, piano and so on?
If it's the first one (simple tones) then Desiderio's answer may be on the right track but if you want 'real' insrument sounds then you will need to have a short 'sample' in either /res/raw or in your /assets directory.
You can load them into a SoundPool instance and use it to playback at different 'rates', e.g., a 'rate' of 2 will be twice the speed and double the frequency thus increasing by an octave. A 'rate' of 0.5 will be half the speed so lowering the sound by an octave.