ref: 37ee100e2f72daba5a1643c034728881ee03689e
parent: 29b91fbc8eb7f5f69c436d032fde05c0b133b3be
author: cbagwell <cbagwell>
date: Sun Feb 13 13:18:41 EST 2011
Further fixes to osx core audio driver
--- a/src/coreaudio.c
+++ b/src/coreaudio.c
@@ -29,10 +29,22 @@
sox_format_t *ft = (sox_format_t *)inClientData;
priv_t *ac = (priv_t *)ft->priv;
float *buf = outOutputData->mBuffers[0].mData;
+ int len;
+ /* mDataByteSize may be non-zero even when mData is NULL, but that is
+ * not an error.
+ */
+ if (buf == NULL)
+ return kAudioHardwareNoError;
+
+
pthread_mutex_lock(&ac->mutex);
- memcpy(buf, ac->buffer, ac->buf_offset);
+ len = ac->buf_offset;
+
+ memcpy(buf, ac->buffer, len);
+ outOutputData->mBuffers[0].mDataByteSize = len;
+
ac->buf_offset = 0;
pthread_mutex_unlock(&ac->mutex);
@@ -56,11 +68,13 @@
float *destbuf = (float *)((unsigned char *)ac->buffer + ac->buf_offset);
int i;
- /* mDataByteSize may be non-zero even when mData is NULL, but that is not an error */
+ /* mDataByteSize may be non-zero even when mData is NULL, but that is
+ * not an error.
+ */
if (buf == NULL)
return kAudioHardwareNoError;
- if (buflen > (ac->buf_size + ac->buf_offset))
+ if (buflen > (ac->buf_size - ac->buf_offset))
buflen = ac->buf_size - ac->buf_offset;
pthread_mutex_lock(&ac->mutex);
@@ -276,10 +290,7 @@
* buf_size is in bytes
*/
do {
- /* Wait until callback has cleared the buffer. We move in
- * lock-step with the callback; we never deal with a partially
- * written buffer. */
- while (ac->buf_offset != 0)
+ while (ac->buf_offset >= ac->buf_size)
pthread_cond_wait(&ac->cond, &ac->mutex);
len = nsamp - written;