1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00

Added an upper threshold that must be crossed before a lower threshold warning is communicated.

This commit is contained in:
Thomas Harte 2016-10-18 22:21:34 -04:00
parent ca28e3c64e
commit 5a808d789a

View File

@ -15,6 +15,7 @@
{ {
AudioQueueRef _audioQueue; AudioQueueRef _audioQueue;
size_t _queuedSamples; size_t _queuedSamples;
BOOL _hasHad256;
} }
#pragma mark - AudioQueue callbacks #pragma mark - AudioQueue callbacks
@ -22,7 +23,11 @@
- (void)audioQueue:(AudioQueueRef)theAudioQueue didCallbackWithBuffer:(AudioQueueBufferRef)buffer - (void)audioQueue:(AudioQueueRef)theAudioQueue didCallbackWithBuffer:(AudioQueueBufferRef)buffer
{ {
size_t samplesInBuffer = (size_t)(buffer->mAudioDataByteSize / sizeof(int16_t)); 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; _queuedSamples -= samplesInBuffer;
AudioQueueFreeBuffer(_audioQueue, buffer); AudioQueueFreeBuffer(_audioQueue, buffer);
@ -102,6 +107,7 @@ static void audioOutputCallback(
AudioQueueBufferRef newBuffer; AudioQueueBufferRef newBuffer;
size_t bufferBytes = lengthInSamples * sizeof(int16_t); size_t bufferBytes = lengthInSamples * sizeof(int16_t);
_queuedSamples += lengthInSamples; _queuedSamples += lengthInSamples;
_hasHad256 |= (_queuedSamples >= 256);
AudioQueueAllocateBuffer(_audioQueue, (UInt32)bufferBytes, &newBuffer); AudioQueueAllocateBuffer(_audioQueue, (UInt32)bufferBytes, &newBuffer);
memcpy(newBuffer->mAudioData, buffer, bufferBytes); memcpy(newBuffer->mAudioData, buffer, bufferBytes);