macaudio.h
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:10k
源码类别:

Symbian

开发平台:

Visual C++

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