Sound Blaster 16: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
Line 55: Line 55:
| 0x22 || Master volume || 0xLR L=left volume R=right volume min=0x0 max=0xF (default value is 0xCC or 0x11)
| 0x22 || Master volume || 0xLR L=left volume R=right volume min=0x0 max=0xF (default value is 0xCC or 0x11)
|-
|-
| 0x80 || Set IRQ || 0x1=IRQ 2 0x2=IRQ 5 0x4=IRQ 7 0x8=IRQ 10 (You can read this value too, usually is IRQ 5)
| 0x80 || Set IRQ || See below
|-
|-
|}
|}


There are two modes for transfering data. First is single mode - data from buffer are played, interrupt is fired and playing is stopped. It make lower quality of sound. Second is auto mode - data from buffer are playing forever and interrupt is fired after play buffer. You should use interrupt for re-filling buffer.
There are two modes for transfering data. First is single mode - data from buffer are played, interrupt is fired and playing is stopped. It make lower quality of sound. Second is auto mode - data from buffer are playing forever and interrupt is fired after play buffer. You should use interrupt for re-filling buffer.

==Operations==

===Reseting DSP (detecting DSP)===
# Send 1 to DSP reset port
# Wait 3 microseconds
# Send 0 to DSP reset port
# Now should be in DSP read port 0xAA.
Some SB-compatible cards returned 0xAA on first check but on second check they reported their specific version.

==Setting IRQ==
# Send 0x80 to Mixer port
# Send value of your IRQ to Mixer data port
0x01=IRQ 2 0x02=IRQ 5 0x04=IRQ 7 0x08=IRQ 10 Usually is used IRQ 5.


==Playing sound==
==Playing sound==

Revision as of 15:44, 18 May 2020

This page is a work in progress.
This page may thus be incomplete. Its content may be changed in the near future.

The Sound Blaster series is a family of sound cards made by Creative. For many years they were the standard audio cards on IBM PC's.

Introduction

The Sound Blaster 16 is the successor to the Sound Blaster Pro audio card found in many older computers. It was first brought out in 1992. The main improvement over the Pro is its 16-bit digital audio sampling (hence the name). Most SB16 cards are PCI compatible, as Creative made this improvement shortly after releasing the card, upgrading from ISA.

Digital Signal Processor

The DSP built into the Sound Blaster 16 supports playing and recording audio in 8-bit and 16-bit PCM encoded samples, along with playing several other formats (ADPCM, etc.). The base I/O register address can be found using the PCI bus for PCI models, or by detecting the presence of an older ISA Sound Blaster by issuing a Get Version command to one of several common I/O port addresses (0x220, 0x240, etc.) and waiting for a response.

Port Description
0x224 Mixer port
0x225 Mixer data port
0x226 DSP Reset
0x22A DSP Read
0x22C DSP Write
0x22E DSP Read Status (Read this port to acknowledge 8-bit interrupt)
0x22F DSP 16-bit Interrupt Acknowledge (Read this port to acknowledge 16-bit interrupt) (DSP Version 4.0+ Only)
Command for DSP Write Description Output/input for command
0x40 Set time constant 8 bit value
0x41 Set Output Sample Rate high bit/low bit
0xD1 Turn speaker on
0xD3 Turn speaker off
0xD5 Stop playing data
0xE1 Get DSP version major version/minor version
Command for Mixer port Description Mixer data port
0x22 Master volume 0xLR L=left volume R=right volume min=0x0 max=0xF (default value is 0xCC or 0x11)
0x80 Set IRQ See below

There are two modes for transfering data. First is single mode - data from buffer are played, interrupt is fired and playing is stopped. It make lower quality of sound. Second is auto mode - data from buffer are playing forever and interrupt is fired after play buffer. You should use interrupt for re-filling buffer.

Operations

Reseting DSP (detecting DSP)

  1. Send 1 to DSP reset port
  2. Wait 3 microseconds
  3. Send 0 to DSP reset port
  4. Now should be in DSP read port 0xAA.

Some SB-compatible cards returned 0xAA on first check but on second check they reported their specific version.

Setting IRQ

  1. Send 0x80 to Mixer port
  2. Send value of your IRQ to Mixer data port

0x01=IRQ 2 0x02=IRQ 5 0x04=IRQ 7 0x08=IRQ 10 Usually is used IRQ 5.

Playing sound

  1. Detect DSP
  2. Load sound data to memory
  3. Program ISA DMA
  4. Set output sample rate(0x40/frequency)
  5. Write DMA transfer type to DSP(command)
  6. Write data lenght to DSP(Low byte/High byte)

Programming DMA

Port Description
0xC4 Address
0xC6 Count
0x8B Page
0xD4 Single mask
0xD6 Transfer mode
0xD8 Clear pointer

Code

  %macro OUTB 2
    mov dx, %1
    mov al, %2
    out dx, al
  %endmacro

  %macro INB 1
    mov dx, %1
    in al, dx
  %endmacro


  ;SOUND BLASTER 16 driver in real mode

  ;reset sound blaster
  OUTB 0x226, 1 ;reset port
  mov ah, 86h
  mov cx, 0x0000
  mov dx, 0xFFFF
  int 15h ;wait
  OUTB 0x226, 0 ;reset port

  ;DMA channel 1
  OUTB 0x0A, 5 ;disable channel 1 (number of channel + 0x04)
  OUTB 0x0C, 1 ;flip flop
  OUTB 0x0B, 0x49 ;transfer mode
  OUTB 0x83, 0x01 ;PAGE TRANSFER (EXAMPLE POSITION IN MEMORY 0x[01]0F04) - SET THIS VALUE FOR YOU
  OUTB 0x02, 0x04 ;POSITION LOW BIT (EXAMPLE POSITION IN MEMORY 0x010F[04]) - SET THIS VALUE FOR YOU
  OUTB 0x02, 0x0F ;POSITON HIGH BIT (EXAMPLE POSITION IN MEMORY 0x01[0F]04) - SET THIS VALUE FOR YOU
  OUTB 0x03, 0xFF ;COUNT LOW BIT (EXAMPLE 0x0FFF) - SET THIS VALUE FOR YOU
  OUTB 0x03, 0x0F ;COUNT HIGH BIT (EXAMPLE 0x0FFF) - SET THIS VALUE FOR YOU
  OUTB 0x0A, 1 ;enable channel 1

  ;program sound blaster 16
  OUTB 0x22C, 0x40 ;set time constant
  OUTB 0x22C, 165 ;10989 Hz
  OUTB 0x22C, 0xC0 ;8 bit sound
  OUTB 0x22C, 0x00 ;mono and unsigned sound data
  OUTB 0x22C, 0xFE ;COUNT LOW BIT - COUNT LENGHT-1 (EXAMPLE 0x0FFF SO 0x0FFE) - SET THIS VALUE FOR YOU
  OUTB 0x22C, 0x0F ;COUNT HIGH BIT - COUNT LENGHT-1 (EXAMPLE 0x0FFF SO 0x0FFE) - SET THIS VALUE FOR YOU

  ;now transfer start - dont forget to handle irq

See Also

External Links