Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencontrol.c
Go to the documentation of this file.
00001 #include <sndblst.h> 00002 00003 /* 00004 TODO: MmMapIoSpace() 00005 */ 00006 00007 /* 00008 This checks the read or write status port of the device. 00009 */ 00010 00011 BOOLEAN 00012 WaitForReady( 00013 PSOUND_BLASTER_PARAMETERS SBDevice, 00014 UCHAR Port) 00015 { 00016 ULONG timeout = SB_TIMEOUT; 00017 BOOL ready = FALSE; 00018 00019 while ( ( ! ready ) && ( timeout > 0 ) ) 00020 { 00021 if ( SbRead(SBDevice, Port) & 0x80 ) 00022 return TRUE; 00023 00024 timeout --; 00025 } 00026 00027 return FALSE; 00028 } 00029 00030 BOOLEAN 00031 SbWriteData( 00032 PSOUND_BLASTER_PARAMETERS SBDevice, 00033 UCHAR Data) 00034 { 00035 if ( ! WaitToWrite(SBDevice) ) 00036 return FALSE; 00037 00038 DPRINT("Writing 0x%x to Sound Blaster card (data)\n", Data); 00039 SbWrite(SBDevice, SB_WRITE_DATA_PORT, Data); 00040 00041 return TRUE; 00042 } 00043 00044 BOOLEAN 00045 SbReadData( 00046 PSOUND_BLASTER_PARAMETERS SBDevice, 00047 PUCHAR Data) 00048 { 00049 if ( ! WaitToWrite(SBDevice) ) 00050 return FALSE; 00051 00052 *Data = SbRead(SBDevice, SB_READ_DATA_PORT); 00053 DPRINT("Read 0x%x from Sound Blaster card (data)\n", *Data); 00054 00055 return TRUE; 00056 } 00057 00058 BOOLEAN 00059 ResetSoundBlaster( 00060 PSOUND_BLASTER_PARAMETERS SBDevice) 00061 { 00062 BOOLEAN acked = FALSE; 00063 ULONG timeout; 00064 00065 SbWriteReset(SBDevice, 0x01); 00066 for (timeout = 0; timeout < 30000; timeout ++ ); 00067 SbWriteReset(SBDevice, 0x00); 00068 00069 DPRINT("Waiting for SB to acknowledge our reset request\n"); 00070 00071 if ( ! WaitToRead(SBDevice) ) 00072 { 00073 DPRINT("Didn't get an ACK :(\n"); 00074 return FALSE; 00075 } 00076 00077 timeout = 0; 00078 00079 while ( ( ! acked ) && ( timeout < SB_TIMEOUT ) ) 00080 { 00081 acked = ( SbReadDataWithoutWait(SBDevice) == SB_DSP_READY ); 00082 timeout ++; 00083 } 00084 00085 if ( ! acked ) 00086 { 00087 DPRINT("Didn't get an ACK :(\n"); 00088 return FALSE; 00089 } 00090 00091 return TRUE; 00092 } 00093 00094 ULONG 00095 GetSoundBlasterModel( 00096 PSOUND_BLASTER_PARAMETERS SBDevice) 00097 { 00098 UCHAR MajorVer, MinorVer; 00099 00100 DPRINT("Querying DSP version\n"); 00101 00102 if ( ! SbWriteData(SBDevice, SbGetDspVersion) ) 00103 return NotDetected; 00104 00105 if ( ! WaitToRead(SBDevice) ) 00106 return NotDetected; 00107 00108 if ( SbReadData(SBDevice, &MajorVer) ) 00109 { 00110 if ( SbReadData(SBDevice, &MinorVer) ) 00111 { 00112 DPRINT("Version %d.%d\n", MajorVer, MinorVer); 00113 00114 SBDevice->dsp_version = (MajorVer * 256) + MinorVer; 00115 00116 if ( SBDevice->dsp_version < 0x0200 ) 00117 return SoundBlaster; 00118 else if ( ( SBDevice->dsp_version & 0xFF00 ) == 0x0200 ) 00119 return SoundBlaster2; 00120 else if ( ( SBDevice->dsp_version & 0xFF00 ) == 0x0300 ) 00121 return SoundBlasterPro; 00122 else if ( SBDevice->dsp_version >= 0x0400 ) 00123 return SoundBlaster16; 00124 00125 return NotDetected; 00126 } 00127 } 00128 00129 return NotDetected; 00130 } 00131 00132 00133 BOOLEAN 00134 IsSampleRateCompatible( 00135 PSOUND_BLASTER_PARAMETERS SBDevice, 00136 ULONG SampleRate) 00137 { 00138 /* TODO */ 00139 return TRUE; 00140 } 00141 00142 BOOLEAN 00143 SetOutputSampleRate( 00144 PSOUND_BLASTER_PARAMETERS SBDevice, 00145 ULONG SampleRate) 00146 { 00147 /* Only works for DSP v4.xx */ 00148 DPRINT("Setting sample rate\n"); 00149 00150 SbWriteData(SBDevice, SbSetOutputRate); 00151 SbWriteData(SBDevice, SampleRate / 256); 00152 SbWriteData(SBDevice, SampleRate % 256); 00153 00154 return TRUE; 00155 } 00156 00157 BOOLEAN 00158 EnableSpeaker( 00159 PSOUND_BLASTER_PARAMETERS SBDevice) 00160 { 00161 DPRINT("Enabling speaker\n"); 00162 00163 return SbWriteData(SBDevice, SbEnableSpeaker); 00164 } 00165 00166 BOOLEAN 00167 DisableSpeaker( 00168 PSOUND_BLASTER_PARAMETERS SBDevice) 00169 { 00170 DPRINT("Disabling speaker\n"); 00171 00172 return SbWriteData(SBDevice, SbDisableSpeaker); 00173 } 00174 00175 BOOLEAN 00176 StartSoundOutput( 00177 PSOUND_BLASTER_PARAMETERS SBDevice, 00178 ULONG BitDepth, 00179 ULONG Channels, 00180 ULONG BlockSize) 00181 { 00182 DPRINT("Initializing output with %d channels at %d bits/sample\n", Channels, BitDepth); 00183 00184 UCHAR command = 0xc6, mode = 0x00; 00185 00186 if ( ( Channels < 1 ) || ( Channels > 2 ) ) 00187 return FALSE; 00188 00189 if ( ( BitDepth != 8 ) && ( BitDepth != 16 ) ) 00190 return FALSE; 00191 00192 switch ( BitDepth ) 00193 { 00194 case 8 : command = 0xc6; break; 00195 case 16 : command = 0xb6; break; 00196 }; 00197 00198 switch ( Channels ) 00199 { 00200 case 1 : mode = 0x00; break; 00201 case 2 : mode = 0x20; break; 00202 } 00203 #if 0 00204 first_byte = (BitDepth == 16) ? 0xb6 : 0xc6; 00205 second_byte = (Channels == 1) ? 0x20 : 0x00; 00206 #endif 00207 00208 if ( SBDevice->dsp_version < 0x0400 ) 00209 { 00210 /* TODO: Additional programming required */ 00211 } 00212 00213 /* Send freq */ 00214 SbWriteData(SBDevice, command); 00215 SbWriteData(SBDevice, mode); 00216 SbWriteData(SBDevice, BlockSize % 256); 00217 SbWriteData(SBDevice, BlockSize / 256); 00218 00219 DPRINT("Finished programming the DSP\n"); 00220 00221 return TRUE; 00222 } Generated on Sun May 27 2012 04:16:33 for ReactOS by
1.7.6.1
|