-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSuperpoweredIOSAudioOutput.h
176 lines (127 loc) · 7.37 KB
/
SuperpoweredIOSAudioOutput.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#import <AVFoundation/AVAudioSession.h>
struct multiRouteOutputChannelMap;
struct multiRouteInputChannelMap;
@protocol SuperpoweredIOSAudioIODelegate;
/**
@brief Handles all audio session, audio lifecycle (interruptions), output, buffer size, samplerate and routing headaches.
@warning All methods and setters should be called on the main thread only!
*/
@interface SuperpoweredIOSAudioOutput: NSObject {
int preferredBufferSizeSamples;
bool inputEnabled;
}
/** @brief The preferred buffer size. Should be 128, 256 or 512. */
@property (nonatomic, assign) int preferredBufferSizeSamples;
/** @brief Set this to true to enable audio input. Disabled by default. */
@property (nonatomic, assign) bool inputEnabled;
/**
@brief Creates the audio output instance.
@param delegate The object fully implementing the SuperpoweredIOSAudioIODelegate protocol. Not retained.
@param preferredBufferSize The initial value for preferredBufferSizeSamples. Should be 128, 256 or 512.
@param audioSessionCategory The audio session category. If you want to use MultiRoute, set it to AVAudioSessionCategoryPlayback, and set multiRouteChannels to more than 2. You don't loose the ability of AirPlay this way.
@param multiRouteChannels The number of channels you provide in the audio processing callback. Used in the MultiRoute category only.
@param fixReceiver Sometimes the audio goes to the phone's receiver ("ear speaker"). Set this to true if you want the real speaker instead.
@param float32 The canonical iOS audio format is "Apple 8.24". Set this to true if you want 32-bit floating point instead.
*/
- (id)initWithDelegate:(id<SuperpoweredIOSAudioIODelegate>)delegate preferredBufferSize:(unsigned int)preferredBufferSize audioSessionCategory:(NSString *)audioSessionCategory multiRouteChannels:(int)multiRouteChannels fixReceiver:(bool)fixReceiver float32:(bool)float32;
/**
@brief Starts audio processing.
@return True if successful, false if failed.
*/
- (bool)start;
/**
@brief Stops audio processing.
*/
- (void)stop;
/**
@brief Call this to re-configure the channel mapping for the MultiRoute category.
*/
- (void)multiRouteRemapChannels;
@end
/**
@brief You must implement this protocol to make SuperpoweredIOSAudioOutput work.
*/
@protocol SuperpoweredIOSAudioIODelegate
/**
@brief The audio session may be interrupted by a phone call, etc. This method is called on the main thread when audio resumes.
*/
- (void)interruptionEnded;
/**
@brief This method is called on the main thread, when you use the MultiRoute audio session category and a new audio device is connected or disconnected.
@param outputMap Map the output channels here.
@param inputMap Map the input channels here.
@param multiRouteDeviceName The name of the attached audio device, for example the model of the sound card.
@param outputsAndInputs A human readable description about the available outputs and inputs.
*/
- (void)multiRouteMapChannels:(multiRouteOutputChannelMap *)outputMap inputMap:(multiRouteInputChannelMap *)inputMap multiRouteDeviceName:(NSString *)multiRouteDeviceName outputsAndInputs:(NSString *)outputsAndInputs;
/**
@brief Process audio here.
@return Return false when you did no audio processing (silence).
@param buffers Input-output buffers.
@param inputChannels The number of input channels.
@param outputChannels The number of output channels.
@param numberOfSamples The number of samples requested.
@param samplerate The current sample rate in Hz.
@param hostTime A mach timestamp, indicates when this chunk of audio will be passed to the audio output.
@warning It's called on a high priority real-time audio thread, so please take care of blocking and processing time to prevent audio dropouts.
*/
- (bool)audioProcessingCallback:(void **)buffers inputChannels:(unsigned int)inputChannels outputChannels:(unsigned int)outputChannels numberOfSamples:(unsigned int)numberOfSamples samplerate:(unsigned int)samplerate hostTime:(UInt64)hostTime;
@end
/**
@brief Output channel mapping for the MultiRoute audio session category.
This structure maps the channels you provide in the audio processing callback to the appropriate output channels.
You can have more than a single stereo output with the MultiRoute audio session category, if a HDMI or USB audio device is connected (it doesn't work with other, such as wireless audio accessories).
@em Example:
Let's say you have four output channels, and you'd like the first stereo pair on USB 3+4, and the other stereo pair on the iPad's headphone socket.
1. Set deviceChannels[0] to 2, deviceChannels[1] to 3.
2. Set USBChannels[2] to 0, USBChannels[3] to 1.
@em Explanation:
- Your four output channels are having the identifiers: 0, 1, 2, 3.
- The iPad (and all other iOS device) has just a stereo built-in channel pair. This is represented by deviceChannels, and (1.) sets your second stereo pair (2, 3) to these.
- You other stereo pair (0, 1) is mapped to USBChannels. USBChannels[2] represents the third USB channel.
@since The MultiRoute category is available in iOS 6.0 and later.
@param deviceChannels The iOS device's built-in output channels.
@param HDMIChannels HDMI output channels.
@param USBChannels USB output channels.
@param numberOfHDMIChannelsAvailable Number of available HDMI output channels.
@param numberOfUSBChannelsAvailable Number of available USB output channels.
@param headphoneAvailable Something is plugged into the iOS device's headphone socket or not.
*/
typedef struct multiRouteOutputChannelMap {
int deviceChannels[2];
int HDMIChannels[8];
int USBChannels[32];
// READ ONLY information:
int numberOfHDMIChannelsAvailable, numberOfUSBChannelsAvailable;
bool headphoneAvailable;
} multiRouteOutputChannelMap;
/**
@brief Input channel mapping for the MultiRoute audio session category.
Similar to the output channels, you can map the input channels for the multiroute category. It works with USB only.
Let's say you set the channel count to 4, so RemoteIO is able to provide you 4 input channel buffers. Using this struct, you can map which USB input channel appears on the specific buffer positions.
@since The MultiRoute category is available in iOS 6.0 and later.
@see @c multiRouteOutputChannelMap
@param USBChannels Example: set USBChannels[0] to 3, to receive the input of the third USB channel on the first buffer.
@param numberOfUSBChannelsAvailable Number of USB input channels.
*/
typedef struct multiRouteInputChannelMap {
int USBChannels[32];
int numberOfUSBChannelsAvailable; // READ ONLY
} multiRouteInputChannelMap;
/**
@brief Converts from Apple 8.24 to 32-bit floating point.
This code is not optimized with Superpowered.
@param input Input buffers.
@param output Output buffers.
@param numberOfBuffers How many buffers to convert.
@param numberOfFrames How many frames to convert.
*/
void apple824ToFloat(int **input, float **output, int numberOfBuffers, int numberOfFrames);
/**
@brief Converts from stereo interleaved 32-bit floating point to non-interleaved Apple 8.24.
This code is not optimized with Superpowered. If you have the Superpowered Audio SDK, please use the SuperpoweredStereoMixer for this conversion.
@param input Input buffer (stereo, interleaved, 32-bit floating point).
@param output Two output buffer.
@param numberOfFrames How many frames to convert.
*/
void stereoFloatToApple824(float *input, int *output[2], int numberOfFrames);