1 /*
2 ReactOS Sound System
3 Sound Blaster DSP support
4 Sample rate routines
5
6 Author:
7 Andrew Greenwood (silverblade@reactos.org)
8
9 History:
10 2 July 2008 - Created (split from sbdsp.c)
11
12 Notes:
13 Functions documented in sbdsp.h
14 */
15
16 #include "precomp.h"
17
18 BOOLEAN
SbDspIsValidInputRate(IN UCHAR MajorVersion,IN UCHAR MinorVersion,IN USHORT Rate,IN BOOLEAN Stereo)19 SbDspIsValidInputRate(
20 IN UCHAR MajorVersion,
21 IN UCHAR MinorVersion,
22 IN USHORT Rate,
23 IN BOOLEAN Stereo)
24 {
25 if ( MajorVersion == 1 )
26 {
27 if ( Stereo )
28 return FALSE;
29
30 return ( ( Rate >= 4000 ) && ( Rate <= 13000 ) );
31 }
32 else if ( MajorVersion == 2 )
33 {
34 if ( Stereo )
35 return FALSE;
36
37 if ( MinorVersion == 0 )
38 return ( ( Rate >= 4000 ) && ( Rate <= 15000 ) );
39 else
40 return ( ( Rate >= 4000 ) && ( Rate <= 44100 ) );
41 }
42 else if ( MajorVersion == 3 )
43 {
44 if ( Stereo )
45 return FALSE;
46
47 return ( ( Rate >= 4000 ) && ( Rate <= 13000 ) );
48 }
49 else /* 4.00 and above */
50 {
51 return ( ( Rate >= 5000 ) && ( Rate <= 44100 ) );
52 }
53 }
54
55 BOOLEAN
SbDspIsValidOutputRate(IN UCHAR MajorVersion,IN UCHAR MinorVersion,IN USHORT Rate,IN BOOLEAN Stereo)56 SbDspIsValidOutputRate(
57 IN UCHAR MajorVersion,
58 IN UCHAR MinorVersion,
59 IN USHORT Rate,
60 IN BOOLEAN Stereo)
61 {
62 if ( MajorVersion == 1 )
63 {
64 if ( Stereo )
65 return FALSE;
66
67 return ( ( Rate >= 4000 ) && ( Rate <= 23000 ) );
68 }
69 else if ( MajorVersion == 2 )
70 {
71 if ( Stereo )
72 return FALSE;
73
74 if ( MinorVersion == 0 )
75 return ( ( Rate >= 4000 ) && ( Rate <= 23000 ) );
76 else
77 return ( ( Rate >= 4000 ) && ( Rate <= 44100 ) );
78 }
79 else if ( MajorVersion == 3 )
80 {
81 if ( ! Stereo )
82 return ( ( Rate >= 4000 ) && ( Rate <= 44100 ) );
83 else
84 return ( ( Rate >= 11025 ) && ( Rate <= 22050 ) );
85 }
86 else /* 4.00 and above */
87 {
88 return ( ( Rate >= 5000 ) && ( Rate <= 44100 ) );
89 }
90 }
91
92 /* Internal routine - call only after submitting one of the rate commands */
93 NTSTATUS
SbDsp4WriteRate(IN PUCHAR BasePort,IN USHORT Rate,IN ULONG Timeout)94 SbDsp4WriteRate(
95 IN PUCHAR BasePort,
96 IN USHORT Rate,
97 IN ULONG Timeout)
98 {
99 NTSTATUS Status;
100
101 /* NOTE - No check for validity of rate! */
102
103 /* Write high byte */
104 Status = SbDspWrite(BasePort, (Rate & 0xff00) >> 8, Timeout);
105 if ( Status != STATUS_SUCCESS )
106 return Status;
107
108 /* Write low byte */
109 Status = SbDspWrite(BasePort, Rate & 0xff, Timeout);
110 if ( Status != STATUS_SUCCESS )
111 return Status;
112
113 return Status;
114 }
115
116 NTSTATUS
SbDsp4SetOutputRate(IN PUCHAR BasePort,IN USHORT Rate,IN ULONG Timeout)117 SbDsp4SetOutputRate(
118 IN PUCHAR BasePort,
119 IN USHORT Rate,
120 IN ULONG Timeout)
121 {
122 NTSTATUS Status;
123
124 /* NOTE - No check for validity of rate! */
125
126 /* Prepare to write the output rate */
127 Status = SbDspWrite(BasePort, SB_DSP_OUTPUT_RATE, (Rate & 0xff00) >> 8);
128 if ( Status != STATUS_SUCCESS )
129 return Status;
130
131 return SbDsp4WriteRate(BasePort, Rate, Timeout);
132 }
133
134 NTSTATUS
SbDsp4SetInputRate(IN PUCHAR BasePort,IN USHORT Rate,IN ULONG Timeout)135 SbDsp4SetInputRate(
136 IN PUCHAR BasePort,
137 IN USHORT Rate,
138 IN ULONG Timeout)
139 {
140 NTSTATUS Status;
141
142 /* NOTE - No check for validity of rate! */
143
144 /* Prepare to write the input rate */
145 Status = SbDspWrite(BasePort, SB_DSP_OUTPUT_RATE, (Rate & 0xff00) >> 8);
146 if ( Status != STATUS_SUCCESS )
147 return Status;
148
149 return SbDsp4WriteRate(BasePort, Rate, Timeout);
150 }
151
152