簡體   English   中英

更改錄制音頻的音高和頻率

[英]Changing Pitch and Frequency of Recorded Audio

我一直在嘗試通過以下代碼調整音頻片段的音調:

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

我的猜測是應該使用MediaRecorder進行此調整。

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

但是,我不確定調用哪種方法來改變音高?

通過SO,我發現在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部分。 如果將其更改為.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值來更改速率。

如果您仍然無法發布代碼,我會看一下。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM