|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : AudioStreamEngine.h 00004 * Part of : AudioStream 00005 * Created : April 28, 2006 by Forum Nokia 00006 * Description : Declares the Engine class for AudioStream application 00007 * Version : 2.0 00008 * 00009 * Copyright (c) 2006 - 2007 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 #ifndef AUDIOSTREAMENGINE_H 00017 #define AUDIOSTREAMENGINE_H 00018 00019 // INCLUDES 00020 #include <e32base.h> 00021 #include <aknviewappui.h> 00022 00023 #include <mda\common\audio.h> 00024 #include <MdaAudioInputStream.h> // audio input stream 00025 #include <MdaAudioOutputStream.h> // audio output stream 00026 00027 #include "AudioStream.hrh" 00028 #include "AudioStreamView.h" 00029 #include "AudioStreamAppUi.h" 00030 00031 // FORWARD DECLARATIONS 00032 class CAudioStreamView; 00033 00034 // CLASS DECLARATION 00035 00036 /** 00037 * CAudioStreamEngine application engine class. 00038 * 00039 */ 00040 class CAudioStreamEngine : public CBase, MMdaAudioInputStreamCallback, 00041 MMdaAudioOutputStreamCallback 00042 { 00043 public: 00044 /*! 00045 * NewL() 00046 * 00047 * discussion Create new CAudioStreamEngine object 00048 * return a pointer to the created instance of CAudioStreamEngine 00049 */ 00050 static CAudioStreamEngine* NewL(CAudioStreamAppUi* /* aAppUi */); 00051 00052 /*! 00053 * NewLC() 00054 * 00055 * discussion Create new CAudioStreamEngine object 00056 * return a pointer to the created instance of CAudioStreamEngine which 00057 * has also been pushed to cleanup stack 00058 */ 00059 static CAudioStreamEngine* NewLC(CAudioStreamAppUi* /* aAppUi */); 00060 00061 00062 /*! 00063 * ~CAudioStreamEngine() 00064 * 00065 * discussion Destroy the object and release all memory objects 00066 */ 00067 ~CAudioStreamEngine(); 00068 00069 00070 public: // New functions 00071 00072 /*! 00073 * Play() 00074 * 00075 * discussion Plays the audio data sample 00076 */ 00077 void Play(); 00078 /*! 00079 * Record() 00080 * 00081 * discussion Records an audio data sample 00082 */ 00083 void Record(); 00084 /*! 00085 * Stop() 00086 * 00087 * discussion Stops the playing/recording of the audio data 00088 */ 00089 void Stop(); 00090 00091 /*! 00092 * LoadAudioFileL() 00093 * 00094 * discussion Loads an audio data from a file 00095 */ 00096 void LoadAudioFileL(); 00097 /*! 00098 * SaveAudioFileL() 00099 * 00100 * discussion Saves the audio data into a file 00101 */ 00102 void SaveAudioFileL(); 00103 00104 /*! 00105 * SetEncodingL() 00106 * 00107 * discussion Sets the audio encoding to be used 00108 * param aAmr If ETrue, AMR-NB encoding will be used, if EFalse, the platform's 00109 * default encoding will be used 00110 */ 00111 void SetEncodingL(TBool aAmr); 00112 00113 private: // in-class methods 00114 00115 /*! 00116 * GetFrame() 00117 * 00118 * discussion Returns a modifiable pointer to a single frame inside the 00119 * audio buffer 00120 * 00121 * param aFrameIdx frame index 00122 * return a TPtr8 reference to the requested frame 00123 */ 00124 TPtr8& CAudioStreamEngine::GetFrame(TUint aFrameIdx); 00125 /*! 00126 * GetPlaybackFrames() 00127 * 00128 * discussion Returns a modifiable pointer to frames from the first frame to 00129 * aLastFrame in the audio buffer 00130 * 00131 * param aLastFrame Index of the last frame to be included in the pointer returned 00132 * return a TPtr8 reference to the requested frames 00133 */ 00134 TPtr8& CAudioStreamEngine::GetPlaybackFrames(TUint aLastFrame); 00135 00136 /*! 00137 * ShowMessage() 00138 * 00139 * discussion Displays application messages for user on a label 00140 * 00141 * param aMsg text to be displayed 00142 * param aReset if true, the label will be cleared before displaying aMsg, 00143 * if false, aMsg text will be appended to existing message on label 00144 */ 00145 void ShowMessage(const TDesC& /* aMsg */, TBool /* aReset=false */); 00146 00147 /*! 00148 * MaiscOpenComplete() 00149 * 00150 * discussion A callback function that is called when 00151 * CMdaAudioInputStream::Open() has completed, indicating that the audio 00152 * input stream is ready for use. 00153 * 00154 * param aError KErrNone if the open succeeded, otherwise one of the system 00155 * error codes. 00156 */ 00157 virtual void MaiscOpenComplete(TInt aError); 00158 /*! 00159 * MaiscBufferCopied() 00160 * 00161 * discussion A callback function that is called when a chunk of audio data 00162 * has been copied to the descriptor specified in a 00163 * CMdaAudioInputStream::ReadL(). 00164 * 00165 * param aError KErrNone if the copy succeeded, KErrAbort if the input stream 00166 * was closed for some reason, otherwise one of the system error codes. 00167 */ 00168 virtual void MaiscBufferCopied(TInt aError, const TDesC8& aBuffer); 00169 /*! 00170 * MaiscRecordComplete() 00171 * 00172 * discussion A callback function that is called when the input stream is 00173 * closed using CMdaAudioInputStream::Stop(). 00174 * 00175 * param aError KErrNone if the stop succeeded, otherwise one of the system 00176 * error codes. 00177 */ 00178 virtual void MaiscRecordComplete(TInt aError); 00179 00180 /*! 00181 * MaoscOpenComplete() 00182 * 00183 * discussion A callback function that is called when 00184 * CMdaAudioOutputStream::Open() has completed, indicating that the audio 00185 * output stream is ready for use. 00186 * 00187 * param aError KErrNone if the open succeeded, otherwise one of the system 00188 * error codes. 00189 */ 00190 virtual void MaoscOpenComplete(TInt aError); 00191 /*! 00192 * MaoscBufferCopied() 00193 * 00194 * discussion A callback function that is called when a descriptor has been 00195 * copied to the lower layers of MMF. It is also called when an error has 00196 * occurred or when the client has stopped the stream playing before the 00197 * descriptor has been fully copied (by calling 00198 * CMdaAudioOutputStream::Stop()) 00199 * 00200 * param aError KErrNone if the copy succeeded, otherwise one of the system 00201 * error codes. KErrAbort indicates that the client has stopped the stream 00202 * playing before the descriptor has been copied. 00203 * param aBuffer reference to the buffer that has been copied. 00204 */ 00205 virtual void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer); 00206 00207 /*! 00208 * MaoscPlayComplete() 00209 * 00210 * discussion A callback function that is called when playback terminates as 00211 * a result of a CMdaAudioOutputStream::Stop(). 00212 * 00213 * param aError KErrNone if the close succeeded, otherwise one of the system 00214 * error codes. 00215 */ 00216 virtual void MaoscPlayComplete(TInt aError); 00217 00218 public: // Functions from base classes 00219 00220 private: // Basic two-phase EPOC constructors 00221 00222 /*! 00223 * ConstructL() 00224 * 00225 * discussion Perform the second phase construction of a CAudioStreamEngine 00226 * object 00227 */ 00228 void ConstructL(); 00229 00230 /*! 00231 * CAudioStreamEngine() 00232 * 00233 * discussion Perform the first phase of two phase construction 00234 */ 00235 CAudioStreamEngine(CAudioStreamAppUi* /* aAppUi */); 00236 00237 private: 00238 00239 // enumeration of input/output stream status 00240 enum TStatus 00241 { 00242 ENotReady, 00243 EOpen 00244 }; 00245 00246 00247 private: // data members 00248 00249 // application UI object reference 00250 CAudioStreamAppUi* iAppUi; 00251 // audio input stream object reference 00252 CMdaAudioInputStream* iInputStream; 00253 // audio output stream object reference 00254 CMdaAudioOutputStream* iOutputStream; 00255 00256 // Handle to CCoeEnv's file server 00257 RFs iFs; 00258 00259 // Do we use AMR-NB encoding? 00260 TBool iUseAMR; 00261 // The path to the sample audio file (sample.aud or sample.amr) 00262 TFileName iAudioFilePath; 00263 // The audio file to be used (sample.aud or sample.amr) 00264 TFileName iAudioFile; 00265 // The frame size for the current encoding 00266 TUint iFrameSize; 00267 // The number of frames to be buffered 00268 TUint iFrameCount; 00269 00270 // A buffer containing the audio frames 00271 HBufC8* iStreamBuffer; 00272 // Modifiable pointer used to reference a single frame in iStreamBuffer 00273 // while recording, and all the valid frames in iStreamBuffer while playback (the 00274 // iStreamBuffer might not always be fully recorded in this example). 00275 TPtr8 iFramePtr; 00276 // Buffer status (does it contain valid audio data) 00277 TBool iBufferOK; 00278 // The default encoding used by the platform 00279 TFourCC iDefaultEncoding; 00280 // The encoding we are currently using 00281 TFourCC iCurrentEncoding; 00282 00283 // Audio data stream settings for input and output streams 00284 TMdaAudioDataSettings iStreamSettings; 00285 // Status enumeration of input stream 00286 TStatus iInputStatus; 00287 // Status enumeration of output stream 00288 TStatus iOutputStatus; 00289 // Index of audio data block currently being played/recorded on the buffer 00290 TUint iStreamIdx; 00291 // Application status message displayed to user 00292 TBuf<255> iMsg; 00293 // Stream start (first audio block in buffer) and end index 00294 TUint iStreamStart; 00295 TUint iStreamEnd; 00296 00297 }; 00298 00299 #endif // AUDIOSTREAMENGINE_H 00300 00301
|
© Nokia 2009 |