我不知道要准确发布什么代码,所以你必须告诉我你是否需要。 我可以说我使用创建声音缓冲区,并使用以下方法锁定流:
WAVEFORMATEX wfx; ZeroMemory(&wfx, sizeof(wfx));
LPDIRECTSOUNDBUFFER pDsb = NULL;
memset(&wfx, 0, sizeof(WAVEFORMATEX));
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = snd->channels;
wfx.nSamplesPerSec = snd->sample_rate;
wfx.nBlockAlign = snd->channels * 2;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
wfx.wBitsPerSample = 16;
DSBUFFERDESC dsbdesc; ZeroMemory(&dsbdesc, sizeof(dsbdesc));
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_GLOBALFOCUS;
dsbdesc.dwBufferBytes = snd->size;
dsbdesc.lpwfxFormat = &wfx;
SoundMgr->CreateSoundBuffer(&dsbdesc, &pDsb, NULL);
pDsb->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*)&snd->voice);
pDsb->Release();
DWORD len;
snd->voice->Lock(0, 0, (void**)&snd->data, &len, NULL, NULL, DSBLOCK_ENTIREBUFFER);
答案 0 :(得分:1)
您是否曾尝试通过其他应用程序(如Windows Media Player)播放声音?
我遇到了类似的问题,一小时后看着代码,我意识到原因是一个狡猾的扬声器插孔。在我摇摇晃晃之后,两位发言者都开始工作了。
如果其他应用程序确实存在问题,则可能不是硬件。另请检查Windows中的左右扬声器音量。