diff --git a/TheAmazingAudioEngine/Renderers/AERenderer.m b/TheAmazingAudioEngine/Renderers/AERenderer.m index f2516c2..e3297ce 100644 --- a/TheAmazingAudioEngine/Renderers/AERenderer.m +++ b/TheAmazingAudioEngine/Renderers/AERenderer.m @@ -27,6 +27,7 @@ #import "AERenderer.h" #import "AETypes.h" #import "AEManagedValue.h" +#import "AEDSPUtilities.h" NSString * const AERendererDidChangeSampleRateNotification = @"AERendererDidChangeSampleRateNotification"; NSString * const AERendererDidChangeChannelCountNotification = @"AERendererDidChangeChannelCountNotification"; @@ -56,9 +57,7 @@ void AERendererRun(__unsafe_unretained AERenderer * THIS, AudioBufferList * buff AEBufferStackSetFrameCount(THIS->_stack, frames); // Clear the output buffer - for ( int i=0; imNumberBuffers; i++ ) { - memset(bufferList->mBuffers[i].mData, 0, frames * AEAudioDescription.mBytesPerFrame); - } + AEDSPClearBufferList(bufferList, frames); // Run the block __unsafe_unretained AERenderLoopBlock block = (__bridge AERenderLoopBlock)AEManagedValueGetValue(THIS->_blockValue); diff --git a/TheAmazingAudioEngine/Utilities/AEDSPUtilities.h b/TheAmazingAudioEngine/Utilities/AEDSPUtilities.h index b99dbac..3f949e7 100644 --- a/TheAmazingAudioEngine/Utilities/AEDSPUtilities.h +++ b/TheAmazingAudioEngine/Utilities/AEDSPUtilities.h @@ -31,6 +31,25 @@ extern "C" { #endif +/* + Clear buffers in AudioBufferList using AEDSPClearAudioBuffer + + @param listPtr Pointer to AudioBufferList struct + @param frameCount Number of frames to clear in each AudioBuffer +*/ +void AEDSPClearBufferList(AudioBufferList *listPtr, UInt32 frameCount); + + +/* + Clear buffer to zero using vDSP_vclr and set mDataByteSize accordingly + + @param bufferPtr Pointer to AudioBuffer struct + @param frameCount Number of frames to clear, + mDataByteSize field will be set accordingly +*/ +void AEDSPClearAudioBuffer(AudioBuffer *bufferPtr, UInt32 frameCount); + + /*! * Scale values in a buffer list by some gain value * diff --git a/TheAmazingAudioEngine/Utilities/AEDSPUtilities.m b/TheAmazingAudioEngine/Utilities/AEDSPUtilities.m index 486b7a5..a0d13d8 100644 --- a/TheAmazingAudioEngine/Utilities/AEDSPUtilities.m +++ b/TheAmazingAudioEngine/Utilities/AEDSPUtilities.m @@ -9,6 +9,19 @@ #import "AEDSPUtilities.h" @import Accelerate; +void AEDSPClearBufferList(AudioBufferList *listPtr, UInt32 frameCount) +{ + for (UInt32 n = listPtr->mNumberBuffers; n != 0;) + { AEDSPClearAudioBuffer(&listPtr->mBuffers[(n-=1)], frameCount); } +} + +void AEDSPClearAudioBuffer(AudioBuffer *buffer, UInt32 frameCount) +{ + buffer->mDataByteSize = buffer->mNumberChannels * frameCount * sizeof(float); + vDSP_vclr(buffer->mData, 1, frameCount); +} + + static const UInt32 kGainSmoothingRampDuration = 128; static const float kGainSmoothingRampStep = 1.0 / kGainSmoothingRampDuration; static const float kSmoothGainThreshold = kGainSmoothingRampStep;