栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

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



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/454743.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号