add new sound code

This commit is contained in:
Glenn Maynard
2002-12-13 08:33:25 +00:00
parent 2d3f6381f5
commit 3cbb03e273
12 changed files with 944 additions and 0 deletions
@@ -0,0 +1,52 @@
#include "../../stdafx.h"
#include "DSoundHelpers.h"
/* Stuff shared between the two DirectSound drivers. */
static IDirectSoundBuffer8 *CreateBuf(IDirectSound8 *ds8, WAVEFORMATEX *wavefmt, Uint32 buffersize, bool Hardware)
{
/* Try to create the secondary buffer */
DSBUFFERDESC format;
memset(&format, 0, sizeof(format));
format.dwSize = sizeof(format);
format.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;
if(Hardware)
format.dwFlags |= DSBCAPS_LOCHARDWARE;
format.dwBufferBytes = buffersize;
format.dwReserved = 0;
format.lpwfxFormat = wavefmt;
IDirectSoundBuffer *sndbuf_buf;
HRESULT hr = ds8->CreateSoundBuffer(&format, &sndbuf_buf, NULL);
if (FAILED(hr))
throw "CreateSoundBuffer failed";
IDirectSoundBuffer8 *buf;
sndbuf_buf->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) &buf);
return buf;
}
IDirectSoundBuffer8 *CreateBuf(IDirectSound8 *ds8,
int channels, int samplerate, int bits,
Uint32 buffersize, bool Hardware)
{
WAVEFORMATEX waveformat;
memset(&waveformat, 0, sizeof(waveformat));
waveformat.cbSize = sizeof(waveformat);
waveformat.wFormatTag = WAVE_FORMAT_PCM;
int bytes = bits/8;
waveformat.wBitsPerSample = WORD(bits);
waveformat.nChannels = WORD(channels);
waveformat.nSamplesPerSec = DWORD(samplerate);
waveformat.nBlockAlign = WORD(bytes*channels);
waveformat.nAvgBytesPerSec = samplerate * bytes*channels;
return CreateBuf(ds8, &waveformat, buffersize, Hardware);
}
/*
* Copyright (c) 2002 by the person(s) listed below. All rights reserved.
*
* Glenn Maynard
*/