mmdevapi: Do not mix frames and bytes.

This commit is contained in:
Jörg Höhle 2011-08-09 21:29:00 +02:00 committed by Alexandre Julliard
parent 74566422c7
commit abf5b64f4c
2 changed files with 8 additions and 8 deletions

View File

@ -1994,15 +1994,16 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
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 =
(This->lcl_offs_frames + This->held_frames) % This->bufsize_frames;
UINT32 write_offs_bytes = write_offs_frames * This->fmt->nBlockAlign;
snd_pcm_uframes_t chunk_frames = This->bufsize_frames - write_offs_frames;
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);
}else{
memcpy(This->local_buffer + write_offs_bytes, buffer, chunk_bytes);
@ -2015,7 +2016,6 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
IAudioRenderClient *iface, UINT32 written_frames, DWORD flags)
{
ACImpl *This = impl_from_IAudioRenderClient(iface);
UINT32 written_bytes = written_frames * This->fmt->nBlockAlign;
BYTE *buffer;
HRESULT hr;
@ -2048,7 +2048,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
if(This->held_frames){
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;
}else{

View File

@ -1625,15 +1625,16 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
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 =
(This->lcl_offs_frames + This->held_frames) % This->bufsize_frames;
UINT32 write_offs_bytes = write_offs_frames * This->fmt->nBlockAlign;
UINT32 chunk_frames = This->bufsize_frames - write_offs_frames;
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);
}else{
memcpy(This->local_buffer + write_offs_bytes, buffer, chunk_bytes);
@ -1647,7 +1648,6 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
{
ACImpl *This = impl_from_IAudioRenderClient(iface);
BYTE *buffer;
UINT32 written_bytes = written_frames * This->fmt->nBlockAlign;
TRACE("(%p)->(%u, %x)\n", This, written_frames, flags);
@ -1670,7 +1670,7 @@ static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
if(This->held_frames){
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;
}else{