Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
10 KiB

  1. /*****************************************************************************
  2. * private.h - FM synth miniport private definitions
  3. *****************************************************************************
  4. * Copyright (c) 1997-2000 Microsoft Corporation. All rights reserved.
  5. */
  6. #ifndef _FMSYNTH_PRIVATE_H_
  7. #define _FMSYNTH_PRIVATE_H_
  8. #include "portcls.h"
  9. #include "stdunk.h"
  10. #include "ksdebug.h"
  11. #include "miniport.h"
  12. enum {
  13. CHAN_MASTER = (-1),
  14. CHAN_LEFT = 0,
  15. CHAN_RIGHT = 1
  16. };
  17. /*****************************************************************************
  18. * Classes
  19. */
  20. /*****************************************************************************
  21. * CMiniportMidiFM
  22. *****************************************************************************
  23. * FM miniport. This object is associated with the device and is
  24. * created when the device is started. The class inherits IMiniportMidi
  25. * so it can expose this interface and CUnknown so it automatically gets
  26. * reference counting and aggregation support.
  27. */
  28. class CMiniportMidiFM
  29. : public IMiniportMidi,
  30. public IPowerNotify,
  31. public CUnknown
  32. {
  33. private:
  34. PPORTMIDI m_Port; // Callback interface.
  35. PUCHAR m_PortBase; // Base port address.
  36. BOOLEAN m_BoardNotResponsive; // Indicates dead hardware.
  37. BOOLEAN m_bInit; // true if we have already done init.
  38. BOOLEAN m_fStreamExists; // True if we have a stream.
  39. BYTE m_SavedRegValues[0x200]; // Shadow copies of the FM registers.
  40. POWER_STATE m_PowerState; // Saved power state (D0 = full power, D3 = off)
  41. BOOLEAN m_volNodeNeeded; // Whether we need to furnish a volume node.
  42. KSPIN_LOCK m_SpinLock; // Protects writes to hardware.
  43. /*************************************************************************
  44. * CMiniportMidiFM methods
  45. *
  46. * These are private member functions used internally by the object. See
  47. * MINIPORT.CPP for specific descriptions.
  48. *
  49. */
  50. NTSTATUS
  51. ProcessResources
  52. (
  53. IN PRESOURCELIST ResourceList
  54. );
  55. void SoundMidiSendFM(PUCHAR PortBase, ULONG Address, UCHAR Data); // low-level--write registers
  56. BOOL SoundSynthPresent(IN PUCHAR base, IN PUCHAR inbase); // detect if synth is present.
  57. BOOL SoundMidiIsOpl3(VOID); // returns true if the device is an opl3 and false if not.
  58. VOID Opl3_BoardReset(VOID);
  59. VOID MiniportMidiFMResume(VOID);
  60. public:
  61. /*************************************************************************
  62. * The following two macros are from STDUNK.H. DECLARE_STD_UNKNOWN()
  63. * defines inline IUnknown implementations that use CUnknown's aggregation
  64. * support. NonDelegatingQueryInterface() is declared, but it cannot be
  65. * implemented generically. Its definition appears in MINIPORT.CPP.
  66. * DEFINE_STD_CONSTRUCTOR() defines inline a constructor which accepts
  67. * only the outer unknown, which is used for aggregation. The standard
  68. * create macro (in MINIPORT.CPP) uses this constructor.
  69. */
  70. DECLARE_STD_UNKNOWN();
  71. // expand constructor to take bool for whether to include volume
  72. CMiniportMidiFM(PUNKNOWN pUnknownOuter,int createVolNode)
  73. : CUnknown(pUnknownOuter)
  74. {
  75. m_volNodeNeeded = (createVolNode != 0);
  76. };
  77. ~CMiniportMidiFM();
  78. /*************************************************************************
  79. * IMiniport methods
  80. */
  81. STDMETHODIMP_(NTSTATUS)
  82. GetDescription
  83. ( OUT PPCFILTER_DESCRIPTOR * OutFilterDescriptor
  84. );
  85. STDMETHODIMP_(NTSTATUS)
  86. DataRangeIntersection
  87. ( IN ULONG PinId
  88. , IN PKSDATARANGE DataRange
  89. , IN PKSDATARANGE MatchingDataRange
  90. , IN ULONG OutputBufferLength
  91. , OUT PVOID ResultantFormat
  92. , OUT PULONG ResultantFormatLength
  93. )
  94. {
  95. return STATUS_NOT_IMPLEMENTED;
  96. }
  97. /*************************************************************************
  98. * IMiniportMidi methods
  99. */
  100. STDMETHODIMP_(NTSTATUS) Init
  101. (
  102. IN PUNKNOWN UnknownNotUsed OPTIONAL,
  103. IN PRESOURCELIST ResourceList,
  104. IN PPORTMIDI Port,
  105. OUT PSERVICEGROUP * ServiceGroup
  106. );
  107. STDMETHODIMP_(NTSTATUS) NewStream
  108. (
  109. OUT PMINIPORTMIDISTREAM * Stream,
  110. IN PUNKNOWN OuterUnknown OPTIONAL,
  111. IN POOL_TYPE PoolType,
  112. IN ULONG Pin,
  113. IN BOOLEAN Capture,
  114. IN PKSDATAFORMAT DataFormat,
  115. OUT PSERVICEGROUP * ServiceGroup
  116. );
  117. STDMETHODIMP_(void) Service
  118. ( void
  119. );
  120. /*************************************************************************
  121. * IPowerNotify methods
  122. */
  123. STDMETHODIMP_(void) PowerChangeNotify(
  124. IN POWER_STATE PowerState
  125. );
  126. /*************************************************************************
  127. * Friends
  128. */
  129. friend class CMiniportMidiStreamFM;
  130. };
  131. /*****************************************************************************
  132. * CMiniportMidiStreamFM
  133. *****************************************************************************
  134. * FM miniport stream. This object is associated with a pin and is created
  135. * when the pin is instantiated. The class inherits IMiniportMidiStream
  136. * so it can expose this interface and CUnknown so it automatically gets
  137. * reference counting and aggregation support.
  138. */
  139. class CMiniportMidiStreamFM
  140. : public IMiniportMidiStream,
  141. public CUnknown
  142. {
  143. private:
  144. CMiniportMidiFM * m_Miniport; // Parent miniport.
  145. PUCHAR m_PortBase; // Base port address.
  146. // midi stuff
  147. voiceStruct m_Voice[NUM2VOICES]; /* info on what voice is where */
  148. DWORD m_dwCurTime; /* for note on/off */
  149. /* volume */
  150. WORD m_wSynthAttenL; /* in 1.5dB steps */
  151. WORD m_wSynthAttenR; /* in 1.5dB steps */
  152. /* support for volume property */
  153. LONG m_MinVolValue; // Minimum value for volume controller
  154. LONG m_MaxVolValue; // Maximum value for volume controller
  155. ULONG m_VolStepDelta; // Correlation between controller and actual decibels
  156. LONG m_SavedVolValue[2]; // Saved value for volume controller
  157. /* channel volumes */
  158. BYTE m_bChanAtten[NUMCHANNELS]; /* attenuation of each channel, in .75 db steps */
  159. BYTE m_bStereoMask[NUMCHANNELS]; /* mask for left/right for stereo midi files */
  160. short m_iBend[NUMCHANNELS]; /* bend for each channel */
  161. BYTE m_bPatch[NUMCHANNELS]; /* patch number mapped to */
  162. BYTE m_bSustain[NUMCHANNELS]; /* Is sustain in effect on this channel? */
  163. /*************************************************************************
  164. * CMiniportMidiStreamFM methods
  165. *
  166. * These are private member functions used internally by the object. See
  167. * MINIPORT.CPP for specific descriptions.
  168. */
  169. VOID WriteMidiData(DWORD dwData);
  170. // opl3 processing methods.
  171. VOID Opl3_ChannelVolume(BYTE bChannel, WORD wAtten);
  172. VOID Opl3_SetPan(BYTE bChannel, BYTE bPan);
  173. VOID Opl3_PitchBend(BYTE bChannel, short iBend);
  174. VOID Opl3_NoteOn(BYTE bPatch,BYTE bNote, BYTE bChannel, BYTE bVelocity,short iBend);
  175. VOID Opl3_NoteOff (BYTE bPatch,BYTE bNote, BYTE bChannel, BYTE bSustain);
  176. VOID Opl3_AllNotesOff(VOID);
  177. VOID Opl3_ChannelNotesOff(BYTE bChannel);
  178. WORD Opl3_FindFullSlot(BYTE bNote, BYTE bChannel);
  179. WORD Opl3_CalcFAndB (DWORD dwPitch);
  180. DWORD Opl3_CalcBend (DWORD dwOrig, short iBend);
  181. BYTE Opl3_CalcVolume (BYTE bOrigAtten, BYTE bChannel,BYTE bVelocity, BYTE bOper, BYTE bMode);
  182. BYTE Opl3_CalcStereoMask (BYTE bChannel);
  183. WORD Opl3_FindEmptySlot(BYTE bPatch);
  184. VOID Opl3_SetVolume(BYTE bChannel);
  185. VOID Opl3_FMNote(WORD wNote, noteStruct FAR * lpSN);
  186. VOID Opl3_SetSustain(BYTE bChannel, BYTE bSusLevel);
  187. void SetFMAtten(LONG channel, LONG level);
  188. LONG GetFMAtten(LONG channel) { return m_SavedVolValue[channel]; };
  189. public:
  190. NTSTATUS
  191. Init
  192. (
  193. IN CMiniportMidiFM * Miniport,
  194. IN PUCHAR PortBase
  195. );
  196. /*************************************************************************
  197. * The following two macros are from STDUNK.H. DECLARE_STD_UNKNOWN()
  198. * defines inline IUnknown implementations that use CUnknown's aggregation
  199. * support. NonDelegatingQueryInterface() is declared, but it cannot be
  200. * implemented generically. Its definition appears in MINIPORT.CPP.
  201. * DEFINE_STD_CONSTRUCTOR() defines inline a constructor which accepts
  202. * only the outer unknown, which is used for aggregation. The standard
  203. * create macro (in MINIPORT.CPP) uses this constructor.
  204. */
  205. DECLARE_STD_UNKNOWN();
  206. DEFINE_STD_CONSTRUCTOR(CMiniportMidiStreamFM);
  207. ~CMiniportMidiStreamFM();
  208. /*************************************************************************
  209. * IMiniportMidiStream methods
  210. */
  211. STDMETHODIMP_(NTSTATUS) SetFormat
  212. (
  213. IN PKSDATAFORMAT DataFormat
  214. );
  215. STDMETHODIMP_(NTSTATUS) SetState
  216. (
  217. IN KSSTATE State
  218. );
  219. STDMETHODIMP_(NTSTATUS) Read
  220. (
  221. IN PVOID BufferAddress,
  222. IN ULONG BufferLength,
  223. OUT PULONG BytesRead
  224. );
  225. STDMETHODIMP_(NTSTATUS) Write
  226. (
  227. IN PVOID BufferAddress,
  228. IN ULONG BytesToWrite,
  229. OUT PULONG BytesWritten
  230. );
  231. /*************************************************************************
  232. * Friends
  233. */
  234. friend
  235. NTSTATUS BasicSupportHandler
  236. (
  237. IN PPCPROPERTY_REQUEST PropertyRequest
  238. );
  239. friend
  240. NTSTATUS PropertyHandler_Level
  241. (
  242. IN PPCPROPERTY_REQUEST PropertyRequest
  243. );
  244. friend
  245. NTSTATUS PropertyHandler_CpuResources
  246. (
  247. IN PPCPROPERTY_REQUEST PropertyRequest
  248. );
  249. };
  250. #endif