Sound Blaster 16


Introduction
Overview
IO Ports
Resetting the DSP
Available Modes
Class Functions
AutoDetecting Settings
DSP Commands
Sound Playback Ability
Examples
Download the PDF Version!


















Introduction


I definitely encourage you to read or print all of this document. This data has changed the way not only how I look at hardware, but it also has given me the courage to say "screw that driver, I'll just program the hardware directly!" I have no idea how you ended up here, but let me say that we share the same pain and torment of using insufficient drivers and functions. Sometimes we just have to do things ourselves! This document goes hand in hand with the sound programming doc. Together you can build a Real-time Sound FX Mixing Machine!


Overview


If you are unfamiliar with programming hardware, then this section should be able to shed a little light on the mystery. Basically we are going to figure out information about the available sound card, given it is either a true Sound Blaster or a compatible card. With this information we can deduce what functions are available for us to use. From there we will begin to initialize the card and perform some simple functions using a mixture of outport (outp) commands and some additional information we get from the card itself. Specifically we know that the hardware uses a base io port that is given to us. Additions to that port number are the location of other ports specific to the SB. Maybe this will shed some light.
IO Ports
Later we will experiment with some different kinds of playback and sharpen our programming skills to manipulate the sound card the way WE want to :)


AutoDetecting SB Settings


Autodetecting is really kind of a cheap trick. We aren't doing any fancy hardware checking or any system checking. All we have to do is grab a system variable name BLASTER. Each Sound Blaster card has this system variable set in the autoexec.bat file. By grabbing this string and going through its various sections, we can get all the information we need to talk to the card.

Resetting the DSP


In order to reset the DSP we have to write a 1 to the RESET port, wait a few milliseconds and then write a 0 to the RESET port. After this we proceed to poll the DSPREAD port to see if it gives us the OK (DSP_READY signal). Immediately afterward we can request that the DSP give us its major and minor version numbers.


Available Modes


The DSP Version of your Sound Blaster card is the determining factor as to how you can output sound on the Sound Blaster. With the release of version 4.0+ programming has gotten a lot easier and a pretty wide variety of playback modes are supported, including 16 bit Stereo Auto Init playback! The following is a quick listing of all available modes and their appropriate DSP versions.

DMA Operation Mode 1.xx2.002.01+3.xx4.xx
8 Bit Mono PCM Single Cycle
8 Bit Mono PCM Auto-Init
8 Bit Mono ADPCM Single Cycle
8 Bit Mono ADPCM Auto-Init
8 Bit Mono High Speed PCM Single Cycle
8 Bit Mono High Speed PCM Auto-Init
8 Bit Stereo High Speed PCM Single Cycle
8 Bit Stereo High Speed PCM Auto-Init
8/16 Bit Mono PCM Single Cycle
8/16 Bit Mono PCM Auto-Init
8/16 Bit Stereo PCM Single Cycle
8/16 Bit Stereo PCM Auto-Init




Sound Playback Ability


Here's a listing of what playback rates are available on which DSP versions!

DSP VersionTransfer ModeFormatSampling Range
4.xxMono8 bit unsigned5000 to 44100 Hz
Mono16 bit unsigned5000 to 44100 Hz
Stereo8 bit unsigned5000 to 44100 Hz
Stereo16 bit unsigned5000 to 44100 Hz
3.xxMono8 bit unsigned4000 to 23000 Hz
Mono/High Speed8 bit unsigned23000 to 44100 Hz
Stereo/High Speed8 bit unsigned11025 to 22050
2.01+Mono8 bit unsigned4000 to 23000 Hz
Mono/High Speed8 bit unsigned23000 to 44100 Hz
2.00 and 1.xxMono8 bit unsigned4000 to 23000 Hz
ALLMono8 bit to 4 bit ADPCM4000 to 12000 Hz
ALLMono8 bit to 3 bit ADPCM4000 to 13000 Hz
ALLMono8 bit to 2 bit ADPCM4000 to 11000 Hz




IO Port Listing

IO Address
Description
Access
Base + 0h FM Music Status Port
Read
Base + 0h FM Music Register Address Port
Write
Base + 1h FM Music Data Port
Write Only
Base + 2h Advanced FM Music Status Port
Read
Base + 2h Advanced FM Music Register Address Port
Write
Base + 3h Advanced FM Music Data Port
Write Only
Base + 4h Mixer Chip Register Address Port
Write Only
Base + 5h Mixer Chip Data Port
Read / Write
Base + 6h DSP Reset
Write Only
Base + 8h FM Music Status Port
Read
Base + 8h FM Music Register Port
Write
Base + 9h FM Music Data Port Write Only
Base + Ah DSP Read Data Port Read Only
Base + Ch DSP Write Command/Data Write
Base + Ch DSP Write Buffer Status (Bit 7) Read
Base + Eh DSP Read Buffer Status (Bit 7) Read Only
Base + 10h CD-ROM Command or Data Register Read / Write
Base + 11h CD-ROM Status Register Read Only
Base + 12h CD-ROM Reset Register Write Only
Base + 13h CD-ROM Enable Register Write ONly


