Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
/* Code to playback an 8bit *.wav file */
#include <stdio.h>
#define PORT 0x220 /* Soundblaster Base Port, change to 0x240 or whatever */
/* for different hardware configuration */
void writedsp( int byte, int bp );
int samplebyte( int bp );
void sbreset( int bp );
unsigned long getspeed(void);
int main(void)
{
int delay, speed;
FILE *fp;
speed = getspeed();
printf ("Speed = %u\n", speed);
sbreset(PORT); /* Reset the Soundblaster card */
if( fp = fopen( "c:\\windows\\hal.wav","rb" ) )
{
printf( "Now Playing..." );
writedsp(0xD1, PORT); /* Turn speaker on */
while (feof(fp)== 0)
{
writedsp(0x10, PORT);
writedsp(fgetc(fp), PORT);
for (delay = 0 ; delay < speed; delay++) {;}
}
writedsp(0xD3, PORT); /* Turn speaker off */
}
else
{ printf( "Error in opening file\n" ); }
return 0;
}
void writedsp( int byte, int bp )
{
/* Writes to the Soundblaster's DSP Command Channel -
* call with bp% = SB base port (normally 0x220)
* byte = byte to write to DSP
*/
int t, dspcmd, x;
dspcmd = bp + 12;
for (t = 1; t < 8; t++)
{ x = inp(dspcmd); } /* Delay to give SB time to process code */
outp (dspcmd, byte);
}
int samplebyte( int bp )
{
/* Samples a byte from the SB's ADC, and returns
* the resultant byte. Call with BP = SB base port
* (normally 0x220)
*/
int port;
writedsp(0x20, bp); /* Command to sample one byte */
port = bp + 14;
while ( inp(port) & 0x80 == 0 ) {;}
port = bp + 10;
return (inp(port));
}
void sbreset( int bp )
{
/* Resets the Soundblaster chip -
* call with bp = Base Port (normally 0x220)
*/
int port, t, x;
port = bp + 6;
outp (port, 1);
for (t = 1; t < 10; t++)
{ x = inp(port); } /* Delay loop, give SB time to reset */
outp ( port, 0 );
port = bp + 10;
for (t = 1; t < 10; t++)
{ x = inp(port); }
}
unsigned long getspeed(void)
{
unsigned long temp, count = 0;
temp = clock() + 800;
while( (clock() < temp ) )
{ count++; }
return (count >> 4);
}