Leaked source code of windows server 2003
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.

206 lines
4.4 KiB

  1. /***************************************************************************
  2. *
  3. * mixer.c
  4. *
  5. * Copyright (c) 1991-1996 Microsoft Corporation. All Rights Reserved.
  6. *
  7. * This code provides VDD support for SB 2.0 sound output, specifically:
  8. * Mixer Chip CT1335 (not strictly part of SB 2.0, but apps seem to like it)
  9. *
  10. ***************************************************************************/
  11. /*****************************************************************************
  12. *
  13. * #includes
  14. *
  15. *****************************************************************************/
  16. #include <windows.h> // The VDD is a win32 DLL
  17. #include <mmsystem.h> // Multi-media APIs
  18. #include <vddsvc.h> // Definition of VDD calls
  19. #include <vsb.h>
  20. #include <mixer.h>
  21. extern SETVOLUMEPROC SetVolumeProc;
  22. extern HWAVEOUT HWaveOut; // the current open wave output device
  23. /*
  24. * Mixer globals
  25. */
  26. struct {
  27. BYTE MasterVolume; // current master volume
  28. BYTE FMVolume; // current volume of fm device
  29. BYTE CDVolume; // current volume of cd
  30. BYTE VoiceVolume; // current volume of wave device
  31. }
  32. MixerSettings;
  33. /*
  34. * Mixer State Machine
  35. */
  36. enum {
  37. MixerReset = 1, // initial state and after reset
  38. MixerMasterVolume,
  39. MixerFMVolume,
  40. MixerCDVolume,
  41. MixerVoiceVolume
  42. }
  43. MixerState = MixerReset; // state of current command/data being set
  44. /****************************************************************************
  45. *
  46. * Mixer device routines
  47. *
  48. ****************************************************************************/
  49. VOID
  50. MixerDataRead(
  51. BYTE * data
  52. )
  53. {
  54. switch(MixerState) {
  55. case MixerReset:
  56. ResetMixer();
  57. break;
  58. case MixerMasterVolume:
  59. *data = MixerSettings.MasterVolume;
  60. break;
  61. case MixerFMVolume:
  62. *data = MixerSettings.FMVolume;
  63. break;
  64. case MixerCDVolume:
  65. *data = MixerSettings.CDVolume;
  66. break;
  67. case MixerVoiceVolume:
  68. *data = MixerSettings.VoiceVolume;
  69. break;
  70. }
  71. }
  72. VOID
  73. MixerAddrWrite(
  74. BYTE data
  75. )
  76. {
  77. switch(data) {
  78. case MIXER_RESET:
  79. MixerState = MixerReset;
  80. break;
  81. case MIXER_MASTER_VOLUME:
  82. MixerState = MixerMasterVolume;
  83. break;
  84. case MIXER_FM_VOLUME:
  85. MixerState = MixerFMVolume;
  86. break;
  87. case MIXER_CD_VOLUME:
  88. MixerState = MixerCDVolume;
  89. break;
  90. case MIXER_VOICE_VOLUME:
  91. MixerState = MixerVoiceVolume;
  92. break;
  93. }
  94. }
  95. VOID
  96. MixerDataWrite(
  97. BYTE data
  98. )
  99. {
  100. // only voice and master volume implemented,
  101. // havent't found any apps using others
  102. switch(MixerState) {
  103. case MixerReset:
  104. ResetMixer();
  105. break;
  106. case MixerMasterVolume:
  107. MixerSettings.MasterVolume = data;
  108. MixerSetMasterVolume(data);
  109. break;
  110. case MixerFMVolume:
  111. MixerSettings.FMVolume = data;
  112. break;
  113. case MixerCDVolume:
  114. MixerSettings.CDVolume = data;
  115. break;
  116. case MixerVoiceVolume:
  117. MixerSettings.VoiceVolume = data;
  118. MixerSetVoiceVolume(data);
  119. break;
  120. }
  121. }
  122. /*
  123. * Reset the mixer to initial values.
  124. */
  125. VOID
  126. ResetMixer(
  127. VOID
  128. )
  129. {
  130. MixerSettings.MasterVolume = 0x08; // set to level 4
  131. MixerSetMasterVolume(0x08);
  132. MixerSettings.FMVolume = 0x08; // set to level 4
  133. MixerSettings.CDVolume = 0x00; // set to level 0
  134. MixerSettings.VoiceVolume = 0x04; // set to level 2
  135. MixerSetVoiceVolume(0x04);
  136. MixerState = MixerReset;
  137. }
  138. /***************************************************************************/
  139. /*
  140. * Set master volume.
  141. */
  142. VOID
  143. MixerSetMasterVolume(
  144. BYTE level
  145. )
  146. {
  147. ULONG volume = 0;
  148. level = level >> 1;
  149. level = level & 0x07;
  150. volume = level*0x2492; // 0xFFFF/7 = 0x2492
  151. volume = volume + (volume<<16);
  152. }
  153. /***************************************************************************/
  154. /*
  155. * Set volume of wave out device.
  156. */
  157. VOID
  158. MixerSetVoiceVolume(
  159. BYTE level
  160. )
  161. {
  162. ULONG volume = 0;
  163. level = level >> 1;
  164. level = level & 0x03;
  165. volume = level*0x5555; // 0xFFFF/3 = 0x5555
  166. volume = volume + (volume<<16);
  167. SetVolumeProc(HWaveOut, volume);
  168. }