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

编程入门 行业动态 更新时间:2024-10-28 20:26:03
本文介绍了改变音高录制的音频和频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在试图用code从以下调整记录一段音频的音调:

developer.android/guide/topics/媒体/音频capture.html

我的猜测是,这一调整应与完成的 MediaRecorder 。

developer.android/reference/android/media/ MediaRecorder.html

不过,我不能确定打电话来改变音调哪种方法?

翻翻所以,我发现changing在Android的一个音效档的频率,但我很困惑,如何整合的Soundpool 与我下面的音频捕获导向的元素。有基于开发指南我使用的是更简单的解决方案?

解决方案

mAudioManager =(AudioManager)context.getSystemService(Context.AUDIO_SERVICE); mSoundPool =新的Soundpool(大小,AudioManager.STREAM_MUSIC,0); mSoundPoolMap =新的HashMap<整数,整数GT;(); mSoundPoolMap.put(索引,mSoundPool.load(上下文,R.raw.sound,1)); mSoundPool.play(ID,streamVolume,streamVolume,1,循环,1F);

的频率是第1f一部分。如果您将其更改为.5f和2.0f之间的值,应该减速或加速样本,从而改变音高。

下面是从我的应用程序之一约code:

私人的Soundpool的Soundpool;     私人的HashMap<整数,整数GT; soundsMap;     保护无效的onCreate(包savedInstanceState){ 的Soundpool =新的Soundpool(4,AudioManager.STREAM_MUSIC,1​​00);         soundsMap =新的HashMap<整数,整数GT;();         soundsMap.put(cowbell1,soundpool.load(此,R.raw.cowbell,1));         soundsMap.put(cowbell2,soundpool.load(此,R.raw.cowbell1,1));         soundsMap.put(cowbell3,soundpool.load(此,R.raw.windhh3,1)); }     公共无效playSound(INT声音,浮动fSpeed​​){     AudioManager经理=(AudioManager)getSystemService(Context.AUDIO_SERVICE);     浮streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);     浮streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);     浮动量= streamVolumeCurrent / streamVolumeMax;     soundpool.play(soundsMap.get(音),音量,音量,1,0,fSpeed​​);    }

要叫我用这样的声音:

playSound(cowbell1,1.0F); 要么                 playSound(cowbell2,1.0F);

的速率可以通过改变1.0F值被改变。

如果您仍然有后您的code麻烦,我会看看吧。

I've been trying to adjust the pitch of a record piece of audio following with code from:

developer.android/guide/topics/media/audio-capture.html

My guess is that this adjustment should be done with the MediaRecorder.

developer.android/reference/android/media/MediaRecorder.html

However, I am unsure which method to call to change the pitch?

Looking through SO, I found changing the frequency of a soundfile in android but I am confused as to how to integrate a SoundPool with the elements in the audio capture guide I am following. Is there a more straightforward solution based on the developer guide I am using?

解决方案

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);

The frequency is the 1f part. If you change it to a value between .5f and 2.0f that should slow down or speed up the sample, which changes the pitch.

Here's some code from one of my apps:

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); }

To call a sound I use this:

playSound(cowbell1, 1.0f); or playSound(cowbell2, 1.0f);

The rate can be changed by altering the 1.0f value.

If you're still having trouble post your code and I'll have a look at it.

更多推荐

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

本文发布于:2023-07-11 11:51:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093950.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:音高   频率   音频

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!