Android的音频:改变音高 [英] Android audio : change pitch

查看:268
本文介绍了Android的音频:改变音高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的机器人文档的Soundpool说的应用程序也可以通过调整回放速率实时为多普勒或合成效果改变音调。于是,我就这样做,用setRate方法顺利变化从一个音符到另一个,但结果是可怕的:声音变化非常破烂。这里是code我试过了。请告诉我,如果有更好的办法。

  INT流ID = soundPool.play(soundId,1,1,1,0,1.0F);
为(浮X = 0 X  - 。1; X + = 0.005){
  SystemClock.sleep(10);
  soundPool.setRate(流ID,1 + x)的;
}
 

解决方案

虽然机器人文档建议,你可以使用 setRate()来产生多普勒效应,我想不依靠快或足够好的实现每一个Android设备上。

负担得起的音频IC需要44kHz的或48kHz的固定采样率。因此采样率转换(即间距变更)必须在软件来完成。正因为如此,包括低级别的数字运算,我相信,这是由设备制造商,而不是由谷歌来实现。由于各种各样的Andr​​oid设备制造商和使用的往往低成本的硬件,当然,还有很多采样率转换的实现在那里。有的快,有的慢。有的光滑,有的粗糙的。

改变播放过程中转化率时,会发生什么?如果算法确实件$ P $不符pcisely在一起,有可能是一个短裂的音频播放。您更改转换率每10毫秒。如果有一个裂缝每隔10ms,对应到100Hz的频率为一个音本身。这很可能是你听到的是什么衣衫褴褛。

总之,我不认为这是可能的模拟实时乐器上广泛使用高级的Andr​​oid API的Andr​​oid设备。本机应用程序可能是速度不够快,但。

The Android documentation for SoundPool says "the application can also alter the pitch by adjusting the playback rate in real-time for doppler or synthesis effects". So I tried to do this, using the setRate method to vary smoothly from one note to another, but the result is awful: the sound variation is very ragged. Here is the code I tried. Please tell me if there is a better way.

int streamId = soundPool.play (soundId, 1, 1, 1, 0, 1.0f);
for (float x = 0; x < 1; x += 0.005) {
  SystemClock.sleep (10);
  soundPool.setRate (streamId, 1 + x);
}

解决方案

Even though the Androids documentation suggests that you can use setRate() to produce doppler effects, I would not rely on a fast or good enough implementation on every android device.

Affordable audio ICs require a fixed sample rate of 44kHz or 48kHz. Sample rate conversion (i.e. pitch modification) therefore has to be done in software. Because this includes low-level number crunching I am sure that this is implemented by the device manufacturer and not by Google. Given the wide variety of Android device manufacturers and the often low-cost hardware used, there are certainly many sample rate conversion implementations out there. Some faster, some slower. Some smooth, some ragged.

What happens when changing the conversion rate during playback? If the algorithm doesn't match the pieces precisely together, there might be a short crack in your audio playback. You change the conversion rate every 10 milliseconds. If there is a crack every 10ms, that corresponds to a frequency of 100Hz which is a tone itself. This is likely to be what you hear as "ragged".

All in all I don't think that it is possible to emulate musical instruments in real-time on a wide range of Android devices using high-level Android API. A native application might be fast enough though.

这篇关于Android的音频:改变音高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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