我一直在尝试使用以下代码调整音频记录的音高:
http://developer.android.com/guide/topics/media/audio-capture.html
我的猜测是,这种调整应该使用 MediaRecorder
来完成。
http://developer.android.com/reference/android/media/MediaRecorder.html
但是,我不确定调用哪个方法来更改音调?
浏览SO,我发现changing the frequency of a soundfile in android但我对如何将 SoundPool 与我正在遵循的音频捕获指南中的元素集成感到困惑。根据我正在使用的开发人员指南,是否有更直接的解决方案?
最佳答案
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mSoundPool = new SoundPool(size, AudioManager.STREAM_MUSIC, 0);
mSoundPoolMap = new HashMap<Integer, Integer>();
mSoundPoolMap.put(index, mSoundPool.load(context, R.raw.sound, 1));
mSoundPool.play(id, streamVolume, streamVolume, 1, loop, 1f);
频率是1f部分。如果将其更改为 0.5f 到 2.0f 之间的值,则会减慢或加快采样速度,从而改变音调。
这是我的一个应用程序中的一些代码:
private SoundPool soundpool;
private HashMap<Integer, Integer> soundsMap;
protected void onCreate(Bundle savedInstanceState) {
soundpool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundsMap = new HashMap<Integer, Integer>();
soundsMap.put(cowbell1, soundpool.load(this, R.raw.cowbell, 1));
soundsMap.put(cowbell2, soundpool.load(this, R.raw.cowbell1, 1));
soundsMap.put(cowbell3, soundpool.load(this, R.raw.windhh3, 1));
}
public void playSound(int sound, float fSpeed) {
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
soundpool.play(soundsMap.get(sound), volume, volume, 1, 0, fSpeed);
}
要调用声音,我使用这个:
playSound(cowbell1, 1.0f);
or
playSound(cowbell2, 1.0f);
可以通过更改 1.0f 值来更改速率。
如果您仍然遇到问题,请发布代码,我会查看它。
关于java - 更改录制音频的音高和频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18992943/