【问题标题】:Changing Pitch and Frequency of Recorded Audio改变录制音频的音高和频率
【发布时间】:2013-09-30 08:06:57
【问题描述】:

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

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 与我正在关注的音频捕获指南中的元素集成感到困惑。有没有基于我正在使用的开发者指南的更直接的解决方案?

【问题讨论】:

  • 当您说“调整音高”时,您是指以不同的速度播放样本(这会影响播放的持续时间),还是您希望保持相同的持续时间并且只改变音高(音高变化)?
  • @Michael 目前我希望保持相同的持续时间,只更改音频文件的音高/声音。如果您对此有任何想法,请告诉我..提前致谢

标签: java android audio audio-processing


【解决方案1】:
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 的值来改变速率。

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

【讨论】:

    猜你喜欢
    • 2021-10-26
    • 1970-01-01
    • 2015-08-15
    • 1970-01-01
    • 2011-06-10
    • 2013-07-30
    • 1970-01-01
    相关资源
    最近更新 更多