更改录制音频的音高和频率

更改录制音频的音高和频率,第1张

更改录制音频的音高频率

mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mSoundPool = new SoundPool(size, AudioManager.STREAM_MUSIC, 0);
mSoundPoolMap = new HashMap();
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值来更改速率。

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



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5430269.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存