Base Address Memory Regions Used
220h 220h to 233h
240h 240h to 253h
260h 260h to 273h
280h 280h to 293h




DSP Command Listing (Only relevant modes displayed)

10h____8-bit Direct mode single byte digitized sound output
Input
: 10h, Data (1 byte)
Notes : The user is responsible for calling this function at a relivant frequency. The user has to call this function and immediately follow it with the unsigned byte. Repeat this process until the end of the sound.

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
Yes Yes Yes Yes Yes


14h____8-bit Single-Cycle DMA mode digitized sound output
Input
: 14h, LoByte(length-1), HiByte(length-1)Data (1 byte)
Notes : length is 1 WORD in length and is the number of 8-bit samples to be played.

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
Yes Yes Yes Yes Yes


1Ch____8-bit Auto-Init DMA mode digitized sound output
Input
: 1Ch Notes :There are 2 ways of stopping Auto-Init Mode:
1) Switch to Single-Cycle DMA mode. The DSP after finishing its current block will process this command.
2) Send the exit Auto-Init mode command.(DAh)

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
No Yes Yes Yes Yes


20h____8-bit Direct mode single byte digitized sound input
Input
: 20h Notes :The procedure to fetch data from the card is to 1)send command 0x20, 2) read a byte of digitized data from the DSP, 3) wait for the correct time period and repeat steps 1&2.

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
Yes Yes Yes Yes Yes


24h____8bit Single Cycle DMA mode digitiezed sound input
Input
: 24h,Lo(length-1),Hi(length-1)
Notes : Length is a word giving the number of 8-bit samples.

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
Yes Yes Yes Yes Yes


2Ch____8-bit Auto-Init DMA mode digitized sound input
Input
: 2Ch
Notes : Send 2Ch and GO!

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
No Yes Yes Yes Yes


40h____Set digitized sound transfer Time Constant
Input
: 40h,TimeConst
Notes : TimeConst is calculated as follows:
TimeConst=65536 - (256 000 000/(channels * sampling rate))
channels is 1 for mono, and 2 for stereo. Only the high byte is sent to the DSP.
Availability
1.xx 2.00 2.01+ 3.xx 4.xx
Yes Yes Yes Yes Yes


41h____Set digitized sound output sampling rate
Input
: 41h,Hi(Sr),Lo(Sr)
Notes : Sr is the raw sampling rate from 5khz -> 45khz

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
No No No No Yes


42h____Set digitized sound input sample rate
Input
: 42h,Hi(Sr),Lo(Sr)
Notes : See 41h

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
No No No No Yes


48h____Set DSP block transfer size
Input
: 48h, Lo(Bs-1),Hi(Bs-1)
Notes : The DSP will generate an interrupt after each block of size Bs has been transfered. This command is used in high speed mode I/O and Auto-Init mode I/O

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
No Yes Yes Yes Yes


80h____Pause DAC for a duration
Input
: 80h,Lo(Time-1),Hi(Time-1)
Notes : Time is the number of sampling periods. After the DAC has restarted it will generate an interrupt.

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
Yes Yes Yes Yes Yes


D0h____Pause 8-bit DMA mode digitizes sound output
Input
: D0h
Notes : This will make the DSP to stop sending DMA requests. Continue output with command D4h.

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
Yes Yes Yes Yes Yes


D1h____Turn on the speaker
Input
: D1h
Notes : On version 1.xx, the DSP will pause after executing this command. With version 4.xx, this serves only to set the speaker on/off flag so that the command D8 (get speaker status) works correctly. Command D3 will turn off the speaker.

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
Yes Yes Yes Yes Yes


D8h____Get Speaker Status
Input
: D8h
Notes : After sending this command, read a byte from the DSP. A value of FFh indicates that the speaker is on, and 00h that it is off.

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
No Yes Yes Yes Yes


E1h____Get DSP Version Number
Input
: E1h
Notes : After sending this command, read 2 bytes from the DSP. The first is the major version number, and the second is the minor version. It has been my experience that this command has to be executed immediately after the DSP has been reset to work.

Availability
1.xx 2.00 2.01+ 3.xx 4.xx
Yes Yes Yes Yes Yes





Examples


Lesson 1 : Initilizing the DSP and Getting Environment Settings
Lesson 2 : Setting the Sound Blaster Mixer Levels
Lesson 3 : Reading the .Voc Format
Lesson 4 : Playback using Direct Mode
Lesson 5 : Playback using Single Cycle Mode
Lesson 6 : Playback using Auto-Init Mode

There are more examples that deal with the actual usage of the sound card, Lesson 6 is the last tutorial that deals with programming the card. The others teach the reader how to take that knowledge and build on it to achieve 3-d sound and special effects.