ReactOS  0.4.15-dev-1207-g698a8e6
mixer.c
Go to the documentation of this file.
1 /*
2  ReactOS Sound System
3  Sound Blaster DSP support
4  Mixer routines
5 
6  Author:
7  Andrew Greenwood (silverblade@reactos.org)
8 
9  History:
10  2 July 2008 - Created
11 
12  Notes:
13  Functions documented in sbdsp.h
14 
15  Currently, input/output switches and PC speaker volume
16  level are not supported.
17 
18  The I/O switches are used for muting/unmuting mic, etc.
19 */
20 
21 #include "precomp.h"
22 
23 VOID
25 {
27  /* Are we meant to send anything else? */
28 }
29 
32  IN UCHAR Line,
33  IN UCHAR Level,
34  OUT PUCHAR PackedLevel)
35 {
36  if ( ! PackedLevel )
38 
39  switch ( Line )
40  {
51  case SB_MIX_MIC_LEVEL :
52  case SB_MIX_LEGACY_MIC_LEVEL : /* is this correct? */
53  {
54  if ( Level >= 0x20 )
56 
57  *PackedLevel = Level << 3;
58  return STATUS_SUCCESS;
59  }
60 
65  {
66  if ( Level >= 0x04 )
68 
69  *PackedLevel = Level << 6;
70  return STATUS_SUCCESS;
71  }
72 
73  case SB_MIX_VOC_LEVEL : /* legacy */
74  case SB_MIX_MASTER_LEVEL :
75  case SB_MIX_FM_LEVEL :
76  case SB_MIX_CD_LEVEL :
77  case SB_MIX_LINE_LEVEL :
78  case SB_MIX_TREBLE_LEFT_LEVEL : /* bass/treble */
82  {
83  if ( Level >= 0x10 )
85 
86  *PackedLevel = Level << 4;
87  return STATUS_SUCCESS;
88  }
89 
90  default :
92  };
93 }
94 
97  IN UCHAR Line,
98  IN UCHAR PackedLevel,
100 {
101  if ( ! Level )
103 
104  switch ( Line )
105  {
108  case SB_MIX_VOC_LEFT_LEVEL :
112  case SB_MIX_CD_LEFT_LEVEL :
113  case SB_MIX_CD_RIGHT_LEVEL :
116  case SB_MIX_MIC_LEVEL :
117  {
118  *Level = PackedLevel >> 3;
119  return STATUS_SUCCESS;
120  }
121 
126  {
127  *Level = PackedLevel >> 6;
128  return STATUS_SUCCESS;
129  }
130 
131  case SB_MIX_VOC_LEVEL : /* legacy */
132  case SB_MIX_MASTER_LEVEL :
133  case SB_MIX_FM_LEVEL :
134  case SB_MIX_CD_LEVEL :
135  case SB_MIX_LINE_LEVEL :
136  case SB_MIX_TREBLE_LEFT_LEVEL : /* bass/treble */
140  {
141  *Level = PackedLevel >> 4;
142  return STATUS_SUCCESS;
143  }
144 
145  default :
147  };
148 }
149 
150 NTSTATUS
152  IN PUCHAR BasePort,
153  IN UCHAR Line,
154  IN UCHAR Level)
155 {
156  UCHAR PackedLevel = 0;
158 
159  Status = SbMixerPackLevelData(Line, Level, &PackedLevel);
160 
161  switch ( Status )
162  {
163  case STATUS_SUCCESS :
164  break;
165 
168 
171 
172  default :
173  return Status;
174  };
175 
176  DbgPrint("SbMixerSetLevel: Line 0x%x, raw level 0x%x, packed 0x%x\n", Line, Level, PackedLevel);
177 
178  WRITE_SB_MIXER_REGISTER(BasePort, Line);
179  WRITE_SB_MIXER_DATA(BasePort, PackedLevel);
180 
181  return STATUS_SUCCESS;
182 }
183 
184 NTSTATUS
186  IN PUCHAR BasePort,
187  IN UCHAR Line,
188  OUT PUCHAR Level)
189 {
190  UCHAR PackedLevel = 0;
192 
193  if ( ! Level )
195 
196  WRITE_SB_MIXER_REGISTER(BasePort, Line);
197  PackedLevel = READ_SB_MIXER_DATA(BasePort);
198 
199  Status = SbMixerUnpackLevelData(Line, PackedLevel, Level);
200 
201  switch ( Status )
202  {
203  case STATUS_SUCCESS :
204  break;
205 
208 
211 
212  default :
213  return Status;
214  };
215 
216  DbgPrint("SbMixerGetLevel: Line 0x%x, raw level 0x%x, packed 0x%x\n", Line, Level, PackedLevel);
217 
218  return STATUS_SUCCESS;
219 }
220 
221 VOID
223 {
224  /* Untested... */
226  WRITE_SB_MIXER_DATA(BasePort, 1);
227 }
228 
229 VOID
231 {
232  /* Untested... */
234  WRITE_SB_MIXER_DATA(BasePort, 0);
235 }
236 
237 BOOLEAN
239 {
240  /* Untested... */
242  return (READ_SB_MIXER_DATA(BasePort) != 0);
243 }
#define SB_MIX_VOC_LEFT_LEVEL
Definition: sbdsp.h:96
#define IN
Definition: typedefs.h:39
#define SB_MIX_LEGACY_MIC_LEVEL
Definition: sbdsp.h:84
#define SB_MIX_LINE_LEVEL
Definition: sbdsp.h:88
#define DbgPrint
Definition: loader.c:25
unsigned char * PUCHAR
Definition: retypes.h:3
#define SB_MIX_RESET
Definition: sbdsp.h:93
#define SB_MIX_CD_LEFT_LEVEL
Definition: sbdsp.h:100
LONG NTSTATUS
Definition: precomp.h:26
#define SB_MIX_MASTER_RIGHT_LEVEL
Definition: sbdsp.h:95
#define SB_MIX_MASTER_LEVEL
Definition: sbdsp.h:85
#define SB_MIX_BASS_LEFT_LEVEL
Definition: sbdsp.h:116
#define SB_MIX_LINE_RIGHT_LEVEL
Definition: sbdsp.h:103
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
#define SB_MIX_OUTPUT_RIGHT_GAIN
Definition: sbdsp.h:112
#define SB_MIX_CD_LEVEL
Definition: sbdsp.h:87
VOID SbMixerEnableAGC(IN PUCHAR BasePort)
Definition: mixer.c:222
#define SB_MIX_TREBLE_LEFT_LEVEL
Definition: sbdsp.h:114
NTSTATUS SbMixerGetLevel(IN PUCHAR BasePort, IN UCHAR Line, OUT PUCHAR Level)
Definition: mixer.c:185
NTSTATUS SbMixerUnpackLevelData(IN UCHAR Line, IN UCHAR PackedLevel, OUT PUCHAR Level)
Definition: mixer.c:96
#define SB_MIX_CD_RIGHT_LEVEL
Definition: sbdsp.h:101
#define WRITE_SB_MIXER_DATA(bp, x)
Definition: sbdsp.h:45
#define SB_MIX_MIC_LEVEL
Definition: sbdsp.h:104
#define SB_MIX_OUTPUT_LEFT_GAIN
Definition: sbdsp.h:111
#define SB_MIX_TREBLE_RIGHT_LEVEL
Definition: sbdsp.h:115
#define SB_MIX_FM_LEVEL
Definition: sbdsp.h:86
#define STATUS_INVALID_PARAMETER_3
Definition: ntstatus.h:477
#define SB_MIX_INPUT_RIGHT_GAIN
Definition: sbdsp.h:110
#define SB_MIX_VOC_RIGHT_LEVEL
Definition: sbdsp.h:97
#define SB_MIX_INPUT_LEFT_GAIN
Definition: sbdsp.h:109
unsigned char BOOLEAN
#define WRITE_SB_MIXER_REGISTER(bp, x)
Definition: sbdsp.h:43
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
#define READ_SB_MIXER_DATA(bp)
Definition: sbdsp.h:44
#define SB_MIX_MIDI_LEFT_LEVEL
Definition: sbdsp.h:98
Definition: ncftp.h:79
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define SB_MIX_MIDI_RIGHT_LEVEL
Definition: sbdsp.h:99
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
NTSTATUS SbMixerPackLevelData(IN UCHAR Line, IN UCHAR Level, OUT PUCHAR PackedLevel)
Definition: mixer.c:31
#define SB_MIX_VOC_LEVEL
Definition: sbdsp.h:83
#define SB_MIX_AGC
Definition: sbdsp.h:113
NTSTATUS SbMixerSetLevel(IN PUCHAR BasePort, IN UCHAR Line, IN UCHAR Level)
Definition: mixer.c:151
#define SB_MIX_MASTER_LEFT_LEVEL
Definition: sbdsp.h:94
BOOLEAN SbMixerIsAGCEnabled(IN PUCHAR BasePort)
Definition: mixer.c:238
#define SB_MIX_BASS_RIGHT_LEVEL
Definition: sbdsp.h:117
#define OUT
Definition: typedefs.h:40
VOID SbMixerReset(IN PUCHAR BasePort)
Definition: mixer.c:24
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define SB_MIX_LINE_LEFT_LEVEL
Definition: sbdsp.h:102
VOID SbMixerDisableAGC(IN PUCHAR BasePort)
Definition: mixer.c:230