MCI接口实现音频左右声道控制

由于工作原因,领导要求实现一段音频播放功能的代码,并实现左右声道单独播放.
后来查询之后可以由mciSendCommand和mciSendString来实现,播放,停止一些简单的命令2个函数都能实现.
但是...mciSendCommand对左右声道的操控未果,不知是和原因,请大神指点...
附上mciSendCommand对左右声道操控的代码,,,这段代码在实际运用中不起作用....

MCI_DGV_SETAUDIO_PARMS s;
mciSendCommand(m_idDevPlay,MCI_SETAUDIO, MCI_SET_OFF ,(DWORD_PTR)&s);
switch (nC)
{
case C_L:
s.dwValue = MCI_DGV_SETAUDIO_SOURCE_LEFT;
break;
case C_R:
s.dwValue = MCI_DGV_SETAUDIO_SOURCE_RIGHT;
break;
default:
s.dwValue = MCI_DGV_SETAUDIO_SOURCE_STEREO;
break;
}
s.dwItem = MCI_DGV_SETAUDIO_SOURCE;
mciSendCommand(m_idDevPlay,MCI_SETAUDIO,MCI_DGV_SETAUDIO_VALUE | MCI_DGV_SETAUDIO_ITEM ,(DWORD_PTR)&s);
mciSendCommand(m_idDevPlay,MCI_SETAUDIO, MCI_SET_ON ,(DWORD_PTR)&s);

后来用mciSendString实现了左右声道的切换,特此记录 附代码....

#define MCISENDSTRING3(x,y,z) \
memset(strCommand,0,sizeof(strCommand)); \
sprintf_s(strCommand,256,x); \
mciSendString(strCommand,NULL,0,0); \
memset(strCommand,0,sizeof(strCommand)); \
sprintf_s(strCommand,256,y); \
mciSendString(strCommand,NULL,0,0); \
memset(strCommand,0,sizeof(strCommand)); \
sprintf_s(strCommand,256,z); \
mciSendString(strCommand,NULL,0,0);

void MCIPlayer::SetChannel(int nChannel)
{
if (m_bOpen)
{
char strCommand[256];
switch (nChannel)
{
case 1:
MCISENDSTRING3("setaudio NOWMUSIC source to left","setaudio NOWMUSIC left on","setaudio NOWMUSIC right off");
break;
case 2:
MCISENDSTRING3("setaudio NOWMUSIC source to right","setaudio NOWMUSIC left off","setaudio NOWMUSIC right on");
break;
default:
MCISENDSTRING3("setaudio NOWMUSIC source to stereo","setaudio NOWMUSIC left on","setaudio NOWMUSIC right on");
break;
}
}
}


你可能感兴趣的:(C++)