Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix for non-power-of-2 output channels on mac
Index: src/hostapi/coreaudio/pa_mac_core_blocking.c
===================================================================
--- src/hostapi/coreaudio/pa_mac_core_blocking.c (revision 1948)
+++ src/hostapi/coreaudio/pa_mac_core_blocking.c (working copy)
@@ -186,7 +186,7 @@
err = PaUtil_InitializeRingBuffer(
&blio->outputRingBuffer,
- 1, ringBufferSize*blio->outputSampleSizePow2*outChan,
+ outChan*blio->outputSampleSizePow2, ringBufferSize,
data );
assert( !err );
}
@@ -268,9 +268,9 @@
if( blio->outputRingBuffer.buffer ) {
PaUtil_FlushRingBuffer( &blio->outputRingBuffer );
bzero( blio->outputRingBuffer.buffer,
- blio->outputRingBuffer.bufferSize );
+ blio->ringBufferFrames * blio->outputRingBuffer.elementSizeBytes );
/* Advance buffer */
- PaUtil_AdvanceRingBufferWriteIndex( &blio->outputRingBuffer, blio->ringBufferFrames*blio->outputSampleSizeActual*blio->outChan );
+ PaUtil_AdvanceRingBufferWriteIndex( &blio->outputRingBuffer, blio->ringBufferFrames);
//PaUtil_AdvanceRingBufferWriteIndex( &blio->outputRingBuffer, blio->outputRingBuffer.bufferSize );
/* Update isOutputFull. */
@@ -380,14 +380,14 @@
avail = PaUtil_GetRingBufferReadAvailable( &blio->outputRingBuffer );
/* check for underflow */
- if( avail < frameCount * blio->outputSampleSizeActual * blio->outChan )
+ if( avail < frameCount)
OSAtomicOr32( paOutputUnderflow, &blio->statusFlags );
- toWrite = MIN( avail, frameCount * blio->outputSampleSizeActual * blio->outChan );
+ toWrite = MIN( avail, frameCount);
- if( toWrite != frameCount * blio->outputSampleSizeActual * blio->outChan )
+ if( toWrite != frameCount)
bzero( ((char *)output)+toWrite,
- frameCount * blio->outputSampleSizeActual * blio->outChan - toWrite );
+ frameCount * 1 - toWrite );
/* copy the data */
/*printf( "writing %d\n", toWrite );*/
written = PaUtil_ReadRingBuffer( &blio->outputRingBuffer, output, toWrite );
@@ -520,11 +520,10 @@
}
} while( avail == 0 );
- toWrite = MIN( avail, frames * blio->outputSampleSizeActual * blio->outChan );
- toWrite -= toWrite % blio->outputSampleSizeActual * blio->outChan ;
+ toWrite = MIN( avail, frames );
PaUtil_WriteRingBuffer( &blio->outputRingBuffer, (void *)cbuf, toWrite );
cbuf += toWrite;
- frames -= toWrite / ( blio->outputSampleSizeActual * blio->outChan );
+ frames -= toWrite / 1;
#ifdef PA_MAC_BLIO_MUTEX
if( toWrite == avail ) {
@@ -587,7 +586,6 @@
PaMacBlio *blio = & ((PaMacCoreStream*)stream) -> blio;
VVDBUG(("GetStreamWriteAvailable()\n"));
- return PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer )
- / ( blio->outputSampleSizeActual * blio->outChan );
+ return PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment