macaudio.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:9k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #pragma once
  36. #include "hxtypes.h"
  37. //#include "callback.h"
  38. #ifndef _MAC_MACHO
  39. #include <SoundInput.h>
  40. #endif
  41. #include "hxcom.h"
  42. #include "hxausvc.h"
  43. #include "hxengin.h"
  44. #include "hxaudev.h"
  45. /*--------------------------------------------------------------------------
  46. | CMacWaveFormat class
  47. --------------------------------------------------------------------------*/
  48. class CMacWaveFormat {
  49. friend class CWaveHeader;
  50. protected:
  51. short numChannels;
  52. Fixed sampleRate;
  53. short sampleSize;
  54. OSType compressionType;
  55. short baseFrequency;
  56. public:
  57. CMacWaveFormat (void);
  58. ~CMacWaveFormat (void);
  59. OSErr SetUpSound (SndListHandle sndHandle,
  60. long numBytes,
  61. short *headerLen,
  62. long *headerOffset);
  63.  
  64. static OSErr SetHeaderLength (SoundHeaderPtr pSoundHeader,
  65. long numBytes);
  66. void  SetFormat (ULONG32 sampleRate,
  67. UINT16  channels,
  68. UINT16   bitsPerSample);
  69.  
  70. private:
  71. void SetFormatDflt (void);
  72. };
  73. /*--------------------------------------------------------------------------
  74. | CAudioOutMac class
  75. --------------------------------------------------------------------------*/
  76. class CAudioOutMac;
  77. typedef struct audio_init_params
  78. {
  79. float  sampleRate;
  80. UINT16  channels;
  81. UINT16  bitsPerSample;
  82. UINT16  volume;
  83. UINT16  numBufs;
  84. UINT16  bufSize;
  85. } AUDIO_INIT_PARAMS;
  86. #define WAVE_DEFAULT_SAMPLE_RATE  8000.
  87. #define WAVE_DEFAULT_BITSPERSAMPLE  16
  88. #define WAVE_DEFAULT_CHANNELS  1
  89. /*--------------------------------------------------------------------------
  90. | CWaveHeader
  91. --------------------------------------------------------------------------*/
  92. class CWaveHeader {
  93. private:
  94. static const Size kSndHeaderSize;
  95. enum PlayState {
  96. kFreeState,
  97. kQueuedState,
  98. kFnordState
  99. };
  100. long soundA5;
  101. short state;
  102. Size cbPlaying;
  103. ULONG32 timeEnd;
  104. UINT16 mMaxPlay;
  105. SndListHandle sndHandle;
  106. short mHeaderLen;
  107. SoundHeaderPtr mSoundHeader;
  108. float mSampleRate;
  109. UINT16 mBitsPerSample;
  110. UINT16 mChannels;
  111. public:
  112. enum ReleaseCode {
  113. kCallBackRelease,
  114. kAbortRelease,
  115. kResetRelease,
  116. kFnordRelease
  117. };
  118. CAudioOutMac *waveOut;
  119. static UINT16 WAVE_BLOCKSIZE;
  120. static SndChannelPtr NewChannel (void);
  121. static OSErr DisposeChannel (SndChannelPtr chan);
  122. CWaveHeader (void);
  123. ~CWaveHeader (void);
  124. inline void SetOutput(CAudioOutMac *waveOutArg)
  125. {waveOut = waveOutArg;};
  126. inline Boolean Available(void) const
  127. {return (kFreeState == state);};
  128. inline UINT16 MaxPlayLength(void) const
  129. {return mMaxPlay;};
  130. OSErr Allocate(UINT16 inMaxPlay,
  131. float   sampleRate,
  132. UINT16  channels,
  133. UINT16  bitsPerSample);
  134.  
  135. void Release (short param1, BOOL bSendTimeSync = TRUE);
  136. OSErr PlayBuffer(char *pData,
  137.    UINT16 cbPlay,
  138.    ULONG32 timeEndArg);
  139. inline void  *get_buffer  (void)
  140. {return (void *)((*(Handle) sndHandle) + mHeaderLen);};
  141. private:
  142. static pascal void Callback(SndChannelPtr chan,
  143.  SndCommand *cmd);
  144. };
  145. /*--------------------------------------------------------------------------
  146. | CAudioOutMac
  147. --------------------------------------------------------------------------*/
  148. class callback;
  149. class CHXSimpleList;
  150. #ifdef THREADS_SUPPORTED
  151. class HXMutex;
  152. #endif
  153. // foward decls.
  154. struct IHXCallback;
  155. struct IHXInterruptState;
  156. class CAudioOutMac : public CHXAudioDevice {
  157. public:
  158. /* Create friend class for scheduled playback callback.
  159.  */
  160.         class HXPauseResumeCb : public IHXCallback
  161.         {
  162.         private:
  163.             LONG32              m_lRefCount;
  164.                                 ~HXPauseResumeCb();
  165.             PRIVATE_DESTRUCTORS_ARE_NOT_A_CRIME
  166.         public:
  167.                                 HXPauseResumeCb(CAudioOutMac* pAudioObject);
  168.     CallbackHandle   m_CallbackHandle;
  169.             CAudioOutMac*    m_pAudioDeviceObject;
  170.             CHXSimpleList*   m_pCommandList;
  171.             /*
  172.              *  IUnknown methods
  173.              */
  174.             STDMETHOD(QueryInterface)   (THIS_
  175.                                             REFIID riid,
  176.                                             void** ppvObj);
  177.             STDMETHOD_(ULONG32,AddRef)  (THIS);
  178.             STDMETHOD_(ULONG32,Release) (THIS);
  179.             /*
  180.              *  IHXCallback methods
  181.              */
  182.             STDMETHOD(Func)                     (THIS);
  183.             void Enter(BOOL bResume);
  184.         };
  185. friend class HXPauseResumeCb;
  186. BOOL OkToPauseResume(BOOL bToBeResumed/* TRUE - Resume. FALSE - Pause */);
  187. private:
  188.     struct GestaltDeferredStruct
  189.     {
  190. UINT32* quitting;
  191. UINT32* pending;
  192. ProcessSerialNumber psn;
  193.     };
  194.     
  195. static UINT16 NUM_WAVEHDRS;
  196. friend class CWaveHeader;
  197. UINT16 mcbPlaying;
  198. SndChannelPtr chan;
  199. CMacWaveFormat wf;
  200. CWaveHeader* mlpWaveHdrs;
  201. Boolean mPaused; // Kludge to prevent paused callbacks
  202. UINT16 m_uNumBlocksInDevice;
  203. static UINT16  m_uzVolume;
  204. Boolean m_bFirstPacket;
  205. ULONG32 m_ulTimeOfFirstPacket;
  206. CHXSimpleList* m_pPendingCallbackList;
  207. HXPauseResumeCb* m_pCallback;
  208. DeferredTask* mDeferredTaskRec;
  209. double m_millisecondsIntoClip;
  210. #ifdef THREADS_SUPPORTED
  211. static HXMutex* zm_pMutex;
  212. #endif
  213.            static DeferredTaskUPP gDeferredTask;
  214. static  pascal  void DeferredTaskCallback(long param);
  215. public:
  216. #if 1
  217. enum PlayResults {
  218. playSuccess = 0,
  219. playError,
  220. playFull,
  221. playFnord
  222. };
  223. enum OpenResults {
  224. openSuccess = 0,
  225. openDriver,
  226. openMemory,
  227. openFnord
  228. };
  229. #endif
  230. CAudioOutMac ();
  231. ~CAudioOutMac (void);
  232. void   ProcessCmd(SndCommand* cmd, BOOL bSendTimeSync = TRUE);
  233. void   AddToThePendingList(void* pNode);
  234. BOOL   m_bDeferredTaskPending;
  235. IHXInterruptState* m_pInterruptState;
  236. // m_bAudioCallbacksAreAlive and m_bIsQuitting need to be UINT32s because
  237. // later interrupt-related crash-preventing Gestalt-based code makes that
  238. // assumption.
  239. UINT32 m_bAudioCallbacksAreAlive;
  240. UINT32 m_bIsQuitting;
  241. protected:
  242. HX_RESULT    _Imp_Open( const HXAudioFormat* pFormat );
  243. HX_RESULT    _Imp_Close( void );
  244. HX_RESULT _Imp_Seek(ULONG32 ulSeekTime);
  245. HX_RESULT    _Imp_Pause( void );
  246. HX_RESULT    _Imp_Resume( void );
  247. HX_RESULT    _Imp_Write( const HXAudioData* pAudioOutHdr );
  248. HX_RESULT    _Imp_Reset( void );
  249. HX_RESULT   _Imp_Drain( void );
  250. BOOL  _Imp_SupportsVolume( void );
  251. UINT16    _Imp_GetVolume();
  252. HX_RESULT    _Imp_SetVolume( const UINT16 uVolume );
  253. HX_RESULT    _Imp_CheckFormat( const HXAudioFormat* pFormat);
  254. HX_RESULT _Imp_GetCurrentTime(ULONG32& ulCurrentTime);
  255. INT16 _Imp_GetAudioFd(void) {return 0;};
  256. UINT16 _NumberOfBlocksRemainingToPlay(void);
  257.  
  258. void Abort(void);
  259. void CleanupPendingLists(void);
  260. inline CWaveHeader*GetWaveHeader(short index)
  261. {return mlpWaveHdrs ? mlpWaveHdrs + index : NULL;};
  262. private:
  263. void ReleaseBlocks (short releaseCode);
  264. OSErr DoImmediate (short cmd,
  265.  short param1 = 0,
  266.  long param2 = 0L);
  267. void DonePlaying (UINT16 cbPlayedArg,
  268.  ULONG32 timeEndArg,
  269.  short waveTask,
  270.  BOOL bSendTimeSync = TRUE);
  271. inline void StartedPlaying (UINT16 cbPlayed)
  272. {mcbPlaying += cbPlayed;};
  273. };