Author: silverblade
Date: Tue Jul 1 18:02:07 2008
New Revision: 34244
URL:
http://svn.reactos.org/svn/reactos?rev=34244&view=rev
Log:
Fixed some bugs in previous commit, implemented validation of sample rate.
Modified:
branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/main.c
branches/silverblade-audio/include/reactos/libs/sound/sbdsp.h
branches/silverblade-audio/lib/drivers/sound/sbdsp.c
Modified: branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/main.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/drivers/multi…
==============================================================================
--- branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/main.c [iso-8859-1]
(original)
+++ branches/silverblade-audio/drivers/multimedia/audio/sb16_nt4/main.c [iso-8859-1] Tue
Jul 1 18:02:07 2008
@@ -171,46 +171,46 @@
DbgPrint("Resetting Sound Blaster DSP at 0x220\n");
result = SbDspReset((PUCHAR)0x220, SB_DEFAULT_TIMEOUT);
DbgPrint("Reset was %s\n",
- NT_SUCCESS(result) ? "successful" : "unsuccessful");
+ result == STATUS_SUCCESS ? "successful" :
"unsuccessful");
/* 0x240, we don't expect to work */
DbgPrint("Resetting Sound Blaster DSP at 0x240\n");
result = SbDspReset((PUCHAR)0x240, SB_DEFAULT_TIMEOUT);
DbgPrint("Reset was %s\n",
- NT_SUCCESS(result) ? "successful" : "unsuccessful");
+ result == STATUS_SUCCESS ? "successful" :
"unsuccessful");
/* Try getting version */
DbgPrint("Retrieving Sound Blaster version...\n");
result = SbDspGetVersion((PUCHAR)0x220, &major, &minor, SB_DEFAULT_TIMEOUT);
DbgPrint("Version retrival was %s\n",
- NT_SUCCESS(result) ? "successful" : "unsuccessful");
+ result == STATUS_SUCCESS ? "successful" :
"unsuccessful");
DbgPrint("Sound Blaster DSP version is %d.%02d\n", major, minor);
result = SbDspIsSpeakerEnabled((PUCHAR)0x220, &speaker_state,
SB_DEFAULT_TIMEOUT);
DbgPrint("Speaker state retrieval %s\n",
- NT_SUCCESS(result) ? "succeeded" : "failed");
+ result == STATUS_SUCCESS ? "succeeded" : "failed");
DbgPrint("Speaker state is presently %s\n",
speaker_state ? "ENABLED" : "DISABLED");
result = SbDspEnableSpeaker((PUCHAR)0x220, SB_DEFAULT_TIMEOUT);
DbgPrint("Speaker enable request %s\n",
- NT_SUCCESS(result) ? "succeeded" : "failed");
+ result == STATUS_SUCCESS ? "succeeded" : "failed");
result = SbDspIsSpeakerEnabled((PUCHAR)0x220, &speaker_state,
SB_DEFAULT_TIMEOUT);
DbgPrint("Speaker state retrieval %s\n",
- NT_SUCCESS(result) ? "succeeded" : "failed");
+ result == STATUS_SUCCESS ? "succeeded" : "failed");
DbgPrint("Speaker state is now %s\n",
speaker_state ? "ENABLED" : "DISABLED");
result = SbDspDisableSpeaker((PUCHAR)0x220, SB_DEFAULT_TIMEOUT);
DbgPrint("Speaker disable request %s\n",
- NT_SUCCESS(result) ? "succeeded" : "failed");
+ result == STATUS_SUCCESS ? "succeeded" : "failed");
result = SbDspIsSpeakerEnabled((PUCHAR)0x220, &speaker_state,
SB_DEFAULT_TIMEOUT);
DbgPrint("Speaker state retrieval %s\n",
- NT_SUCCESS(result) ? "succeeded" : "failed");
+ result == STATUS_SUCCESS ? "succeeded" : "failed");
DbgPrint("Speaker state is now %s\n",
speaker_state ? "ENABLED" : "DISABLED");
Modified: branches/silverblade-audio/include/reactos/libs/sound/sbdsp.h
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/include/react…
==============================================================================
--- branches/silverblade-audio/include/reactos/libs/sound/sbdsp.h [iso-8859-1] (original)
+++ branches/silverblade-audio/include/reactos/libs/sound/sbdsp.h [iso-8859-1] Tue Jul 1
18:02:07 2008
@@ -15,7 +15,19 @@
#ifndef ROS_SOUND_SBDSP_H
#define ROS_SOUND_SBDSP_H
-#include <sound/time.h>
+/*
+ Product versions
+ DSP 1.0, 1.5, 2.0, 2.01 correspond with respective Sound Blaster versions.
+ DSP 3.xx is Sound Blaster Pro
+ DSP 4.xx is Sound Blaster 16
+*/
+
+#define SOUND_BLASTER_1_0 L"Sound Blaster 1.0"
+#define SOUND_BLASTER_1_5 L"Sound Blaster 1.5"
+#define SOUND_BLASTER_2_0 L"Sound Blaster 2.0"
+#define SOUND_BLASTER_PRO L"Sound Blaster Pro"
+#define SOUND_BLASTER_16 L"Sound Blaster 16"
+
/*
Sound Blaster ports I/O
@@ -155,19 +167,33 @@
IN ULONG Timeout);
/*
- Validate the sample rate
- * DSP 4.xx only
+ Validate the input sample rate. The major and minor versions are required
+ to determine the capabilities of the card.
*/
BOOLEAN
-SbDspIsValidRate(
- IN USHORT Rate);
+SbDspIsValidInputRate(
+ IN UCHAR MajorVersion,
+ IN UCHAR MinorVersion,
+ IN USHORT Rate,
+ IN BOOLEAN Stereo);
+
+/*
+ Validate the output sample rate. The major and minor versions are required
+ to determine the capabilities of the card.
+*/
+BOOLEAN
+SbDspIsValidOutputRate(
+ IN UCHAR MajorVersion,
+ IN UCHAR MinorVersion,
+ IN USHORT Rate,
+ IN BOOLEAN Stereo);
/*
Set the output/playback rate
* DSP 4.xx only
*/
NTSTATUS
-SbDspSetOutputRate(
+SbDsp4SetOutputRate(
IN PUCHAR BasePort,
IN USHORT Rate,
IN ULONG Timeout);
@@ -177,7 +203,7 @@
* DSP 4.xx only
*/
NTSTATUS
-SbDspSetInputRate(
+SbDsp4SetInputRate(
IN PUCHAR BasePort,
IN USHORT Rate,
IN ULONG Timeout);
Modified: branches/silverblade-audio/lib/drivers/sound/sbdsp.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/sbdsp.c [iso-8859-1] (original)
+++ branches/silverblade-audio/lib/drivers/sound/sbdsp.c [iso-8859-1] Tue Jul 1 18:02:07
2008
@@ -109,7 +109,7 @@
Status = SbDspWaitToWrite(BasePort, Timeout);
- if ( ! NT_SUCCESS(Status) )
+ if ( Status != STATUS_SUCCESS )
{
return Status;
}
@@ -135,7 +135,7 @@
Status = SbDspWaitToRead(BasePort, Timeout);
- if ( ! NT_SUCCESS(Status) )
+ if ( Status != STATUS_SUCCESS )
{
return Status;
}
@@ -164,12 +164,12 @@
/* Send version request */
Status = SbDspWrite(BasePort, SB_DSP_VERSION, Timeout);
- if ( ! NT_SUCCESS(Status) )
+ if ( Status != STATUS_SUCCESS )
return Status;
/* Get the major version */
Status = SbDspRead(BasePort, MajorVersion, Timeout);
- if ( ! NT_SUCCESS(Status) )
+ if ( Status != STATUS_SUCCESS )
return FALSE;
/* Get the minor version */
@@ -194,10 +194,7 @@
}
/*
- BUG?
- It seems under VirtualBox this returns 0x05, irrespective
- of the speaker state. I'm not sure if this will also occur
- on real hardware.
+ VirtualBox doesn't seem to support this.
*/
NTSTATUS
SbDspIsSpeakerEnabled(
@@ -213,12 +210,12 @@
/* Request the speaker status */
Status = SbDspWrite(BasePort, SB_DSP_SPEAKER_STATUS, Timeout);
- if ( ! NT_SUCCESS(Status) )
+ if ( Status != STATUS_SUCCESS )
return Status;
/* Obtain the status */
Status = SbDspRead(BasePort, &SpeakerStatus, Timeout);
- if ( ! NT_SUCCESS(Status) )
+ if ( Status != STATUS_SUCCESS )
return Status;
DbgPrint("SBDSP - SpeakerStatus is %02x\n", SpeakerStatus);
@@ -228,72 +225,135 @@
}
BOOLEAN
-SbDspIsValidRate(
- IN USHORT Rate)
-{
- /* Not sure if this range is 100% correct */
- return ( ( Rate >= 5000 ) && ( Rate <= 45000 ) );
+SbDspIsValidInputRate(
+ IN UCHAR MajorVersion,
+ IN UCHAR MinorVersion,
+ IN USHORT Rate,
+ IN BOOLEAN Stereo)
+{
+ if ( MajorVersion == 1 )
+ {
+ if ( Stereo )
+ return FALSE;
+
+ return ( ( Rate >= 4000 ) && ( Rate <= 13000 ) );
+ }
+ else if ( MajorVersion == 2 )
+ {
+ if ( Stereo )
+ return FALSE;
+
+ if ( MinorVersion == 0 )
+ return ( ( Rate >= 4000 ) && ( Rate <= 15000 ) );
+ else
+ return ( ( Rate >= 4000 ) && ( Rate <= 44100 ) );
+ }
+ else if ( MajorVersion == 3 )
+ {
+ if ( Stereo )
+ return FALSE;
+
+ return ( ( Rate >= 4000 ) && ( Rate <= 13000 ) );
+ }
+ else /* 4.00 and above */
+ {
+ return ( ( Rate >= 5000 ) && ( Rate <= 44100 ) );
+ }
+}
+
+BOOLEAN
+SbDspIsValidOutputRate(
+ IN UCHAR MajorVersion,
+ IN UCHAR MinorVersion,
+ IN USHORT Rate,
+ IN BOOLEAN Stereo)
+{
+ if ( MajorVersion == 1 )
+ {
+ if ( Stereo )
+ return FALSE;
+
+ return ( ( Rate >= 4000 ) && ( Rate <= 23000 ) );
+ }
+ else if ( MajorVersion == 2 )
+ {
+ if ( Stereo )
+ return FALSE;
+
+ if ( MinorVersion == 0 )
+ return ( ( Rate >= 4000 ) && ( Rate <= 23000 ) );
+ else
+ return ( ( Rate >= 4000 ) && ( Rate <= 44100 ) );
+ }
+ else if ( MajorVersion == 3 )
+ {
+ if ( ! Stereo )
+ return ( ( Rate >= 4000 ) && ( Rate <= 44100 ) );
+ else
+ return ( ( Rate >= 11025 ) && ( Rate <= 22050 ) );
+ }
+ else /* 4.00 and above */
+ {
+ return ( ( Rate >= 5000 ) && ( Rate <= 44100 ) );
+ }
}
/* Internal routine - call only after submitting one of the rate commands */
NTSTATUS
-SbDspWriteRate(
- IN PUCHAR BasePort,
- IN USHORT Rate,
- IN ULONG Timeout)
-{
- NTSTATUS Status;
-
- if ( ! SbDspIsValidRate(Rate) )
- return STATUS_INVALID_PARAMETER_2;
+SbDsp4WriteRate(
+ IN PUCHAR BasePort,
+ IN USHORT Rate,
+ IN ULONG Timeout)
+{
+ NTSTATUS Status;
+
+ /* NOTE - No check for validity of rate! */
/* Write high byte */
Status = SbDspWrite(BasePort, (Rate & 0xff00) >> 8, Timeout);
- if ( ! NT_SUCCESS(Status) )
+ if ( Status != STATUS_SUCCESS )
return Status;
/* Write low byte */
Status = SbDspWrite(BasePort, Rate & 0xff, Timeout);
- if ( ! NT_SUCCESS(Status) )
+ if ( Status != STATUS_SUCCESS )
return Status;
return Status;
}
NTSTATUS
-SbDspSetOutputRate(
- IN PUCHAR BasePort,
- IN USHORT Rate,
- IN ULONG Timeout)
-{
- NTSTATUS Status;
-
- if ( ! SbDspIsValidRate(Rate) )
- return STATUS_INVALID_PARAMETER_2;
+SbDsp4SetOutputRate(
+ IN PUCHAR BasePort,
+ IN USHORT Rate,
+ IN ULONG Timeout)
+{
+ NTSTATUS Status;
+
+ /* NOTE - No check for validity of rate! */
/* Prepare to write the output rate */
Status = SbDspWrite(BasePort, SB_DSP_OUTPUT_RATE, (Rate & 0xff00) >> 8);
- if ( ! NT_SUCCESS(Status) )
- return Status;
-
- return SbDspWriteRate(BasePort, Rate, Timeout);
-}
-
-NTSTATUS
-SbDspSetInputRate(
- IN PUCHAR BasePort,
- IN USHORT Rate,
- IN ULONG Timeout)
-{
- NTSTATUS Status;
-
- if ( ! SbDspIsValidRate(Rate) )
- return STATUS_INVALID_PARAMETER_2;
+ if ( Status != STATUS_SUCCESS )
+ return Status;
+
+ return SbDsp4WriteRate(BasePort, Rate, Timeout);
+}
+
+NTSTATUS
+SbDsp4SetInputRate(
+ IN PUCHAR BasePort,
+ IN USHORT Rate,
+ IN ULONG Timeout)
+{
+ NTSTATUS Status;
+
+ /* NOTE - No check for validity of rate! */
/* Prepare to write the input rate */
Status = SbDspWrite(BasePort, SB_DSP_OUTPUT_RATE, (Rate & 0xff00) >> 8);
- if ( ! NT_SUCCESS(Status) )
- return Status;
-
- return SbDspWriteRate(BasePort, Rate, Timeout);
-}
+ if ( Status != STATUS_SUCCESS )
+ return Status;
+
+ return SbDsp4WriteRate(BasePort, Rate, Timeout);
+}