[PATCH v5] dsound: Commit next audio chunk between play cursor and write cursor to playing.

Andrew Eikum aeikum at codeweavers.com
Tue Sep 14 14:24:29 CDT 2021


On Tue, Sep 14, 2021 at 01:14:14PM +0300, Eduard Permyakov wrote:
> On 2021-09-13 6:49 p.m., Andrew Eikum wrote:
> > > On Fri, Sep 10, 2021 at 06:36:23PM +0300, Eduard Permyakov wrote:
> > > > diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c
> > > > index dc3b54906ce..63468732e1d 100644
> > > > --- a/dlls/dsound/buffer.c
> > > > +++ b/dlls/dsound/buffer.c
> > > > @@ -101,6 +101,24 @@ static int __cdecl notify_compar(const void *l, const void *r)
> > > >       return 1;
> > > >   }
> > > > +static void commit_next_chunk(IDirectSoundBufferImpl *dsb)
> > > > +{
> > > > +    void *dstbuff = dsb->committedbuff, *srcbuff = dsb->buffer->memory;
> > > > +    DWORD srcoff = dsb->sec_mixpos, srcsize = dsb->buflen, cpysize = dsb->writelead;
> > > > +
> > > > +    if(cpysize > srcsize - srcoff) {
> > > > +        DWORD overflow = cpysize - (srcsize - srcoff);
> > > > +        memcpy(dstbuff, (BYTE*)srcbuff + srcoff, srcsize - srcoff);
> > > > +        memcpy((BYTE*)dstbuff + (srcsize - srcoff), srcbuff, overflow);
> > > > +    }else{
> > > > +        memcpy(dstbuff, (BYTE*)srcbuff + srcoff, cpysize);
> > > > +    }
> > > > +
> > > > +    dsb->use_committed = TRUE;
> > > > +    dsb->committed_mixpos = 0;
> > > Is it right to always reset this to zero? Is it possible an app could
> > > write to the committed chunk while committed_mixpos is non-zero, and
> > > so reset committed_mixpos when it shouldn't be?
> 
> If the committed_mixpos is greater than 0 and less than dsb->writelead, this
> means
> that a previously committed chunk has not had time to be played completely.
> This
> essentially means that the app is overwriting a single buffer region in
> rapid succession.
> I think this is an extremely exotic case. Since there is only a fixed amount
> of space for
> the committed chunk, we would need to discard either part of the "old"
> committed
> chunk, or part of the "new" committed chunk. For simplicity of the code, I
> have kept
> it such that any part of the "old" committed chunk is discarded in such a
> case.
> 

My concern was more about resetting the value to zero than the audio
data which gets mixed. Won't that result in pulling too many samples
from the committed buffer if the application overwrites the buffer
while committed_mixpos is non-zero, because the value gets reset to
zero?  It's possible I missed something.

Andrew



More information about the wine-devel mailing list