Playing Stereo PCM with DirectSound
Hey, I have simple 16-bit PCM player that I made using DirectSound. But when 开发者_Python百科it plays, it seems that it plays only one speaker instead of both.
I don't know what code to post exactly, so you'll have to tell me if you need any. I can say that I create the sound buffer using, and lock the stream using:
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);
Have you tried playing sound through another application (like Windows Media player)?
I had a similar problem and after an hour looking at the code I realised that the cause was a dodgy speaker jack. After I waggled it both speakers started working.
If other applications do have problems it might not be the hardware. Also check the left and right speaker volume in Windows.
精彩评论