问题:使用的双缓冲无效果,没有起到作用,听的声音还是一卡一卡的,请大虾们看看我写的哪出错了?
WAVEFORMATEX waveformat = {WAVE_FORMAT_PCM, (WORD)1, 8000, 16000, (WORD)2, (WORD)16, 0}; //设定波形音频的格式
//打开音频设备
DWORD rval = waveOutOpen(&hWaveOut, WAVE_MAPPER, &waveformat, (DWORD_PTR)WaveCallback, (DWORD)this, CALLBACK_FUNCTION);
waveHdr1.dwBufferLength = SIZEPERFRAME * FRAMEPERPACKET * PACKETPERPLAY;
waveHdr1.lpData = pData[0];
waveHdr1.dwFlags = WHDR_DONE;
waveHdr1.dwLoops = 0;
waveHdr1.lpNext = NULL;
waveHdr2.dwBufferLength = SIZEPERFRAME * FRAMEPERPACKET * PACKETPERPLAY;
waveHdr2.lpData = pData[1];
waveHdr2.dwFlags = WHDR_DONE;
waveHdr2.dwLoops = 0;
waveHdr2.lpNext = NULL;
//写入wave设备
waveOutPrepareHeader(hWaveOut, &waveHdr1, sizeof(WAVEHDR));
waveOutPrepareHeader(hWaveOut, &waveHdr2, sizeof(WAVEHDR));
waveOutWrite(hWaveOut, &waveHdr1, sizeof(WAVEHDR));
waveOutWrite(hWaveOut, &waveHdr2, sizeof(WAVEHDR));
//回调函数
void CALLBACK CAudioManger::WaveCallback(HWAVEOUT hWave, UINT uMsg, DWORD dwUser,DWORD dw1, DWORD dw2)
{
CAudioManger *pWavePlay = (CAudioManger*)dwUser;
if(NULL != pWavePlay && uMsg == WOM_DONE)
{
LPWAVEHDR pWaveHeader = (LPWAVEHDR)dw1;
waveOutUnprepareHeader( hWave, pWaveHeader, sizeof(WAVEHDR) );
while (1)
{
if (pWavePlay->pPlay->pNext->nNum >= PACKETPERPLAY-1)
{
pWavePlay->pPlay = pWavePlay->pPlay->pNext;
break;
}
}
pWaveHeader->lpData = pWavePlay->pPlay->pBuffer;
pWavePlay->pPlay->nNum = 0;
pWaveHeader->dwBufferLength = SIZEPERFRAME * FRAMEPERPACKET * PACKETPERPLAY;
pWaveHeader->lpNext = NULL;
waveOutPrepareHeader(hWave, pWaveHeader, sizeof(WAVEHDR));
waveOutWrite(hWave, pWaveHeader, sizeof(WAVEHDR) );
}
return ;
}
------最佳解决方案--------------------------------------------------------
这样啊。那你的pBuffer里面获取到的数据大小你确定是SIZEPERFRAME * FRAMEPERPACKET * PACKETPERPLAY嘛?
------其他解决方案--------------------------------------------------------
需要播放的文件格式和你设置的WAVEFORMATEX是一样的吗?最好根据文件读取格式,然后设置WAVEFORMATEX。
回调函数中while循环没怎么看懂。会不会造成死循环啊?
------其他解决方案--------------------------------------------------------
额、这里竟然是.NET区。。
------其他解决方案--------------------------------------------------------
网速不好,怎么缓冲也没用.
------其他解决方案--------------------------------------------------------
to:zq282502532
WAVEFORMATEX格式是一样的,我是捕获麦克风的不是读取文件,设置的格式如下
WAVEFORMATEX waveformat;
waveformat.wFormatTag = WAVE_FORMAT_PCM;
waveformat.nChannels = (WORD)1;
waveformat.nSamplesPerSec = 8000;
waveformat.nAvgBytesPerSec = waveformat.nSamplesPerSec*2;
waveformat.wBitsPerSample = (WORD)16;
waveformat.nBlockAlign = (WORD)2;
while不会死循环的,这里只是多增加一个判断而已
to:liuqian4243
是在局域网,每次进入回调都能可以填充数据
------其他解决方案--------------------------------------------------------