]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Fix wrong offset calculation in snd_pcm_{read|write}_mmap()
authorTakashi Iwai <tiwai@suse.de>
Thu, 20 Sep 2007 11:20:03 +0000 (13:20 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 20 Sep 2007 11:20:03 +0000 (13:20 +0200)
The offset used in snd_pcm_{read|write}_mmap() is not the linear offset
but the offset in a ring buffer.  It has to be rounded.

src/pcm/pcm_mmap.c

index d07a0806898eddc4bfe8e423c4bce9bc519b4183..4621fe6f0955832d0f057ebe80d015a7483f4cc6 100644 (file)
@@ -575,7 +575,7 @@ snd_pcm_sframes_t snd_pcm_write_mmap(snd_pcm_t *pcm, snd_pcm_uframes_t offset,
                if (err < 0)
                        break;
                xfer += frames;
-               offset += frames;
+               offset = (offset + frames) % pcm->buffer_size;
        }
        if (xfer > 0)
                return xfer;
@@ -625,7 +625,7 @@ snd_pcm_sframes_t snd_pcm_read_mmap(snd_pcm_t *pcm, snd_pcm_uframes_t offset,
                if (err < 0)
                        break;
                xfer += frames;
-               offset += frames;
+               offset = (offset + frames) % pcm->buffer_size;
        }
        if (xfer > 0)
                return xfer;