Commit abf5b64f authored by Jörg Höhle's avatar Jörg Höhle Committed by Alexandre Julliard

mmdevapi: Do not mix frames and bytes.

parent 74566422
...@@ -1994,15 +1994,16 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, ...@@ -1994,15 +1994,16 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
return S_OK; return S_OK;
} }
static void alsa_wrap_buffer(ACImpl *This, BYTE *buffer, UINT32 written_bytes) static void alsa_wrap_buffer(ACImpl *This, BYTE *buffer, UINT32 written_frames)
{ {
snd_pcm_uframes_t write_offs_frames = snd_pcm_uframes_t write_offs_frames =
(This->lcl_offs_frames + This->held_frames) % This->bufsize_frames; (This->lcl_offs_frames + This->held_frames) % This->bufsize_frames;
UINT32 write_offs_bytes = write_offs_frames * This->fmt->nBlockAlign; UINT32 write_offs_bytes = write_offs_frames * This->fmt->nBlockAlign;
snd_pcm_uframes_t chunk_frames = This->bufsize_frames - write_offs_frames; snd_pcm_uframes_t chunk_frames = This->bufsize_frames - write_offs_frames;
UINT32 chunk_bytes = chunk_frames * This->fmt->nBlockAlign; UINT32 chunk_bytes = chunk_frames * This->fmt->nBlockAlign;
UINT32 written_bytes = written_frames * This->fmt->nBlockAlign;
if(written_bytes < chunk_bytes){ if(written_bytes <= chunk_bytes){
memcpy(This->local_buffer + write_offs_bytes, buffer, written_bytes); memcpy(This->local_buffer + write_offs_bytes, buffer, written_bytes);
}else{ }else{
memcpy(This->local_buffer + write_offs_bytes, buffer, chunk_bytes); memcpy(This->local_buffer + write_offs_bytes, buffer, chunk_bytes);
...@@ -2015,7 +2016,6 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( ...@@ -2015,7 +2016,6 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
IAudioRenderClient *iface, UINT32 written_frames, DWORD flags) IAudioRenderClient *iface, UINT32 written_frames, DWORD flags)
{ {
ACImpl *This = impl_from_IAudioRenderClient(iface); ACImpl *This = impl_from_IAudioRenderClient(iface);
UINT32 written_bytes = written_frames * This->fmt->nBlockAlign;
BYTE *buffer; BYTE *buffer;
HRESULT hr; HRESULT hr;
...@@ -2048,7 +2048,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( ...@@ -2048,7 +2048,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
if(This->held_frames){ if(This->held_frames){
if(This->buf_state == LOCKED_WRAPPED) if(This->buf_state == LOCKED_WRAPPED)
alsa_wrap_buffer(This, buffer, written_bytes); alsa_wrap_buffer(This, buffer, written_frames);
This->held_frames += written_frames; This->held_frames += written_frames;
}else{ }else{
......
...@@ -1625,15 +1625,16 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, ...@@ -1625,15 +1625,16 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
return S_OK; return S_OK;
} }
static void oss_wrap_buffer(ACImpl *This, BYTE *buffer, UINT32 written_bytes) static void oss_wrap_buffer(ACImpl *This, BYTE *buffer, UINT32 written_frames)
{ {
UINT32 write_offs_frames = UINT32 write_offs_frames =
(This->lcl_offs_frames + This->held_frames) % This->bufsize_frames; (This->lcl_offs_frames + This->held_frames) % This->bufsize_frames;
UINT32 write_offs_bytes = write_offs_frames * This->fmt->nBlockAlign; UINT32 write_offs_bytes = write_offs_frames * This->fmt->nBlockAlign;
UINT32 chunk_frames = This->bufsize_frames - write_offs_frames; UINT32 chunk_frames = This->bufsize_frames - write_offs_frames;
UINT32 chunk_bytes = chunk_frames * This->fmt->nBlockAlign; UINT32 chunk_bytes = chunk_frames * This->fmt->nBlockAlign;
UINT32 written_bytes = written_frames * This->fmt->nBlockAlign;
if(written_bytes < chunk_bytes){ if(written_bytes <= chunk_bytes){
memcpy(This->local_buffer + write_offs_bytes, buffer, written_bytes); memcpy(This->local_buffer + write_offs_bytes, buffer, written_bytes);
}else{ }else{
memcpy(This->local_buffer + write_offs_bytes, buffer, chunk_bytes); memcpy(This->local_buffer + write_offs_bytes, buffer, chunk_bytes);
...@@ -1647,7 +1648,6 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( ...@@ -1647,7 +1648,6 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
{ {
ACImpl *This = impl_from_IAudioRenderClient(iface); ACImpl *This = impl_from_IAudioRenderClient(iface);
BYTE *buffer; BYTE *buffer;
UINT32 written_bytes = written_frames * This->fmt->nBlockAlign;
TRACE("(%p)->(%u, %x)\n", This, written_frames, flags); TRACE("(%p)->(%u, %x)\n", This, written_frames, flags);
...@@ -1670,7 +1670,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( ...@@ -1670,7 +1670,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
if(This->held_frames){ if(This->held_frames){
if(This->buf_state == LOCKED_WRAPPED) if(This->buf_state == LOCKED_WRAPPED)
oss_wrap_buffer(This, buffer, written_bytes); oss_wrap_buffer(This, buffer, written_frames);
This->held_frames += written_frames; This->held_frames += written_frames;
}else{ }else{
......
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