mirror of
https://github.com/TomHarte/CLK.git
synced 2024-09-08 18:55:14 +00:00
Started upon a delegate protocol for the AudioQueue, resolving my use of a deprecated API while I'm at it.
This commit is contained in:
parent
dbdd05afb8
commit
695dd2e9e3
@ -8,12 +8,19 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
@class AudioQueue;
|
||||||
|
|
||||||
|
@protocol AudioQueueDelegate
|
||||||
|
- (void)audioQueueDidCompleteBuffer:(nonnull AudioQueue *)audioQueue;
|
||||||
|
@end
|
||||||
|
|
||||||
@interface AudioQueue : NSObject
|
@interface AudioQueue : NSObject
|
||||||
|
|
||||||
- (instancetype)initWithSamplingRate:(Float64)samplingRate;
|
- (nonnull instancetype)initWithSamplingRate:(Float64)samplingRate;
|
||||||
- (void)enqueueAudioBuffer:(const int16_t *)buffer numberOfSamples:(size_t)lengthInSamples;
|
- (void)enqueueAudioBuffer:(nonnull const int16_t *)buffer numberOfSamples:(size_t)lengthInSamples;
|
||||||
|
|
||||||
@property (nonatomic, readonly) Float64 samplingRate;
|
@property (nonatomic, readonly) Float64 samplingRate;
|
||||||
|
@property (nonatomic, weak) id<AudioQueueDelegate> delegate;
|
||||||
|
|
||||||
+ (Float64)preferredSamplingRate;
|
+ (Float64)preferredSamplingRate;
|
||||||
|
|
||||||
|
@ -36,6 +36,8 @@ enum {
|
|||||||
|
|
||||||
- (void)audioQueue:(AudioQueueRef)theAudioQueue didCallbackWithBuffer:(AudioQueueBufferRef)buffer
|
- (void)audioQueue:(AudioQueueRef)theAudioQueue didCallbackWithBuffer:(AudioQueueBufferRef)buffer
|
||||||
{
|
{
|
||||||
|
[self.delegate audioQueueDidCompleteBuffer:self];
|
||||||
|
|
||||||
[_writeLock lock];
|
[_writeLock lock];
|
||||||
|
|
||||||
const unsigned int writeLead = _audioStreamWritePosition - _audioStreamReadPosition;
|
const unsigned int writeLead = _audioStreamWritePosition - _audioStreamReadPosition;
|
||||||
@ -95,7 +97,7 @@ static void audioOutputCallback(
|
|||||||
_samplingRate = samplingRate;
|
_samplingRate = samplingRate;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Describe a mono, 16bit, 44.1Khz audio format
|
Describe a mono 16bit stream of the requested sampling rate
|
||||||
*/
|
*/
|
||||||
AudioStreamBasicDescription outputDescription;
|
AudioStreamBasicDescription outputDescription;
|
||||||
|
|
||||||
@ -196,6 +198,8 @@ static void audioOutputCallback(
|
|||||||
return ((_audioStreamWritePosition - _audioStreamReadPosition) < (AudioQueueStreamLength - AudioQueueBufferLength)) ? AudioQueueCanProceed : AudioQueueWait;
|
return ((_audioStreamWritePosition - _audioStreamReadPosition) < (AudioQueueStreamLength - AudioQueueBufferLength)) ? AudioQueueCanProceed : AudioQueueWait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Sampling Rate getters
|
||||||
|
|
||||||
+ (AudioDeviceID)defaultOutputDevice
|
+ (AudioDeviceID)defaultOutputDevice
|
||||||
{
|
{
|
||||||
AudioObjectPropertyAddress address;
|
AudioObjectPropertyAddress address;
|
||||||
@ -205,7 +209,7 @@ static void audioOutputCallback(
|
|||||||
|
|
||||||
AudioDeviceID deviceID;
|
AudioDeviceID deviceID;
|
||||||
UInt32 size = sizeof(AudioDeviceID);
|
UInt32 size = sizeof(AudioDeviceID);
|
||||||
return AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &address, 0, NULL, &size, &deviceID) ? 0 : deviceID;
|
return AudioObjectGetPropertyData(kAudioObjectSystemObject, &address, sizeof(AudioObjectPropertyAddress), NULL, &size, &deviceID) ? 0 : deviceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (Float64)preferredSamplingRate
|
+ (Float64)preferredSamplingRate
|
||||||
@ -217,7 +221,7 @@ static void audioOutputCallback(
|
|||||||
|
|
||||||
Float64 samplingRate;
|
Float64 samplingRate;
|
||||||
UInt32 size = sizeof(Float64);
|
UInt32 size = sizeof(Float64);
|
||||||
return AudioHardwareServiceGetPropertyData([self defaultOutputDevice], &address, 0, NULL, &size, &samplingRate) ? 0.0 : samplingRate;
|
return AudioObjectGetPropertyData([self defaultOutputDevice], &address, sizeof(AudioObjectPropertyAddress), NULL, &size, &samplingRate) ? 0.0 : samplingRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
Reference in New Issue
Block a user