00001 /*---------------------------------------------------------------------------- 00002 MoMu: A Mobile Music Toolkit 00003 Copyright (c) 2010 Nicholas J. Bryan, Jorge Herrera, Jieun Oh, and Ge Wang 00004 All rights reserved. 00005 http://momu.stanford.edu/toolkit/ 00006 00007 Mobile Music Research @ CCRMA 00008 Music, Computing, Design Group 00009 Stanford University 00010 http://momu.stanford.edu/ 00011 http://ccrma.stanford.edu/groups/mcd/ 00012 00013 MoMu is distributed under the following BSD style open source license: 00014 00015 Permission is hereby granted, free of charge, to any person obtaining a 00016 copy of this software and associated documentation files (the 00017 "Software"), to deal in the Software without restriction, including 00018 without limitation the rights to use, copy, modify, merge, publish, 00019 distribute, sublicense, and/or sell copies of the Software, and to 00020 permit persons to whom the Software is furnished to do so, subject to 00021 the following conditions: 00022 00023 The authors encourage users of MoMu to include this copyright notice, 00024 and to let us know that you are using MoMu. Any person wishing to 00025 distribute modifications to the Software is encouraged to send the 00026 modifications to the original authors so that they can be incorporated 00027 into the canonical version. 00028 00029 The Software is provided "as is", WITHOUT ANY WARRANTY, express or implied, 00030 including but not limited to the warranties of MERCHANTABILITY, FITNESS 00031 FOR A PARTICULAR PURPOSE and NONINFRINGEMENT. In no event shall the authors 00032 or copyright holders by liable for any claim, damages, or other liability, 00033 whether in an actino of a contract, tort or otherwise, arising from, out of 00034 or in connection with the Software or the use or other dealings in the 00035 software. 00036 -----------------------------------------------------------------------------*/ 00037 00038 /*----------------------------------------------------------------------------*/ 00064 /*----------------------------------------------------------------------------*/ 00065 00066 00067 #ifndef __MO_AUDIO_H__ 00068 #define __MO_AUDIO_H__ 00069 00070 // headers 00071 #include "mo_def.h" 00072 #include <AudioUnit/AudioUnit.h> 00073 00074 00075 /*----------------------------------------------------------------------------*/ 00084 /*----------------------------------------------------------------------------*/ 00085 typedef void (* MoCallback)( Float32 * buffer, UInt32 numFrames, void * userData ); 00086 00087 00088 /*----------------------------------------------------------------------------*/ 00093 /*----------------------------------------------------------------------------*/ 00094 struct MoAudioUnitInfo 00095 { 00096 AudioStreamBasicDescription m_dataFormat; 00097 UInt32 m_bufferSize; // # of frames 00098 UInt32 m_bufferByteSize; 00099 Float32 * m_ioBuffer; 00100 bool m_done; 00101 00103 MoAudioUnitInfo() 00104 { 00105 m_bufferSize = 4096; // max 00106 m_bufferByteSize = 0; 00107 m_ioBuffer = NULL; 00108 m_done = false; 00109 } 00110 00112 ~MoAudioUnitInfo() 00113 { 00114 m_bufferSize = 4096; 00115 m_bufferByteSize = 0; 00116 SAFE_DELETE_ARRAY( m_ioBuffer ); 00117 } 00118 }; 00119 00120 00121 00122 00123 /*----------------------------------------------------------------------------*/ 00141 /*----------------------------------------------------------------------------*/ 00142 class MoAudio 00143 { 00144 public: 00145 static bool init( Float64 srate, UInt32 frameSize, UInt32 numChannels ); 00146 static bool start( MoCallback callback, void * bindle ); 00147 static void stop(); 00148 static void shutdown(); 00149 static Float64 getSampleRate() { return m_srate; } 00150 static void vibrate(); 00151 00152 public: // sketchy public 00153 static void checkInput(); 00154 00155 protected: 00156 static bool initOut(); 00157 static bool initIn(); 00158 00159 protected: 00160 static bool m_hasInit; 00161 static bool m_isRunning; 00162 00163 public: // ge: making this public was a hack 00164 static MoAudioUnitInfo * m_info; 00165 static MoCallback m_callback; 00166 // static Float32 * m_buffer; 00167 // static UInt32 m_bufferFrames; 00168 static AudioUnit m_au; 00169 static bool m_isMute; 00170 static bool m_handleInput; 00171 static Float64 m_hwSampleRate; 00172 static Float64 m_srate; 00173 static UInt32 m_frameSize; 00174 static UInt32 m_numChannels; 00175 static void * m_bindle; 00176 00177 // audio unit remote I/O 00178 static AURenderCallbackStruct m_renderProc; 00179 }; 00180 00181 00182 #endif