Pergunta

Actually I want to give the volume control of left channel and right channel of audio device to user which user use different numbers for each channels. I used "waveOutSetVolume()".It has 2 arguments.first one is handle and second one is hexadecimal or DWORD number.

I got 2 numbers.each one for each channel and then convert them to string.now how i convert them into hexadecimal with "0x" format? Generally,How to change volume of each channel seperatly?

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);
}
Foi útil?

Solução

I fix that

DWORD d = 0xffff & soundVolumeCalculus(leftChannelVolume) ;
DWORD dd = 0xffff0000 & (soundVolumeCalculus(rightChannelVolume)*65535);

waveOutSetVolume(hWaveOut,dd+d);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top