set mixer volume
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
#include <dsound.h>
|
#include <dsound.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#pragma comment(lib, "dsound.lib")
|
#pragma comment(lib, "dsound.lib")
|
||||||
#pragma comment(lib, "dxguid.lib")
|
#pragma comment(lib, "dxguid.lib")
|
||||||
|
|
||||||
@@ -44,8 +46,12 @@ bool DSound::IsEmulated() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware,
|
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_;
|
channels = channels_;
|
||||||
samplerate = samplerate_;
|
samplerate = samplerate_;
|
||||||
samplebits = samplebits_;
|
samplebits = samplebits_;
|
||||||
@@ -80,6 +86,8 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware,
|
|||||||
format.dwFlags |= DSBCAPS_LOCSOFTWARE;
|
format.dwFlags |= DSBCAPS_LOCSOFTWARE;
|
||||||
if(hardware == HW_DONT_CARE)
|
if(hardware == HW_DONT_CARE)
|
||||||
format.dwFlags |= DSBCAPS_STATIC;
|
format.dwFlags |= DSBCAPS_STATIC;
|
||||||
|
if(vol != 1)
|
||||||
|
format.dwFlags |= DSBCAPS_CTRLVOLUME;
|
||||||
format.dwBufferBytes = buffersize;
|
format.dwBufferBytes = buffersize;
|
||||||
format.dwReserved = 0;
|
format.dwReserved = 0;
|
||||||
format.lpwfxFormat = &waveformat;
|
format.lpwfxFormat = &waveformat;
|
||||||
@@ -94,8 +102,15 @@ DSoundBuf::DSoundBuf(DSound &ds, DSoundBuf::hw hardware,
|
|||||||
if(buf == NULL)
|
if(buf == NULL)
|
||||||
RageException::ThrowNonfatal("foo"); // XXX
|
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()
|
DSoundBuf::~DSoundBuf()
|
||||||
{
|
{
|
||||||
buf->Release();
|
buf->Release();
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ class DSoundBuf
|
|||||||
public:
|
public:
|
||||||
enum hw { HW_HARDWARE, HW_SOFTWARE, HW_DONT_CARE };
|
enum hw { HW_HARDWARE, HW_SOFTWARE, HW_DONT_CARE };
|
||||||
DSoundBuf(DSound &ds, hw hardware,
|
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);
|
bool get_output_buf(char **buffer, unsigned *bufsiz, int *play_pos, int chunksize);
|
||||||
void release_output_buf(char *buffer, unsigned bufsiz);
|
void release_output_buf(char *buffer, unsigned bufsiz);
|
||||||
|
|||||||
@@ -161,7 +161,8 @@ RageSound_DSound::RageSound_DSound()
|
|||||||
try {
|
try {
|
||||||
newbuf = new DSoundBuf(ds,
|
newbuf = new DSoundBuf(ds,
|
||||||
DSoundBuf::HW_HARDWARE,
|
DSoundBuf::HW_HARDWARE,
|
||||||
channels, samplerate, 16, buffersize);
|
channels, samplerate, 16, buffersize,
|
||||||
|
0.50f);
|
||||||
} catch(const RageException &e) {
|
} catch(const RageException &e) {
|
||||||
/* If we didn't get at least 8, fail. */
|
/* If we didn't get at least 8, fail. */
|
||||||
if(i >= 8) break; /* OK */
|
if(i >= 8) break; /* OK */
|
||||||
|
|||||||
Reference in New Issue
Block a user