1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-08 20:06:18 +00:00

mmdevapi: Fill buffer with silence in IAudioRenderClient::GetBuffer.

This commit is contained in:
Andrew Eikum 2013-11-12 10:17:21 -06:00 committed by Alexandre Julliard
parent 8c97327da6
commit a5975bb601
4 changed files with 57 additions and 27 deletions

View File

@ -692,8 +692,8 @@ static void test_padding(void)
IAudioRenderClient *arc;
WAVEFORMATEX *pwfx;
REFERENCE_TIME minp, defp;
BYTE *buf;
UINT32 psize, pad, written;
BYTE *buf, silence;
UINT32 psize, pad, written, i;
hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
NULL, (void**)&ac);
@ -712,6 +712,11 @@ static void test_padding(void)
if(hr != S_OK)
return;
if(pwfx->wBitsPerSample == 8)
silence = 128;
else
silence = 0;
/** GetDevicePeriod
* Default (= shared) device period is 10ms (e.g. 441 frames at 44100),
* except when the HW/OS forces a particular alignment,
@ -738,6 +743,12 @@ static void test_padding(void)
hr = IAudioRenderClient_GetBuffer(arc, psize, &buf);
ok(hr == S_OK, "GetBuffer failed: %08x\n", hr);
ok(buf != NULL, "NULL buffer returned\n");
for(i = 0; i < psize * pwfx->nBlockAlign; ++i){
if(buf[i] != silence){
ok(0, "buffer has data in it already\n");
break;
}
}
hr = IAudioRenderClient_GetBuffer(arc, 0, &buf);
ok(hr == AUDCLNT_E_OUT_OF_ORDER, "GetBuffer 0 size failed: %08x\n", hr);

View File

@ -2466,6 +2466,18 @@ static ULONG WINAPI AudioRenderClient_Release(IAudioRenderClient *iface)
return AudioClient_Release(&This->IAudioClient_iface);
}
static void silence_buffer(ACImpl *This, BYTE *buffer, UINT32 frames)
{
WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)This->fmt;
if((This->fmt->wFormatTag == WAVE_FORMAT_PCM ||
(This->fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))) &&
This->fmt->wBitsPerSample == 8)
memset(buffer, 128, frames * This->fmt->nBlockAlign);
else
memset(buffer, 0, frames * This->fmt->nBlockAlign);
}
static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
UINT32 frames, BYTE **data)
{
@ -2515,6 +2527,8 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
This->getbuf_last = frames;
}
silence_buffer(This, *data, frames);
LeaveCriticalSection(&This->lock);
return S_OK;
@ -2568,12 +2582,8 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
else
buffer = This->tmp_buffer;
if(flags & AUDCLNT_BUFFERFLAGS_SILENT){
if(This->fmt->wBitsPerSample == 8)
memset(buffer, 128, written_frames * This->fmt->nBlockAlign);
else
memset(buffer, 0, written_frames * This->fmt->nBlockAlign);
}
if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
silence_buffer(This, buffer, written_frames);
if(This->getbuf_last < 0)
alsa_wrap_buffer(This, buffer, written_frames);

View File

@ -2024,6 +2024,18 @@ static ULONG WINAPI AudioRenderClient_Release(IAudioRenderClient *iface)
return AudioClient_Release(&This->IAudioClient_iface);
}
static void silence_buffer(ACImpl *This, BYTE *buffer, UINT32 frames)
{
WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)This->fmt;
if((This->fmt->wFormatTag == WAVE_FORMAT_PCM ||
(This->fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))) &&
This->fmt->wBitsPerSample == 8)
memset(buffer, 128, frames * This->fmt->nBlockAlign);
else
memset(buffer, 0, frames * This->fmt->nBlockAlign);
}
static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
UINT32 frames, BYTE **data)
{
@ -2094,6 +2106,7 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
This->getbuf_last = frames;
*data = This->public_buffer->mAudioData;
silence_buffer(This, *data, frames);
OSSpinLockUnlock(&This->lock);
@ -2133,18 +2146,8 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
return AUDCLNT_E_INVALID_SIZE;
}
if(flags & AUDCLNT_BUFFERFLAGS_SILENT){
WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)This->fmt;
if((This->fmt->wFormatTag == WAVE_FORMAT_PCM ||
(This->fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))) &&
This->fmt->wBitsPerSample == 8)
memset(This->public_buffer->mAudioData, 128,
frames * This->fmt->nBlockAlign);
else
memset(This->public_buffer->mAudioData, 0,
frames * This->fmt->nBlockAlign);
}
if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
silence_buffer(This, This->public_buffer->mAudioData, frames);
This->public_buffer->mAudioDataByteSize = frames * This->fmt->nBlockAlign;

View File

@ -1367,12 +1367,16 @@ static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient *iface,
return S_OK;
}
static void oss_silence_buffer(ACImpl *This, BYTE *buf, UINT32 frames)
static void silence_buffer(ACImpl *This, BYTE *buffer, UINT32 frames)
{
if(This->fmt->wBitsPerSample == 8)
memset(buf, 128, frames * This->fmt->nBlockAlign);
WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)This->fmt;
if((This->fmt->wFormatTag == WAVE_FORMAT_PCM ||
(This->fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))) &&
This->fmt->wBitsPerSample == 8)
memset(buffer, 128, frames * This->fmt->nBlockAlign);
else
memset(buf, 0, frames * This->fmt->nBlockAlign);
memset(buffer, 0, frames * This->fmt->nBlockAlign);
}
static void oss_write_data(ACImpl *This)
@ -1419,7 +1423,7 @@ static void oss_write_data(ACImpl *This)
to_write_bytes = to_write_frames * This->fmt->nBlockAlign;
if(This->session->mute)
oss_silence_buffer(This, buf, to_write_frames);
silence_buffer(This, buf, to_write_frames);
written_bytes = write(This->fd, buf, to_write_bytes);
if(written_bytes < 0){
@ -1445,7 +1449,7 @@ static void oss_write_data(ACImpl *This)
to_write_bytes = to_write_frames * This->fmt->nBlockAlign;
if(This->session->mute)
oss_silence_buffer(This, This->local_buffer, to_write_frames);
silence_buffer(This, This->local_buffer, to_write_frames);
written_bytes = write(This->fd, This->local_buffer, to_write_bytes);
if(written_bytes < 0){
@ -1846,6 +1850,8 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
This->getbuf_last = frames;
}
silence_buffer(This, *data, frames);
LeaveCriticalSection(&This->lock);
return S_OK;
@ -1902,7 +1908,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
buffer = This->tmp_buffer;
if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
oss_silence_buffer(This, buffer, written_frames);
silence_buffer(This, buffer, written_frames);
if(This->getbuf_last < 0)
oss_wrap_buffer(This, buffer, written_frames);