set mixer volume

This commit is contained in:
Glenn Maynard
2003-01-08 00:44:17 +00:00
parent 89a3690d59
commit 92d2a28940
3 changed files with 20 additions and 3 deletions
+16 -1
View File
@@ -7,6 +7,8 @@
#include <mmsystem.h>
#include <dsound.h>
#include <math.h>
#pragma comment(lib, "dsound.lib")
#pragma comment(lib, "dxguid.lib")
@@ -44,8 +46,12 @@ bool DSound::IsEmulated() const
}
DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware,
int channels_, int samplerate_, int samplebits_, int writeahead_)
int channels_, int samplerate_, int samplebits_, int writeahead_,
float vol)
{
ASSERT(vol >= 0);
ASSERT(vol <= 1);
channels = channels_;
samplerate = samplerate_;
samplebits = samplebits_;
@@ -80,6 +86,8 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware,
format.dwFlags |= DSBCAPS_LOCSOFTWARE;
if(hardware == HW_DONT_CARE)
format.dwFlags |= DSBCAPS_STATIC;
if(vol != 1)
format.dwFlags |= DSBCAPS_CTRLVOLUME;
format.dwBufferBytes = buffersize;
format.dwReserved = 0;
format.lpwfxFormat = &waveformat;
@@ -94,8 +102,15 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware,
if(buf == NULL)
RageException::ThrowNonfatal("foo"); // XXX
float vl2 = log10f(vol) / log10f(2); /* vol log 2 */
/* Volume is in percent; SetVolume wants attenuation in thousands of a
* decibel. */
if(vol != 1)
buf->SetVolume(max(int(1000 * vl2), DSBVOLUME_MIN));
}
DSoundBuf::~DSoundBuf()
{
buf->Release();
+2 -1
View File
@@ -40,7 +40,8 @@ class DSoundBuf
public:
enum hw { HW_HARDWARE, HW_SOFTWARE, HW_DONT_CARE };
DSoundBuf(DSound &ds, hw hardware,
int channels, int samplerate, int samplebits, int writeahead);
int channels, int samplerate, int samplebits, int writeahead,
float vol=1);
bool get_output_buf(char **buffer, unsigned *bufsiz, int *play_pos, int chunksize);
void release_output_buf(char *buffer, unsigned bufsiz);
@@ -161,7 +161,8 @@ RageSound_DSound::RageSound_DSound()
try {
newbuf = new DSoundBuf(ds,
DSoundBuf::HW_HARDWARE,
channels, samplerate, 16, buffersize);
channels, samplerate, 16, buffersize,
0.50f);
} catch(const RageException &e) {
/* If we didn't get at least 8, fail. */
if(i >= 8) break; /* OK */