如何在录制音频的android调整麦克风灵敏度 - 已解决 [英] How to adjust microphone sensitivity while recording audio in android - Solved

查看:2725
本文介绍了如何在录制音频的android调整麦克风灵敏度 - 已解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在录音的应用程序。在app我有一个搜索栏更改输入声音的增益。 我寻觅了很多,但无法找到任何方式来调整输入声音的增益。

我使用AudioRecord类录制的声音。

 记录=新AudioRecord(MediaRecorder.AudioSource.MIC,
            RECORDER_SAMPLERATE,RECORDER_CHANNELS,
            RECORDER_AUDIO_ENCODING,缓冲区大小);

    recorder.startRecording();
 

我已经看到了一个应用程序也在其中使用此功能Play商店。

https://play.google.com/store/应用程序/详细信息?ID = com.grace.microphone

感谢

修改

我已经用做了

 最终诠释USHORT_MASK =(1<< 16) -  1;

最后ByteBuffer的BUF = ByteBuffer.wrap(数据).order(
                        ByteOrder.LITTLE_ENDIAN);
最后的ByteBuffer newBuf = ByteBuffer.allocate(
                        data.length).order(ByteOrder.LITTLE_ENDIAN);

INT样品;
        而(buf.hasRemaining()){
                样本=(int)的buf.getShort()及USHORT_MASK;
                样品* = db_value_global;
                        newBuf.putShort((短)(样品放; USHORT_MASK));
                }

                数据= newBuf.array();

                os.write(数据);
 

解决方案

据我所知,你不希望任何的自动调整,从UI只能手动。有没有内置的功能,这在Android中,相反,你必须手动修改数据。

假设你使用<一个href="http://developer.android.com/reference/android/media/AudioRecord.html#read(short[],%20int,%20int)">read (短[] audioData,INT offsetInShorts,INT sizeInShorts)用于读取数据流。所以,你应该做的是这样的:

 浮动收益= getGain(); //取自UI控件,也许在范围从0.0到2.0
INT numRead =读(audioData,0,大小);
如果(numRead大于0){
    的for(int i = 0; I&LT; numRead ++ I)
         audioData [I] =(短期)Math.min((INT)(audioData [我] *增益),(INT)Short.MAX_VALUE);
}
 

Math.min 用于prevent溢出,如果获得大于1。

i am working on a voice recording app. in app i have a Seekbar to change input voice gain. i have searched a lot but could not found any way to adjust input voice gain.

i am using AudioRecord class to record voice.

 recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
            RECORDER_SAMPLERATE, RECORDER_CHANNELS,
            RECORDER_AUDIO_ENCODING, bufferSize);

    recorder.startRecording();

i have seen an app also in play store which are using this functionality.

https://play.google.com/store/apps/details?id=com.grace.microphone

Thanks

Edit

i have done it using

final int USHORT_MASK = (1 << 16) - 1;

final ByteBuffer buf = ByteBuffer.wrap(data).order(
                        ByteOrder.LITTLE_ENDIAN);
final ByteBuffer newBuf = ByteBuffer.allocate(
                        data.length).order(ByteOrder.LITTLE_ENDIAN);

int sample;
        while (buf.hasRemaining()) {
                sample = (int) buf.getShort() & USHORT_MASK;
                sample *= db_value_global;
                        newBuf.putShort((short) (sample & USHORT_MASK));
                }

                data = newBuf.array();

                os.write(data);

解决方案

As I understand you don't want any automatic adjustments, only manual from the UI. There is no built-in functionality for this in Android, instead you have to modify your data manually.

Suppose you use read (short[] audioData, int offsetInShorts, int sizeInShorts) for reading the stream. So you should just do something like this:

float gain = getGain(); // taken from the UI control, perhaps in range from 0.0 to 2.0
int numRead = read(audioData, 0, SIZE);
if (numRead > 0) {
    for (int i = 0; i < numRead; ++i)
         audioData[i] = (short)Math.min((int)(audioData[i] * gain), (int)Short.MAX_VALUE);
}

Math.min is used to prevent overflow if gain is greater than 1.

这篇关于如何在录制音频的android调整麦克风灵敏度 - 已解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