Ensoniq AudioPCI

From OSDev.wiki
Revision as of 10:22, 15 December 2015 by osdev>Spydertl (Added Playing Audio section)
Jump to navigation Jump to search
This page is a work in progress.
This page may thus be incomplete. Its content may be changed in the near future.

The Ensoniq AudioPCI is a low-cost PCI sound card that notably used software to emulate a MIDI synthesizer using a proprietary wave table format. It also supported up to 48kHz PCM input and output and up to 4 channels in some configurations. It is also the only sound card model currently supported in VMWare virtual machines.

After the AudioPCI was released, Ensoniq was acquired by Creative Labs, which re-labeled the AudioPCI as the SoundBlaster PCI 64, and later the SoundBlaster PCI 128. The PCI Subclass and Revision registers can be used to detect exactly which model is installed, and each model has similar (but not identical) register sets.

I/O Registers

The following I/O mapped registers can be found by reading the BAR0 address of the Ensoniq AudioPCI device.

Offset (Hex) Description
0x00 Control
0x04 Status
0x08 UART Data
0x09 UART Status/Control
0x0a UART Test Mode
0x0c Memory Page
0x10 Sample Rate Converter
0x14 Codec Read/Write
0x18 Legacy
0x20 Serial Interface
0x24 Playback 1 Sample Count
0x28 Playback 2 Sample Count
0x2c Record Sample Count
0x30 (Page 0x0c) Playback 1 Buffer Address
0x34 (Page 0x0c) Playback 1 Buffer Definition
0x38 (Page 0x0c) Playback 2 Buffer Address
0x3c (Page 0x0c) Playback 2 Buffer Definition
0x30 (Page 0x0d) Record Buffer Address
0x34 (Page 0x0d) Record Buffer Definition
0x30 (Page 0x0e) UART FIFO Data

Playing Audio

To play PCM audio on the AudioPCI, the following registers must be configured:

  • Reset the controller by writing 0x20 to the Status register (0x04). This flag will automatically reset back to 0 when the reset is complete.
  • Reset the CODEC by writing 0xff to the Codec register (0x14). This only applies to the 1371 AC 97 model and later.
  • Program the Sample Rate Converter to the appropriate sample rate using register 0x10. The specific values needed here must be calculated. See below.
  • Set the Master Volume and PCM Out Volume levels on the CODEC. These are muted by default.
  • Set the Memory Page register (0x0c) to 0x0c. This is the only page needed for audio playback.
  • Set the Playback 2 Buffer Address register (0x38) to the physical address of your audio buffer.
  • Set the Playback 2 Buffer Definition register (0x3c) to the size of the audio buffer, in DWORDS, minus one. This gives a maximum buffer size of 256K.
  • Set the Playback 2 Sample Count register (0x28) to the number of frames to play. After the last frame is played, an IRQ will be raised.
  • Set the Serial Interface register (0x20) to 0x0020020C to enable 16-bit stereo, interrupts and looped mode on Playback 2.
  • Set the Control register (0x00) to 0x00000020 to enable the Playback 2 DAC.

At this point, the audio should begin playing. You will receive an IRQ when the last requested frame is played. However, in looped mode, the audio will continue playing, and will loop around to the start of the audio buffer when the end of the buffer is reached. By setting the Sample Count register to play half of the audio buffer, you will receive an interrupt when the first half of the buffer has been played. This will allow you to fill the first half of the buffer while the second half is being played, and vice versa. After receiving an interrupt and filling the audio buffer, you must re-enable interrupts by clearing the interrupt enable flag in the Serial Interface register, and then setting it again.