AEIOAudioUnit.h
Go to the documentation of this file.
1 //
2 // AEIOAudioUnit.h
3 // TheAmazingAudioEngine
4 //
5 // Created by Michael Tyson on 4/04/2016.
6 // Copyright © 2016 A Tasty Pixel. All rights reserved.
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source distribution.
25 //
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #import <Foundation/Foundation.h>
32 #import <AudioToolbox/AudioToolbox.h>
33 #import "AETime.h"
34 
45 typedef void (^AEIOAudioUnitRenderBlock)(AudioBufferList * _Nonnull ioData,
46  UInt32 frames,
47  const AudioTimeStamp * _Nonnull timestamp);
48 
56 extern NSString * const _Nonnull AEIOAudioUnitDidSetupNotification;
57 
65 extern NSString * const _Nonnull AEIOAudioUnitDidUpdateStreamFormatNotification;
66 
79 @interface AEIOAudioUnit : NSObject
80 
89 - (BOOL)setup:(NSError * __autoreleasing _Nullable * _Nullable)error;
90 
97 - (BOOL)start:(NSError * __autoreleasing _Nullable * _Nullable)error;
98 
102 - (void)stop;
103 
112 AudioUnit _Nullable AEIOAudioUnitGetAudioUnit(__unsafe_unretained AEIOAudioUnit * _Nonnull unit);
113 
124 OSStatus AEIOAudioUnitRenderInput(__unsafe_unretained AEIOAudioUnit * _Nonnull unit,
125  const AudioBufferList * _Nonnull buffer, UInt32 frames);
126 
136 AudioTimeStamp AEIOAudioUnitGetInputTimestamp(__unsafe_unretained AEIOAudioUnit * _Nonnull unit);
137 
147 double AEIOAudioUnitGetSampleRate(__unsafe_unretained AEIOAudioUnit * _Nonnull unit);
148 
149 #if TARGET_OS_IPHONE
150 
160 AESeconds AEIOAudioUnitGetInputLatency(__unsafe_unretained AEIOAudioUnit * _Nonnull unit);
161 
171 AESeconds AEIOAudioUnitGetOutputLatency(__unsafe_unretained AEIOAudioUnit * _Nonnull unit);
172 
173 #endif
174 
176 @property (nonatomic, readonly) AudioUnit _Nullable audioUnit;
177 
179 @property (nonatomic) double sampleRate;
180 
182 @property (nonatomic, readonly) double currentSampleRate;
183 
185 @property (nonatomic, readonly) BOOL running;
186 
189 @property (nonatomic) BOOL outputEnabled;
190 
192 @property (nonatomic, copy) AEIOAudioUnitRenderBlock _Nullable renderBlock;
193 
195 @property (nonatomic, readonly) int numberOfOutputChannels;
196 
199 @property (nonatomic) BOOL inputEnabled;
200 
203 @property (nonatomic) double inputGain;
204 
206 @property (nonatomic) int maximumInputChannels;
207 
209 @property (nonatomic, readonly) int numberOfInputChannels;
210 
213 @property (nonatomic) AESeconds IOBufferDuration;
214 
215 #if TARGET_OS_IPHONE
216 
218 @property (nonatomic) BOOL latencyCompensation;
219 
220 #endif
221 @end
222 
223 #ifdef __cplusplus
224 }
225 #endif