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 }
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 }
解决方案 »
- android4.0 A10开发板,如何实现分屏(多屏幕显示)不同的内容
- ANDROID中用MediaPlayer不能播放中文文件名的MP3??
- android在相对布局中新添加Button的属性设置问题
- 郁闷啊,北京android这么难找到工作么
- 为什么这里会有add(T Object)之类的方法
- 哪位前辈有关于android图像处理方面的教程
- 求助 有个android手机建立热点后发送组播信息的问题 ...
- cocos2d-x 3.0 的CCTime怎么修改?
- 求教大神!
- Android studio 运行按钮是灰色的,不能运行
- 本人大专在校生,想要参加一个小比赛,关于 java ,android 都可以,各位大侠帮忙给点有创意的点子呗
- 有谁曾用ant把src打成一个jar包吗
我没记错的话read中获取到的buffer 记录到的是音波振幅,这个和音量是成正比的。
请问getVolume获取的是怎么音量?怎么用的?
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为最大!!
哇 牛牛牛
我是个算法白痴,拿笔划了半天,亮点是float r
就是说这个算法的实质就是把 变化 的值给缩到最小 从而控制在value 的0 到100可控
int t = 0;
for (int i = 0; i < buffer.length; i++) {
t += Math.abs(buffer[i]);
}
t /= buffer.length;
System.out.println("你的音量" + t);
我的博客:http://blog.csdn.net/xys289187120
不过开眼了,上层也有问题..学习,先MARK!
我觉得问题好像不是出在差值上。我通过反复测试发现五楼的算法好像并不是把值控制在0到100之间,我对着手机麦克播放音乐,首先把音乐声音关到最小,然后逐步放大音量。麦克接收到的音量值也会跟这重零开始逐步增长。但当接收到的音量达到50多的时候便停止增长了。而且无论我将音乐声音再放大录制的音量也是50多。如果将五楼公式中是“>> 1”去掉则最高停留在110多。所以我认为五楼的算法应该是在0到60之间。
但现在的问题是如果我手机一边播放音乐一边录音,播放音量开到一半的时候录音音量就达到顶峰了。这是很让人郁闷的一件事。
http://topic.csdn.net/u/20101229/14/01099efc-d8e1-43d5-a714-2a84f72c4496.html