2

我一直在尝试使用以下代码调整录音片段的音高:

http://developer.android.com/guide/topics/media/audio-capture.html

我的猜测是这个调整应该用MediaRecorder.

http://developer.android.com/reference/android/media/MediaRecorder.html

但是,我不确定调用哪种方法来改变音高?

通过 SO,我发现改变了 android 中声音文件的频率,但我对如何将 aSoundPool与我正在关注的音频捕获指南中的元素集成感到困惑。是否有基于我正在使用的开发人员指南的更直接的解决方案?

4

1 回答 1

4
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 值来更改速率。

如果您仍然无法发布您的代码,我会看看它。

于 2013-09-24T22:15:30.893 回答