mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-10 08:31:34 +00:00
Marginally reformats for current style.
This commit is contained in:
parent
f02989649c
commit
d751b7e2cb
@ -25,8 +25,7 @@ static NSLock *CSAudioQueueDeallocLock;
|
|||||||
@implementation CSWeakAudioQueuePointer
|
@implementation CSWeakAudioQueuePointer
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation CSAudioQueue
|
@implementation CSAudioQueue {
|
||||||
{
|
|
||||||
AudioQueueRef _audioQueue;
|
AudioQueueRef _audioQueue;
|
||||||
AudioQueueBufferRef _storedBuffers[NumberOfStoredAudioQueueBuffer];
|
AudioQueueBufferRef _storedBuffers[NumberOfStoredAudioQueueBuffer];
|
||||||
NSLock *_storedBuffersLock;
|
NSLock *_storedBuffersLock;
|
||||||
@ -38,13 +37,10 @@ static NSLock *CSAudioQueueDeallocLock;
|
|||||||
/*!
|
/*!
|
||||||
@returns @c YES if the queue is running dry; @c NO otherwise.
|
@returns @c YES if the queue is running dry; @c NO otherwise.
|
||||||
*/
|
*/
|
||||||
- (BOOL)audioQueue:(AudioQueueRef)theAudioQueue didCallbackWithBuffer:(AudioQueueBufferRef)buffer
|
- (BOOL)audioQueue:(AudioQueueRef)theAudioQueue didCallbackWithBuffer:(AudioQueueBufferRef)buffer {
|
||||||
{
|
|
||||||
[_storedBuffersLock lock];
|
[_storedBuffersLock lock];
|
||||||
for(int c = 0; c < NumberOfStoredAudioQueueBuffer; c++)
|
for(int c = 0; c < NumberOfStoredAudioQueueBuffer; c++) {
|
||||||
{
|
if(!_storedBuffers[c] || buffer->mAudioDataBytesCapacity > _storedBuffers[c]->mAudioDataBytesCapacity) {
|
||||||
if(!_storedBuffers[c] || buffer->mAudioDataBytesCapacity > _storedBuffers[c]->mAudioDataBytesCapacity)
|
|
||||||
{
|
|
||||||
if(_storedBuffers[c]) AudioQueueFreeBuffer(_audioQueue, _storedBuffers[c]);
|
if(_storedBuffers[c]) AudioQueueFreeBuffer(_audioQueue, _storedBuffers[c]);
|
||||||
_storedBuffers[c] = buffer;
|
_storedBuffers[c] = buffer;
|
||||||
[_storedBuffersLock unlock];
|
[_storedBuffersLock unlock];
|
||||||
@ -59,12 +55,10 @@ static NSLock *CSAudioQueueDeallocLock;
|
|||||||
static void audioOutputCallback(
|
static void audioOutputCallback(
|
||||||
void *inUserData,
|
void *inUserData,
|
||||||
AudioQueueRef inAQ,
|
AudioQueueRef inAQ,
|
||||||
AudioQueueBufferRef inBuffer)
|
AudioQueueBufferRef inBuffer) {
|
||||||
{
|
|
||||||
// Pull the delegate call for audio queue running dry outside of the locked region, to allow non-deadlocking
|
// Pull the delegate call for audio queue running dry outside of the locked region, to allow non-deadlocking
|
||||||
// lifecycle -dealloc events to result from it.
|
// lifecycle -dealloc events to result from it.
|
||||||
if([CSAudioQueueDeallocLock tryLock])
|
if([CSAudioQueueDeallocLock tryLock]) {
|
||||||
{
|
|
||||||
CSAudioQueue *queue = ((__bridge CSWeakAudioQueuePointer *)inUserData).queue;
|
CSAudioQueue *queue = ((__bridge CSWeakAudioQueuePointer *)inUserData).queue;
|
||||||
BOOL isRunningDry = NO;
|
BOOL isRunningDry = NO;
|
||||||
isRunningDry = [queue audioQueue:inAQ didCallbackWithBuffer:inBuffer];
|
isRunningDry = [queue audioQueue:inAQ didCallbackWithBuffer:inBuffer];
|
||||||
@ -76,14 +70,11 @@ static void audioOutputCallback(
|
|||||||
|
|
||||||
#pragma mark - Standard object lifecycle
|
#pragma mark - Standard object lifecycle
|
||||||
|
|
||||||
- (instancetype)initWithSamplingRate:(Float64)samplingRate
|
- (instancetype)initWithSamplingRate:(Float64)samplingRate {
|
||||||
{
|
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
if(self)
|
if(self) {
|
||||||
{
|
if(!CSAudioQueueDeallocLock) {
|
||||||
if(!CSAudioQueueDeallocLock)
|
|
||||||
{
|
|
||||||
CSAudioQueueDeallocLock = [[NSLock alloc] init];
|
CSAudioQueueDeallocLock = [[NSLock alloc] init];
|
||||||
}
|
}
|
||||||
_storedBuffersLock = [[NSLock alloc] init];
|
_storedBuffersLock = [[NSLock alloc] init];
|
||||||
@ -122,8 +113,7 @@ static void audioOutputCallback(
|
|||||||
NULL,
|
NULL,
|
||||||
kCFRunLoopCommonModes,
|
kCFRunLoopCommonModes,
|
||||||
0,
|
0,
|
||||||
&_audioQueue))
|
&_audioQueue)) {
|
||||||
{
|
|
||||||
AudioQueueStart(_audioQueue, NULL);
|
AudioQueueStart(_audioQueue, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,16 +121,13 @@ static void audioOutputCallback(
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init {
|
||||||
{
|
|
||||||
return [self initWithSamplingRate:[[self class] preferredSamplingRate]];
|
return [self initWithSamplingRate:[[self class] preferredSamplingRate]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
[CSAudioQueueDeallocLock lock];
|
[CSAudioQueueDeallocLock lock];
|
||||||
if(_audioQueue)
|
if(_audioQueue) {
|
||||||
{
|
|
||||||
AudioQueueDispose(_audioQueue, true);
|
AudioQueueDispose(_audioQueue, true);
|
||||||
_audioQueue = NULL;
|
_audioQueue = NULL;
|
||||||
}
|
}
|
||||||
@ -167,15 +154,12 @@ static void audioOutputCallback(
|
|||||||
|
|
||||||
#pragma mark - Audio enqueuer
|
#pragma mark - Audio enqueuer
|
||||||
|
|
||||||
- (void)enqueueAudioBuffer:(const int16_t *)buffer numberOfSamples:(size_t)lengthInSamples
|
- (void)enqueueAudioBuffer:(const int16_t *)buffer numberOfSamples:(size_t)lengthInSamples {
|
||||||
{
|
|
||||||
size_t bufferBytes = lengthInSamples * sizeof(int16_t);
|
size_t bufferBytes = lengthInSamples * sizeof(int16_t);
|
||||||
|
|
||||||
[_storedBuffersLock lock];
|
[_storedBuffersLock lock];
|
||||||
for(int c = 0; c < NumberOfStoredAudioQueueBuffer; c++)
|
for(int c = 0; c < NumberOfStoredAudioQueueBuffer; c++) {
|
||||||
{
|
if(_storedBuffers[c] && _storedBuffers[c]->mAudioDataBytesCapacity >= bufferBytes) {
|
||||||
if(_storedBuffers[c] && _storedBuffers[c]->mAudioDataBytesCapacity >= bufferBytes)
|
|
||||||
{
|
|
||||||
memcpy(_storedBuffers[c]->mAudioData, buffer, bufferBytes);
|
memcpy(_storedBuffers[c]->mAudioData, buffer, bufferBytes);
|
||||||
_storedBuffers[c]->mAudioDataByteSize = (UInt32)bufferBytes;
|
_storedBuffers[c]->mAudioDataByteSize = (UInt32)bufferBytes;
|
||||||
|
|
||||||
@ -197,8 +181,7 @@ static void audioOutputCallback(
|
|||||||
|
|
||||||
#pragma mark - Sampling Rate getters
|
#pragma mark - Sampling Rate getters
|
||||||
|
|
||||||
+ (AudioDeviceID)defaultOutputDevice
|
+ (AudioDeviceID)defaultOutputDevice {
|
||||||
{
|
|
||||||
AudioObjectPropertyAddress address;
|
AudioObjectPropertyAddress address;
|
||||||
address.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
address.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
|
||||||
address.mScope = kAudioObjectPropertyScopeGlobal;
|
address.mScope = kAudioObjectPropertyScopeGlobal;
|
||||||
@ -209,8 +192,7 @@ static void audioOutputCallback(
|
|||||||
return AudioObjectGetPropertyData(kAudioObjectSystemObject, &address, sizeof(AudioObjectPropertyAddress), NULL, &size, &deviceID) ? 0 : deviceID;
|
return AudioObjectGetPropertyData(kAudioObjectSystemObject, &address, sizeof(AudioObjectPropertyAddress), NULL, &size, &deviceID) ? 0 : deviceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (Float64)preferredSamplingRate
|
+ (Float64)preferredSamplingRate {
|
||||||
{
|
|
||||||
AudioObjectPropertyAddress address;
|
AudioObjectPropertyAddress address;
|
||||||
address.mSelector = kAudioDevicePropertyNominalSampleRate;
|
address.mSelector = kAudioDevicePropertyNominalSampleRate;
|
||||||
address.mScope = kAudioObjectPropertyScopeGlobal;
|
address.mScope = kAudioObjectPropertyScopeGlobal;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user