From 5a808d789ac9901fce2d0651242138562bdad3fa Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 18 Oct 2016 22:21:34 -0400 Subject: [PATCH] Added an upper threshold that must be crossed before a lower threshold warning is communicated. --- OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m b/OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m index 2e1ef29e1..a99fdf3b5 100644 --- a/OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m +++ b/OSBindings/Mac/Clock Signal/Audio/CSAudioQueue.m @@ -15,6 +15,7 @@ { AudioQueueRef _audioQueue; size_t _queuedSamples; + BOOL _hasHad256; } #pragma mark - AudioQueue callbacks @@ -22,7 +23,11 @@ - (void)audioQueue:(AudioQueueRef)theAudioQueue didCallbackWithBuffer:(AudioQueueBufferRef)buffer { size_t samplesInBuffer = (size_t)(buffer->mAudioDataByteSize / sizeof(int16_t)); - if(_queuedSamples >= 128 && _queuedSamples - samplesInBuffer < 128) [self.delegate audioQueueIsRunningDry:self]; + if(_queuedSamples >= 128 && _queuedSamples - samplesInBuffer < 128 && _hasHad256) + { + _hasHad256 = NO; + [self.delegate audioQueueIsRunningDry:self]; + } _queuedSamples -= samplesInBuffer; AudioQueueFreeBuffer(_audioQueue, buffer); @@ -102,6 +107,7 @@ static void audioOutputCallback( AudioQueueBufferRef newBuffer; size_t bufferBytes = lengthInSamples * sizeof(int16_t); _queuedSamples += lengthInSamples; + _hasHad256 |= (_queuedSamples >= 256); AudioQueueAllocateBuffer(_audioQueue, (UInt32)bufferBytes, &newBuffer); memcpy(newBuffer->mAudioData, buffer, bufferBytes);