mmdevapi: Fill buffer with silence in IAudioRenderClient::GetBuffer.
This commit is contained in:
parent
8c97327da6
commit
a5975bb601
|
@ -692,8 +692,8 @@ static void test_padding(void)
|
||||||
IAudioRenderClient *arc;
|
IAudioRenderClient *arc;
|
||||||
WAVEFORMATEX *pwfx;
|
WAVEFORMATEX *pwfx;
|
||||||
REFERENCE_TIME minp, defp;
|
REFERENCE_TIME minp, defp;
|
||||||
BYTE *buf;
|
BYTE *buf, silence;
|
||||||
UINT32 psize, pad, written;
|
UINT32 psize, pad, written, i;
|
||||||
|
|
||||||
hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
|
hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_INPROC_SERVER,
|
||||||
NULL, (void**)&ac);
|
NULL, (void**)&ac);
|
||||||
|
@ -712,6 +712,11 @@ static void test_padding(void)
|
||||||
if(hr != S_OK)
|
if(hr != S_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(pwfx->wBitsPerSample == 8)
|
||||||
|
silence = 128;
|
||||||
|
else
|
||||||
|
silence = 0;
|
||||||
|
|
||||||
/** GetDevicePeriod
|
/** GetDevicePeriod
|
||||||
* Default (= shared) device period is 10ms (e.g. 441 frames at 44100),
|
* Default (= shared) device period is 10ms (e.g. 441 frames at 44100),
|
||||||
* except when the HW/OS forces a particular alignment,
|
* except when the HW/OS forces a particular alignment,
|
||||||
|
@ -738,6 +743,12 @@ static void test_padding(void)
|
||||||
hr = IAudioRenderClient_GetBuffer(arc, psize, &buf);
|
hr = IAudioRenderClient_GetBuffer(arc, psize, &buf);
|
||||||
ok(hr == S_OK, "GetBuffer failed: %08x\n", hr);
|
ok(hr == S_OK, "GetBuffer failed: %08x\n", hr);
|
||||||
ok(buf != NULL, "NULL buffer returned\n");
|
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);
|
hr = IAudioRenderClient_GetBuffer(arc, 0, &buf);
|
||||||
ok(hr == AUDCLNT_E_OUT_OF_ORDER, "GetBuffer 0 size failed: %08x\n", hr);
|
ok(hr == AUDCLNT_E_OUT_OF_ORDER, "GetBuffer 0 size failed: %08x\n", hr);
|
||||||
|
|
|
@ -2466,6 +2466,18 @@ static ULONG WINAPI AudioRenderClient_Release(IAudioRenderClient *iface)
|
||||||
return AudioClient_Release(&This->IAudioClient_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,
|
static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
|
||||||
UINT32 frames, BYTE **data)
|
UINT32 frames, BYTE **data)
|
||||||
{
|
{
|
||||||
|
@ -2515,6 +2527,8 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
|
||||||
This->getbuf_last = frames;
|
This->getbuf_last = frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
silence_buffer(This, *data, frames);
|
||||||
|
|
||||||
LeaveCriticalSection(&This->lock);
|
LeaveCriticalSection(&This->lock);
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
@ -2568,12 +2582,8 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
|
||||||
else
|
else
|
||||||
buffer = This->tmp_buffer;
|
buffer = This->tmp_buffer;
|
||||||
|
|
||||||
if(flags & AUDCLNT_BUFFERFLAGS_SILENT){
|
if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
|
||||||
if(This->fmt->wBitsPerSample == 8)
|
silence_buffer(This, buffer, written_frames);
|
||||||
memset(buffer, 128, written_frames * This->fmt->nBlockAlign);
|
|
||||||
else
|
|
||||||
memset(buffer, 0, written_frames * This->fmt->nBlockAlign);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(This->getbuf_last < 0)
|
if(This->getbuf_last < 0)
|
||||||
alsa_wrap_buffer(This, buffer, written_frames);
|
alsa_wrap_buffer(This, buffer, written_frames);
|
||||||
|
|
|
@ -2024,6 +2024,18 @@ static ULONG WINAPI AudioRenderClient_Release(IAudioRenderClient *iface)
|
||||||
return AudioClient_Release(&This->IAudioClient_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,
|
static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
|
||||||
UINT32 frames, BYTE **data)
|
UINT32 frames, BYTE **data)
|
||||||
{
|
{
|
||||||
|
@ -2094,6 +2106,7 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
|
||||||
|
|
||||||
This->getbuf_last = frames;
|
This->getbuf_last = frames;
|
||||||
*data = This->public_buffer->mAudioData;
|
*data = This->public_buffer->mAudioData;
|
||||||
|
silence_buffer(This, *data, frames);
|
||||||
|
|
||||||
OSSpinLockUnlock(&This->lock);
|
OSSpinLockUnlock(&This->lock);
|
||||||
|
|
||||||
|
@ -2133,18 +2146,8 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
|
||||||
return AUDCLNT_E_INVALID_SIZE;
|
return AUDCLNT_E_INVALID_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flags & AUDCLNT_BUFFERFLAGS_SILENT){
|
if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
|
||||||
WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)This->fmt;
|
silence_buffer(This, This->public_buffer->mAudioData, frames);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
This->public_buffer->mAudioDataByteSize = frames * This->fmt->nBlockAlign;
|
This->public_buffer->mAudioDataByteSize = frames * This->fmt->nBlockAlign;
|
||||||
|
|
||||||
|
|
|
@ -1367,12 +1367,16 @@ static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient *iface,
|
||||||
return S_OK;
|
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)
|
WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)This->fmt;
|
||||||
memset(buf, 128, frames * This->fmt->nBlockAlign);
|
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
|
else
|
||||||
memset(buf, 0, frames * This->fmt->nBlockAlign);
|
memset(buffer, 0, frames * This->fmt->nBlockAlign);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void oss_write_data(ACImpl *This)
|
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;
|
to_write_bytes = to_write_frames * This->fmt->nBlockAlign;
|
||||||
|
|
||||||
if(This->session->mute)
|
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);
|
written_bytes = write(This->fd, buf, to_write_bytes);
|
||||||
if(written_bytes < 0){
|
if(written_bytes < 0){
|
||||||
|
@ -1445,7 +1449,7 @@ static void oss_write_data(ACImpl *This)
|
||||||
to_write_bytes = to_write_frames * This->fmt->nBlockAlign;
|
to_write_bytes = to_write_frames * This->fmt->nBlockAlign;
|
||||||
|
|
||||||
if(This->session->mute)
|
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);
|
written_bytes = write(This->fd, This->local_buffer, to_write_bytes);
|
||||||
if(written_bytes < 0){
|
if(written_bytes < 0){
|
||||||
|
@ -1846,6 +1850,8 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
|
||||||
This->getbuf_last = frames;
|
This->getbuf_last = frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
silence_buffer(This, *data, frames);
|
||||||
|
|
||||||
LeaveCriticalSection(&This->lock);
|
LeaveCriticalSection(&This->lock);
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
@ -1902,7 +1908,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
|
||||||
buffer = This->tmp_buffer;
|
buffer = This->tmp_buffer;
|
||||||
|
|
||||||
if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
|
if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
|
||||||
oss_silence_buffer(This, buffer, written_frames);
|
silence_buffer(This, buffer, written_frames);
|
||||||
|
|
||||||
if(This->getbuf_last < 0)
|
if(This->getbuf_last < 0)
|
||||||
oss_wrap_buffer(This, buffer, written_frames);
|
oss_wrap_buffer(This, buffer, written_frames);
|
||||||
|
|
Loading…
Reference in New Issue