CARingBufferError CARingBuffer::Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime startRead) { SampleTime endRead = startRead + nFrames; SampleTime startRead0 = startRead; SampleTime endRead0 = endRead; CARingBufferError err = ClipTimeBounds(startRead, endRead); SampleTime readSizeFrames = endRead - startRead; if (err) { if ( readSizeFrames <= 0 ) { CARB_DEBUG( "POS1 read size frames too little. (%ld)\n", err ); return err; } } SInt32 destStartFrameOffset = startRead - startRead0; if ( destStartFrameOffset > 0 ) { CARB_DEBUG( "Fetch - Zeroing start bound\n" ); ZeroABL(abl, 0, destStartFrameOffset * mBytesPerFrame); } SInt32 destEndSize = endRead0 - endRead; if ( destEndSize > 0 ) { CARB_DEBUG( "Fetch - Zeroing end bound (%ld frames off)\n", destEndSize ); ZeroABL(abl, ( destStartFrameOffset + readSizeFrames ) * mBytesPerFrame, destEndSize * mBytesPerFrame); } Byte **buffers = mBuffers; int offset0 = FrameOffset(startRead); int offset1 = FrameOffset(endRead); int destStartByteOffset = destStartFrameOffset * mBytesPerFrame; int nbytes; if ( offset0 < offset1 ) { nbytes = offset1 - offset0; FetchABL( abl, destStartByteOffset , buffers, offset0, nbytes ); } else { nbytes = mCapacityBytes - offset0; FetchABL( abl, destStartByteOffset , buffers, offset0, nbytes ); FetchABL( abl, destStartByteOffset + nbytes, buffers, 0 , offset1 ); nbytes += offset1; } int nchannels = abl->mNumberBuffers; AudioBuffer *dest = abl->mBuffers; while (--nchannels >= 0) { dest->mDataByteSize = nbytes; dest++; } OSStatus err2 = ClipTimeBounds( startRead, endRead ); err2 = worse( err, err2 ); readSizeFrames = endRead - startRead; if ( err2 ) { if ( readSizeFrames <= 0 ) { CARB_DEBUG( "POS2 read size frames too little. (%ld)\n", err2 ); return err2; } } if ( err2 ) { CARB_DEBUG( "Returning error %ld.\n", err2 ); } return err2; }
CARingBufferError CARingBuffer::Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime startRead) { SampleTime endRead = startRead + nFrames; SampleTime startRead0 = startRead; SampleTime endRead0 = endRead; SampleTime size; CARingBufferError err = ClipTimeBounds(startRead, endRead); if (err) return err; size = endRead - startRead; SInt32 destStartOffset = startRead - startRead0; if(destStartOffset > nFrames) return kCARingBufferError_CPUOverload; if (destStartOffset > 0) { ZeroABL(abl, 0, destStartOffset * mBytesPerFrame); } SInt32 destEndSize = endRead0 - endRead; if (destEndSize > 0) { ZeroABL(abl, destStartOffset + size, destEndSize * mBytesPerFrame); } Byte **buffers = mBuffers; int offset0 = FrameOffset(startRead); int offset1 = FrameOffset(endRead); int nbytes; if (offset0 < offset1) { FetchABL(abl, destStartOffset, buffers, offset0, nbytes = offset1 - offset0); } else { nbytes = mCapacityBytes - offset0; FetchABL(abl, destStartOffset, buffers, offset0, nbytes); FetchABL(abl, destStartOffset + nbytes, buffers, 0, offset1); nbytes += offset1; } int nchannels = abl->mNumberBuffers; AudioBuffer *dest = abl->mBuffers; while (--nchannels >= 0) { dest->mDataByteSize = nbytes; dest++; } return noErr; }
FSTCARingBufferError FSTCARingBuffer::Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime startRead) { SampleTime endRead = startRead + nFrames; SampleTime startRead0 = startRead; SampleTime endRead0 = endRead; SampleTime size; FSTCARingBufferError err = ClipTimeBounds(startRead, endRead); if (err) return err; size = endRead - startRead; SInt32 idx, destStartOffset = startRead - startRead0; if(mBufferList) { for(idx=0; idx<mBufferList->mNumberBuffers; idx++) { AudioBuffer * storeBuf = &mBufferList->mBuffers[idx], * fetchBuf = &abl->mBuffers[idx]; mCapacityBytes = sizeof(float)*storeBuf->mNumberChannels * mCapacityFrames; if (destStartOffset > 0) { ZeroAB(fetchBuf, 0, destStartOffset * sizeof(float)*fetchBuf->mNumberChannels); } SInt32 destEndSize = endRead0 - endRead; if (destEndSize > 0) { ZeroAB(fetchBuf, (destStartOffset + size) * sizeof(float)*fetchBuf->mNumberChannels, destEndSize * sizeof(float)*fetchBuf->mNumberChannels); } int offset0 = startRead * sizeof(float) * storeBuf->mNumberChannels; int offset1 = endRead * sizeof(float) * storeBuf->mNumberChannels; int nbytes; if(offset0 == offset1 == 0) { nbytes = 0; } if (offset0 < offset1) { FetchAB(fetchBuf, destStartOffset, storeBuf, offset0, nbytes = offset1 - offset0); } else { nbytes = mCapacityBytes - offset0; FetchAB(fetchBuf, destStartOffset, storeBuf, offset0, nbytes); FetchAB(fetchBuf, destStartOffset + nbytes, storeBuf, 0, offset1); nbytes += offset1; } fetchBuf->mDataByteSize = nbytes; } } else { if (destStartOffset > 0) { ZeroABL(abl, 0, destStartOffset * mBytesPerFrame); } SInt32 destEndSize = endRead0 - endRead; if (destEndSize > 0) { ZeroABL(abl, destStartOffset + size, destEndSize * mBytesPerFrame); } Byte **buffers = mBuffers; int offset0 = FrameOffset(startRead); int offset1 = FrameOffset(endRead); int nbytes; if (offset0 < offset1) { FetchBufs(abl, destStartOffset, buffers, offset0, nbytes = offset1 - offset0); } else { nbytes = mCapacityBytes - offset0; FetchBufs(abl, destStartOffset, buffers, offset0, nbytes); FetchBufs(abl, destStartOffset + nbytes, buffers, 0, offset1); nbytes += offset1; } int nchannels = abl->mNumberBuffers; AudioBuffer *dest = abl->mBuffers; while (--nchannels >= 0) { dest->mDataByteSize = nbytes; dest++; } } return noErr; }