您的位置:首页 > 其它

8bit采样声音数据的音量计算

2013-05-16 17:01 369 查看
float calcSoundVol(IN void * pBuf, int nlen){
// 计算该采样率下的最大值
float maxVol=pow(2.0f,sampleBits-1)-1;

switch(sampleBits)
{
case 8: // 该例子只处理8bit采样的情况
{
float resultVol = 0.0f;
// 该例子只有一个声道
if(nChannels == 1)
{
for(int i=0;i<nlen;i++)
{
float sampleVol = fabs(*(char*)pBuffer);
if(sampleVol>-maxVol && sampleVol<maxVol && value > resultVol)
resultVol = value;
}
printf("Volume=%.2f\n", resultVol/maxVol*100.0f);
}
}break;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: