527     //---------------------------------------------------------
    528     // Audio data supply
    529     //--------------------
    530     /**
    531      * Reads audio data from the audio hardware for recording into a buffer.
    532      * @param audioData the array to which the recorded audio data is written.
    533      * @param offsetInBytes index in audioData from which the data is written expressed in bytes.
    534      * @param sizeInBytes the number of requested bytes.
    535      * @return the number of bytes that were read or or {@link #ERROR_INVALID_OPERATION}
    536      *    if the object wasn't properly initialized, or {@link #ERROR_BAD_VALUE} if
    537      *    the parameters don't resolve to valid data and indexes.
    538      *    The number of bytes will not exceed sizeInBytes.
    539      */
    540     public int read(byte[] audioData, int offsetInBytes, int sizeInBytes) {
    541         if (mState != STATE_INITIALIZED) {
    542             return ERROR_INVALID_OPERATION;
    543         }
    544 
    545         if ( (audioData == null) || (offsetInBytes < 0 ) || (sizeInBytes < 0)
    546                 || (offsetInBytes + sizeInBytes > audioData.length)) {
    547             return ERROR_BAD_VALUE;
    548         }
    549 
    550         return native_read_in_byte_array(audioData, offsetInBytes, sizeInBytes);
    551     }
这是read 的实现函数,你用这个函数得到音量不对吧? buffer 里面是记录的record的数据呀。
用这个函数吧:  442 void AudioTrack::getVolume(float* left, float* right)
    443 {
    444     *left  = mVolume[LEFT];
    445     *right = mVolume[RIGHT];
    446 }

解决方案 »

  1.   


    我没记错的话read中获取到的buffer 记录到的是音波振幅,这个和音量是成正比的。
    请问getVolume获取的是怎么音量?怎么用的?
      

  2.   

    才做完录音播放的软件 我给你说说我的经验吧。
    for (int i = 0; i < buffer.length; i++) {
    v += buffer[i] * buffer[i];
    }


    int value = (int) (Math.abs((int)(v /(float)r)/10000) >> 1);我计算了噪音 
    value 的 值 控制 为 0 到 100 之间 0为最小  》= 100为最大!!
      

  3.   

    Hope this can give you some inspirehttp://blog.csdn.net/hellogv/article/details/6026455
      

  4.   


    哇 牛牛牛 
    我是个算法白痴,拿笔划了半天,亮点是float r
      

  5.   

    看看MediaRecorder类,我没用过的,楼主可以研究下,是Android专门录音的
      

  6.   


    就是说这个算法的实质就是把 变化 的值给缩到最小 从而控制在value 的0 到100可控 
      

  7.   

    audioRecord.read(buffer, 0, recBufSize);
    int t = 0;
    for (int i = 0; i < buffer.length; i++) {
        t += Math.abs(buffer[i]);
    }
    t /= buffer.length;
    System.out.println("你的音量" + t);
      

  8.   

    其实这个算法还是有优化的余地, 最近我就在公司做优化算法这一块,到时候一定及时分享给大家~~~~
    我的博客:http://blog.csdn.net/xys289187120
      

  9.   

    我们的机器,录音声音一直很小,一直认为是硬件问题,在LINUX下面,直接采集,音量也小....
    不过开眼了,上层也有问题..学习,先MARK!
      

  10.   


    我觉得问题好像不是出在差值上。我通过反复测试发现五楼的算法好像并不是把值控制在0到100之间,我对着手机麦克播放音乐,首先把音乐声音关到最小,然后逐步放大音量。麦克接收到的音量值也会跟这重零开始逐步增长。但当接收到的音量达到50多的时候便停止增长了。而且无论我将音乐声音再放大录制的音量也是50多。如果将五楼公式中是“>> 1”去掉则最高停留在110多。所以我认为五楼的算法应该是在0到60之间。
    但现在的问题是如果我手机一边播放音乐一边录音,播放音量开到一半的时候录音音量就达到顶峰了。这是很让人郁闷的一件事。
      

  11.   

    如何通过麦克风来获取当前说话的音量或分贝高低:
    http://topic.csdn.net/u/20101229/14/01099efc-d8e1-43d5-a714-2a84f72c4496.html