![]() |
pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
|
00001 /* 00002 ------------------------------------------------------------------------------- 00003 This file is part of the Plink, Plonk, Plank libraries 00004 by Martin Robinson 00005 00006 http://code.google.com/p/pl-nk/ 00007 00008 Copyright University of the West of England, Bristol 2011-14 00009 All rights reserved. 00010 00011 Redistribution and use in source and binary forms, with or without 00012 modification, are permitted provided that the following conditions are met: 00013 00014 * Redistributions of source code must retain the above copyright 00015 notice, this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright 00017 notice, this list of conditions and the following disclaimer in the 00018 documentation and/or other materials provided with the distribution. 00019 * Neither the name of University of the West of England, Bristol nor 00020 the names of its contributors may be used to endorse or promote products 00021 derived from this software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF THE WEST OF ENGLAND, BRISTOL BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 This software makes use of third party libraries. For more information see: 00035 doc/license.txt included in the distribution. 00036 ------------------------------------------------------------------------------- 00037 */ 00038 00039 #ifndef PLONK_IOSAUDIOHOST_H 00040 #define PLONK_IOSAUDIOHOST_H 00041 00042 #include <AudioToolbox/AudioServices.h> 00043 #include <AudioUnit/AudioUnit.h> 00044 00045 BEGIN_PLONK_NAMESPACE 00046 00048 class IOSUtilities 00049 { 00050 public: 00052 enum Locations 00053 { 00054 Bundle, 00055 Documents, 00056 Temporary 00057 }; 00058 00064 static Text pathInDirectory (Locations location, const char *filename) throw(); 00065 }; 00066 00067 typedef OSStatus (*RenderCallbackFunction)(void* refCon, 00068 UInt32 inNumberFrames, 00069 AudioUnitRenderActionFlags *ioActionFlags, 00070 const AudioTimeStamp *inTimeStamp, 00071 AudioBufferList *ioData); 00072 00075 template<class SampleType> 00076 class IOSAudioHostBase : public AudioHostBase<SampleType> 00077 { 00078 public: 00079 typedef typename AudioHostBase<SampleType>::BufferArray BufferArray; 00080 typedef typename AudioHostBase<SampleType>::ConstBufferArray ConstBufferArray; 00081 typedef typename AudioHostBase<SampleType>::UnitType UnitType; 00082 typedef NumericalArray<SampleType> Buffer; 00083 00084 IOSAudioHostBase() throw(); 00085 ~IOSAudioHostBase(); 00086 00087 Text getHostName() const throw(); 00088 Text getNativeHostName() const throw(); 00089 Text getInputName() const throw(); 00090 Text getOutputName() const throw(); 00091 double getCpuUsage() const throw() { return cpuUsage; } 00092 00093 void startHost() throw(); 00094 void stopHost() throw(); 00095 void pauseHost() throw(); 00096 void resumeHost() throw(); 00097 00098 virtual void hostInterruption (const bool flag) throw() { } 00099 inline bool wasInterrupted() throw() { return interrupted.getValue() != 0; } 00100 00101 OSStatus renderCallback (UInt32 inNumberFrames, 00102 AudioUnitRenderActionFlags *ioActionFlags, 00103 const AudioTimeStamp *inTimeStamp, 00104 AudioBufferList *ioData) throw(); 00105 00106 void propertyCallback (AudioSessionPropertyID inID, 00107 UInt32 inDataSize, 00108 const void * inPropertyValue) throw(); 00109 00110 void interruptionCallback (UInt32 inInterruption) throw(); 00111 00112 void setCustomRenderCallbacks (void* refCon, RenderCallbackFunction preRender, RenderCallbackFunction postRender) throw(); 00113 00114 00115 private: 00116 void setFormat() throw(); 00117 int setupRemoteIO() throw(); 00118 void killRemoteIO() throw(); 00119 void resetIO() throw(); 00120 void restart() throw(); 00121 void fixAudioRouteIfSetToReceiver() throw(); 00122 00123 AudioStreamBasicDescription format; 00124 AURenderCallbackStruct inputProc; 00125 Float64 hwSampleRate; 00126 AudioUnit rioUnit; 00127 00128 int bufferSize; 00129 float bufferDuration; 00130 double reciprocalBufferDuration; 00131 Buffer convertBuffer; 00132 UInt32 audioInputIsAvailable; 00133 UInt32 numInputChannels; 00134 UInt32 numOutputChannels; 00135 double cpuUsage; 00136 00137 AtomicInt interrupted; 00138 00139 void* customRenderCallbackRef; 00140 RenderCallbackFunction customPreRender; 00141 RenderCallbackFunction customPostRender; 00142 }; 00143 00144 00145 // depracated but for backwards compatibility. 00146 class IOSAudioHost : public IOSAudioHostBase<float> 00147 { 00148 public: 00149 IOSAudioHost() throw() 00150 { 00151 } 00152 }; 00153 00154 END_PLONK_NAMESPACE 00155 00156 #if defined(__OBJC__) || DOXYGEN 00157 00158 @class PLAudioHost; 00159 00160 using namespace plonk; 00161 00166 @protocol PLAudioHostDelegate <NSObject> 00167 @optional 00168 - (FloatUnit)constructGraphFloat:(PLAudioHost*)host; 00169 - (ShortUnit)constructGraphShort:(PLAudioHost*)host; 00170 - (IntUnit)constructGraphInt:(PLAudioHost*)host; 00171 - (DoubleUnit)constructGraphDouble:(PLAudioHost*)host; 00172 - (Unit)constructGraph:(PLAudioHost*)host DEPRECATED_ATTRIBUTE; 00173 - (void)hostStarting:(PLAudioHost*)host; 00174 - (void)hostStopped:(PLAudioHost*)host; 00175 - (void)hostPaused:(PLAudioHost*)host; 00176 - (void)hostResuming:(PLAudioHost*)host; 00177 - (void)hostInterruption:(PLAudioHost*)host withFlag:(BOOL)flag; 00178 @end 00179 00180 00191 @interface PLAudioHost : NSObject 00192 { 00193 void* peer; 00194 id<PLAudioHostDelegate> delegate; 00195 int type; 00196 } 00197 00198 @property (nonatomic, assign) id delegate; 00199 @property (nonatomic, readonly) NSString* hostName; 00200 @property (nonatomic, readonly) NSString* nativeHostName; 00201 @property (nonatomic, readonly) NSString* inputName; 00202 @property (nonatomic, readonly) NSString* outputName; 00203 @property (nonatomic, readonly) double cpuUsage; 00204 @property (nonatomic, readonly) BOOL isRunning; 00205 @property (nonatomic, readonly) BOOL isPaused; 00206 @property (nonatomic, readonly) BOOL wasInterrupted; 00207 @property (nonatomic, readonly) Dynamic outputUnit; 00208 @property (nonatomic) int numInputs; 00209 @property (nonatomic) int numOutputs; 00210 @property (nonatomic) int preferredHostBlockSize; 00211 @property (nonatomic) int preferredGraphBlockSize; 00212 @property (nonatomic) double preferredHostSampleRate; 00213 00215 - (void)startHost; 00216 00218 - (void)stopHost; 00219 00221 - (void)pauseHost; 00222 00224 - (void)resumeHost; 00225 00226 - (void)setCustomRenderCallbacksWithRef:(void*)refCon pre:(RenderCallbackFunction)preFunc post:(RenderCallbackFunction)postFunc; 00227 00228 @end 00229 00230 #endif 00231 00232 #define PLANK_INLINING_FUNCTIONS 1 00233 #include "plonk_IOSAudioHostInline.h" 00234 #undef PLANK_INLINING_FUNCTIONS 00235 00236 #endif // PLONK_IOSAUDIOHOST_H