改变音高录制的音频和频率 [英] Changing Pitch and Frequency of Recorded Audio
问题描述
我一直在试图用code从以下调整记录一段音频的音调:
http://developer.android.com/guide/topics/媒体/音频capture.html
我的猜测是,这一调整应与完成的 MediaRecorder
。
http://developer.android.com/reference/android/media/ MediaRecorder.html
不过,我不能确定打电话来改变音调哪种方法?
翻翻所以,我发现<一href="http://stackoverflow.com/questions/3737636/changing-the-frequency-of-a-soundfile-in-android">changing在Android的一个音效档的频率,但我很困惑,如何整合的Soundpool
与我下面的音频捕获导向的元素。有基于开发指南我使用的是更简单的解决方案?
mAudioManager =(AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mSoundPool =新的Soundpool(大小,AudioManager.STREAM_MUSIC,0);
mSoundPoolMap =新的HashMap&LT;整数,整数GT;();
mSoundPoolMap.put(索引,mSoundPool.load(上下文,R.raw.sound,1));
mSoundPool.play(ID,streamVolume,streamVolume,1,循环,1F);
的频率是第1f一部分。如果您将其更改为.5f和2.0f之间的值,应该减速或加速样本,从而改变音高。
下面是从我的应用程序之一约code:
私人的Soundpool的Soundpool;
私人的HashMap&LT;整数,整数GT; soundsMap;
保护无效的onCreate(包savedInstanceState){
的Soundpool =新的Soundpool(4,AudioManager.STREAM_MUSIC,100);
soundsMap =新的HashMap&LT;整数,整数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:
http://developer.android.com/guide/topics/media/audio-capture.html
My guess is that this adjustment should be done with the MediaRecorder
.
http://developer.android.com/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.
这篇关于改变音高录制的音频和频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!