//通过mask转换得到音频通道数量
#include <stdio.h>
//通过mask转换得到音频通道数量
static int num_channels(int chanmask)
{
int num = 0;
while (chanmask)
{
num += (chanmask & 1);
chanmask >>= 1;
}
return num;
}
int main()
{
int c_chmask = 0x00;
printf(" channels is %d \r\n",num_channels(c_chmask));
c_chmask = 0x01;
printf(" channels is %d \r\n",num_channels(c_chmask));
c_chmask = 0x03;
printf(" channels is %d \r\n",num_channels(c_chmask));
c_chmask = 0x07;
printf(" channels is %d \r\n",num_channels(c_chmask));
c_chmask = 0x0f;
printf(" channels is %d \r\n",num_channels(c_chmask));
return 0;
}
channels is 0
channels is 1
channels is 2
channels is 3
channels is 4
例子:
0x3 得到2ch音频