实际上我想将音频设备的左声道和右声道的音量控制给用户,每个用户使用不同的数字。 我使用" waveOutSetVolume()"。它有2个参数。第一个是句柄,第二个是十六进制或DWORD编号。
我有2个数字。每个通道一个,然后将它们转换为string.now我如何将它们转换为十六进制,用" 0x"格式? 一般来说,如何分别改变每个频道的音量?
void Audio::setChannelsVolume(int rightChannelVolume, int leftChannelVolume)
{
if(leftChannelVolume < 0)
leftChannelVolume = 0;
if(leftChannelVolume > 100)
leftChannelVolume = 100;
if(rightChannelVolume < 0)
rightChannelVolume = 0;
if(rightChannelVolume > 100)
rightChannelVolume = 100;
stringstream volume;
if(leftChannelVolume < 7 && leftChannelVolume > 0)
volume << "0x0" << std::hex << soundVolumeCalculus(leftChannelVolume);
else
volume << "0x"<< std::hex << soundVolumeCalculus(leftChannelVolume);
if(rightChannelVolume < 7 && rightChannelVolume > 0)
volume << "0" << std::hex << soundVolumeCalculus(rightChannelVolume);
else
volume << std::hex << soundVolumeCalculus(rightChannelVolume);
string str = volume.str();
cout<<str;
const char* ch = str.c_str();
waveOutSetVolume(hWaveOut,(DWORD)ch);
}
///////////////////////////////////////////////
int Audio::soundVolumeCalculus(int volume)
{
return (int)((65535*volume)/100);
}
答案 0 :(得分:0)
我解决了这个问题
DWORD d = 0xffff & soundVolumeCalculus(leftChannelVolume) ;
DWORD dd = 0xffff0000 & (soundVolumeCalculus(rightChannelVolume)*65535);
waveOutSetVolume(hWaveOut,dd+d);