嘿,我有一个使用 DirectSound 制作的简单 16 位 PCM 播放器。但是当它播放时,它似乎只播放一个扬声器而不是两个。
我不知道要准确发布什么代码,所以如果您需要任何代码,您必须告诉我。我可以说我使用创建声音缓冲区,并使用以下方法锁定流:
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);