录制的音频提高音量输出 [英] Increase volume output of recorded audio

查看:288
本文介绍了录制的音频提高音量输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Android的一个通话录音应用程序。我使用的扬声器来记录上行和下行音频。我现在面临的唯一问题是音量太低。我已经用增加至AudioManager最大设备的音量,也不能超越的。

I am trying to make a call recording app in Android. I am using loudspeaker to record both uplink and downlink audio. The only problem I am facing is the volume is too low. I've increased the volume of device using AudioManager to max and it can't go beyond that.

我第一次使用MediaRecorder,但由于它有有限的功能,并提供COM pressed声音,我已经试过AudioRecorder。不过我没有带想通了如何增加音频。我已经在Github上项目检查过,但它是没有用的。我搜索计算器上的最后两个星期,但无法找到任何东西都

I've first used MediaRecorder, but since it had limited functions and provides compressed audio, I've tried with AudioRecorder. Still I havn't figured out how to increase the audio. I've checked on projects on Github too, but it's of no use. I've searched on stackoverflow for last two weeks, but couldn't find anything at all.

我敢肯定,这是可能的,因为许多其他应用正在这样做。例如自动呼叫记录做到这一点。

I am quite sure that it's possible, since many other apps are doing it. For instance Automatic Call recorder does that.

我知道我必须做与音频缓冲的东西,但我不能肯定需要在该做些什么。你能指导我这一点。

I understand that I have to do something with the audio buffer, but I am not quite sure what needs to be done on that. Can you guide me on that.

更新: - 结果
我很抱歉,我忘了提,我已经使用增益。我的code几乎类似于<一个href=\"http://sourceforge.net/p/rehearsalassist/$c$c/HEAD/tree/android/branches/pause_and_gain/src/urbanstew/RehearsalAssistant/RehearsalAssistant.java\"相对=nofollow> RehearsalAssistant (其实我得出它从那里)。增益不为超过10dB的工作并且不增加音频音量太大。我想要是我应该能够收听音频没有把我的耳朵上这是在我的code缺乏什么喇叭。

Update:-
I am sorry that I forgot to mention that I am already using Gain. My code is almost similar to RehearsalAssistant (in fact I derived it from there). The gain doesn't work for more than 10dB and that doesn't increase the audio volume too much. What I wanted is I should be able to listen to the audio without putting my ear on the speaker which is what lacking in my code.

我问过的音量/响度的运作类似的问题在SoundDesign SE <一个href=\"http://sound.stackexchange.com/questions/30334/how-to-increase-the-volume-of-a-sound-while-recording\">here.它提到,增益和响度有关,但它不设置实际的响度水平。我不知道是如何工作的,但我下定决心要取得响亮的音量输出。

I've asked a similar question on functioning of the volume/loudness at SoundDesign SE here. It mentions that the Gain and loudness is related but it doesn't set the actual loudness level. I am not sure how things work, but I am determined to get the loud volume output.

推荐答案

您明明有运行 AudioRecord 的东西,所以我跳过的决定采样率的InputSource 。主要的一点是,你需要适当地操作您的记录数据的每个样本中录制循环增大音量。像这样:

You obviously have the AudioRecord stuff running, so I skip the decision for sampleRate and inputSource. The main point is that you need to appropriately manipulate each sample of your recorded data in your recording loop to increase the volume. Like so:

    int minRecBufBytes = AudioRecord.getMinBufferSize( sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT );
    // ...
    audioRecord = new AudioRecord( inputSource, sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, minRecBufBytes );

    // Setup the recording buffer, size, and pointer (in this case quadruple buffering)
    int recBufferByteSize = minRecBufBytes*2;
    byte[] recBuffer = new byte[recBufferByteSize];
    int frameByteSize = minRecBufBytes/2;
    int sampleBytes = frameByteSize;
    int recBufferBytePtr = 0;

    audioRecord.startRecording();

    // Do the following in the loop you prefer, e.g.
    while ( continueRecording ) {
        int reallySampledBytes = audioRecord.read( recBuffer, recBufferBytePtr, sampleBytes );

        int i = 0;
        while ( i < reallySampledBytes ) {
            float sample = (float)( recBuffer[recBufferBytePtr+i  ] & 0xFF
                                  | recBuffer[recBufferBytePtr+i+1] << 8 );

            // THIS is the point were the work is done:
            // Increase level by about 6dB:
            sample *= 2;
            // Or increase level by 20dB:
            // sample *= 10;
            // Or if you prefer any dB value, then calculate the gain factor outside the loop
            // float gainFactor = (float)Math.pow( 10., dB / 20. );    // dB to gain factor
            // sample *= gainFactor;

            // Avoid 16-bit-integer overflow when writing back the manipulated data:
            if ( sample >= 32767f ) {
                recBuffer[recBufferBytePtr+i  ] = (byte)0xFF;
                recBuffer[recBufferBytePtr+i+1] =       0x7F;
            } else if ( sample <= -32768f ) {
                recBuffer[recBufferBytePtr+i  ] =       0x00;
                recBuffer[recBufferBytePtr+i+1] = (byte)0x80;
            } else {
                int s = (int)( 0.5f + sample );  // Here, dithering would be more appropriate
                recBuffer[recBufferBytePtr+i  ] = (byte)(s & 0xFF);
                recBuffer[recBufferBytePtr+i+1] = (byte)(s >> 8 & 0xFF);
            }
            i += 2;
        }

        // Do other stuff like saving the part of buffer to a file
        // if ( reallySampledBytes > 0 ) { ... save recBuffer+recBufferBytePtr, length: reallySampledBytes

        // Then move the recording pointer to the next position in the recording buffer
        recBufferBytePtr += reallySampledBytes;

        // Wrap around at the end of the recording buffer, e.g. like so:
        if ( recBufferBytePtr >= recBufferByteSize ) {
            recBufferBytePtr = 0;
            sampleBytes = frameByteSize;
        } else {
            sampleBytes = recBufferByteSize - recBufferBytePtr;
            if ( sampleBytes > frameByteSize )
                sampleBytes = frameByteSize;
        }
    }

这篇关于录制的音频提高音量输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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