Commit 36e90546 authored by Maarten Lankhorst's avatar Maarten Lankhorst Committed by Alexandre Julliard

dsound: Move resampling away from mixer thread.

parent 1ad6abfb
......@@ -23,6 +23,8 @@
#define DS_TIME_RES 2 /* Resolution of multimedia timer */
#define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */
#include "wine/list.h"
/* direct sound hardware acceleration levels */
#define DS_HW_ACCEL_FULL 0 /* default on Windows 98 */
#define DS_HW_ACCEL_STANDARD 1 /* default on Windows 2000 */
......@@ -108,6 +110,7 @@ typedef struct BufferMemory
{
LONG ref;
LPBYTE memory;
struct list buffers;
} BufferMemory;
ULONG DirectSoundDevice_Release(DirectSoundDevice * device);
......@@ -159,16 +162,17 @@ struct IDirectSoundBufferImpl
PIDSDRIVERBUFFER hwbuf;
PWAVEFORMATEX pwfx;
BufferMemory* buffer;
LPBYTE tmp_buffer;
DWORD playflags,state,leadin;
DWORD startpos,writelead,buflen;
DWORD writelead,buflen;
DWORD nAvgBytesPerSec;
DWORD freq;
DWORD freq, tmp_buffer_len, max_buffer_len;
DSVOLUMEPAN volpan;
DSBUFFERDESC dsbd;
/* used for frequency conversion (PerfectPitch) */
ULONG freqAdjust, freqAcc;
/* used for intelligent (well, sort of) prebuffering */
DWORD primary_mixpos, buf_mixpos;
ULONG freqneeded, freqAdjust, freqAcc, freqAccNext;
/* used for mixing */
DWORD primary_mixpos, buf_mixpos, sec_mixpos;
/* IDirectSoundNotifyImpl fields */
IDirectSoundNotifyImpl* notify;
......@@ -184,6 +188,8 @@ struct IDirectSoundBufferImpl
/* IKsPropertySet fields */
IKsBufferPropertySetImpl* iks;
struct list entry;
};
HRESULT IDirectSoundBufferImpl_Create(
......@@ -431,6 +437,9 @@ void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len
void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan);
void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
void DSOUND_MixToTemporary(const IDirectSoundBufferImpl *dsb, DWORD writepos, DWORD mixlen);
DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, DWORD* overshot);
void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
......@@ -460,7 +469,7 @@ HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
#define STATE_CAPTURING 2
#define STATE_STOPPING 3
#define DSOUND_FREQSHIFT (14)
#define DSOUND_FREQSHIFT (20)
extern DirectSoundDevice* DSOUND_renderer[MAXWAVEDRIVERS];
extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS];
......
......@@ -378,7 +378,7 @@ HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex)
{
HRESULT err = DS_OK;
int i, alloc_size, cp_size;
DWORD nSamplesPerSec;
DWORD nSamplesPerSec, bpp, chans;
TRACE("(%p,%p)\n", device, wfex);
if (device->priolevel == DSSCL_NORMAL) {
......@@ -410,6 +410,8 @@ HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex)
device->pwfx = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,device->pwfx,alloc_size);
nSamplesPerSec = device->pwfx->nSamplesPerSec;
bpp = device->pwfx->wBitsPerSample;
chans = device->pwfx->nChannels;
CopyMemory(device->pwfx, wfex, cp_size);
......@@ -459,14 +461,15 @@ HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex)
DSOUND_RecalcPrimary(device);
}
if (nSamplesPerSec != device->pwfx->nSamplesPerSec) {
if (nSamplesPerSec != device->pwfx->nSamplesPerSec || bpp != device->pwfx->wBitsPerSample || chans != device->pwfx->nChannels) {
IDirectSoundBufferImpl** dsb = device->buffers;
for (i = 0; i < device->nrofbuffers; i++, dsb++) {
/* **** */
RtlAcquireResourceExclusive(&(*dsb)->lock, TRUE);
(*dsb)->freqAdjust = ((*dsb)->freq << DSOUND_FREQSHIFT) /
wfex->nSamplesPerSec;
(*dsb)->freqAdjust = ((DWORD64)(*dsb)->freq << DSOUND_FREQSHIFT) / device->pwfx->nSamplesPerSec;
DSOUND_RecalcFormat((*dsb));
DSOUND_MixToTemporary((*dsb), 0, (*dsb)->buflen);
RtlReleaseResource(&(*dsb)->lock);
/* **** */
......@@ -769,7 +772,7 @@ static HRESULT WINAPI PrimaryBufferImpl_Lock(
writecursor, device->buflen);
return DSERR_INVALIDPARAM;
}
if (writebytes > device->buflen) {
WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
writebytes, device->buflen);
......
......@@ -279,7 +279,7 @@ void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb)
{
TRACE("doppler: Buffer and Listener don't have velocities\n");
}
else
else if (ds3db_ds3db.vVelocity != dsb->device->ds3dl.vVelocity)
{
/* calculate length of ds3db_ds3db.vVelocity component which causes Doppler Effect
NOTE: if buffer moves TOWARDS the listener, it's velocity component is NEGATIVE
......@@ -296,6 +296,8 @@ void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb)
dsb->freq, flFreq);
/* FIXME: replace following line with correct frequency setting ! */
dsb->freq = flFreq;
DSOUND_RecalcFormat(dsb);
DSOUND_MixToTemporary(dsb, 0, dsb->buflen);
}
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment