diff options
-rw-r--r-- | Alc/backends/alsa.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index d0677068..4b798b42 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -1128,11 +1128,12 @@ static void ALCcaptureAlsa_stop(ALCcaptureAlsa *self) void *ptr; size = snd_pcm_frames_to_bytes(self->pcmHandle, avail); - ptr = realloc(self->buffer, size); + ptr = malloc(size); if(ptr) { + ALCcaptureAlsa_captureSamples(self, ptr, avail); + free(self->buffer); self->buffer = ptr; - ALCcaptureAlsa_captureSamples(self, self->buffer, avail); self->size = size; } } @@ -1164,17 +1165,19 @@ static ALCenum ALCcaptureAlsa_captureSamples(ALCcaptureAlsa *self, ALCvoid *buff if((snd_pcm_uframes_t)amt > samples) amt = samples; amt = snd_pcm_frames_to_bytes(self->pcmHandle, amt); - memmove(buffer, self->buffer, amt); + memcpy(buffer, self->buffer, amt); if(self->size > amt) + { memmove(self->buffer, self->buffer+amt, self->size - amt); - else if(self->buffer != buffer) + self->size -= amt; + } + else { - /* Do not free the buffer if it's reading into itself. */ free(self->buffer); self->buffer = NULL; + self->size = 0; } - self->size -= amt; amt = snd_pcm_bytes_to_frames(self->pcmHandle, amt); } else if(self->doCapture) |