Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/drivers/sb16/sound.h need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #ifndef __SOUND_H__
0019 #define __SOUND_H__
0020 
0021 // Error costants
0022 #define SB_OK                   0       // No errors
0023 #define SB_RESET_DSP            1       // Cannot reset the SB DSP
0024 #define SB_DETECT_DSP           2       // Cannot detect the SB DSP I/O base address
0025 #define SB_NOT_INITIALIZED      3       // SB Library not initialized
0026 #define SB_INVALID_IRQ          4       // Invalid IRQ number
0027 #define SB_INVALID_DMA          5       // Invalid DMA channel settings
0028 #define SB_SAMPLE_RATE          6       // Sample rate out of range
0029 #define SB_TOO_MANY_VOICES      7       // Driver is playing too many voices
0030 #define SB_USE_STEREO           8       // Stereo mode not supported
0031 #define SB_INVALID_FILE         9       // Invalid (sound) file
0032 
0033 // Defining the offset of the SB I/O ports
0034 #define SB_DSP_RESET            0x06    // DSP Reset Port
0035 #define SB_DSP_READ_DATA        0x0A    // DSP Read Data Port
0036 #define SB_DSP_WRITE            0x0C    // DSP Write Command/Data (out)
0037 #define SB_DSP_WRITE_BUFFER_STATUS 0x0C // DSP Write Buffer Status (in)
0038 #define SB_DSP_READ_BUFFER_STATUS  0x0E // DSP Data Available
0039 
0040 #define INTERRUPT_SETUP         0x80
0041 #define DMA_SETUP               0x81
0042 
0043 // Other definitions
0044 #define SB_RESET_TIMEOUT        5000000
0045 #define SB_IRQ_DETECT_TIMEOUT   5000000
0046 #define SB_HIGH_SPEED_FREQUENCY 23 * 1024
0047 #define SB_MEMORY_SIZE          4096
0048 #define SB_MAX_VOICES           8
0049 #define WAV_CHUNK_LENGTH        12
0050 #define SB_DRIVER_VERSION_HI    0x01
0051 #define SB_DRIVER_VERSION_LO    0x05
0052 
0053 // Mixer ports and registers
0054 #define MIXER_REG_ADDR_PORT     0x04
0055 #define MIXER_DATA_PORT         0x05
0056 #define MIXER_RESET             0x00
0057 #define MIXER_OUTPUT            0x0E
0058 
0059 // Supported sound files extensions
0060 #define SB_EXTENSION_RAW        ".RAW"
0061 #define SB_EXTENSION_WAV        ".WAV"
0062 
0063 
0064 // DSP Commands
0065 #define SB_SPEAKER_ON        0xD1       // Turn Speaker on
0066 #define SB_SPEAKER_OFF       0xD3       // Turn Speaker off
0067 #define SB_DSP_VERSION       0xE1       // Gets the DSP version
0068 #define SB_DMA_MODE_8_SC     0x14       // DMA DAC, 8-bit (Single Cycle, Norm Speed)
0069 #define SB_DMA_MODE_8_AI_NS  0x1C       // Auto-Init DMA DAC, 8-bit (Normal Speed)
0070 #define SB_TIME_CONSTANT     0x40       // Set Time Constant
0071 #define SB_DMA_BLOCK_SIZE    0x48       // Set DMA Block Size
0072 #define SB_DMA_MODE_8_AI_HS  0x90       // Auto-Init DMA DAC, 8-bit (High Speed)
0073 #define SB_HALT_DMA          0xD0       // Halt DMA Operation, 8-bit
0074 #define SB_EXIT_DMA          0xDA       // Exit Auto-Init DMA Operation, 8-bit
0075 #define SB_IRQ_TRIGGER       0xF2       // Triggers SB interrupt
0076 
0077 // PIC ports addresses
0078 #define SB_PIC1_EOI          0x20       // PIC 1 EOI (End Of Interrupt)
0079 #define SB_PIC2_EOI          0xA0       // PIC 2 EOI
0080 #define SB_PIC_MASK_1        0x21       // PIC 1 port (master)
0081 #define SB_PIC_MASK_2        0xA1       // PIC 2 port (slave)
0082 
0083 // IRQ ACK ports
0084 #define SB_IRQ_ACK_8         0x0E       // ACK of the 8 bit IRQ
0085 #define SB_IRQ_ACK_16        0x0F       // ACK of the 16 bit IRQ
0086 
0087 // DMA Ports
0088 #define SB_DMA_MASK_8   0x0A    // 8-bit DMA mask register
0089 #define SB_DMA_MODE_8   0x0B    // 8-bit DMA mode register
0090 #define SB_DMA_CLEAR_8  0x0C    // 8-bit DMA clear byte ptr
0091 #define SB_DMA_MASK_16  0xD4    // 16-bit DMA mask port
0092 #define SB_DMA_MODE_16  0xD6    // 16-bit DMA mode register
0093 #define SB_DMA_CLEAR_16 0xD8    // 16-bit DMA clear byte ptr
0094 
0095 typedef struct
0096 {
0097   char riffsign[4] /*PACKED*/;  // The RIFF signature (should be 'RIFF')
0098   int length PACKED;            // The length of the data in the next chunk
0099   char wavesign[4] /*PACKED*/;  // The WAVE signature (should be 'WAVE')
0100   char ftmsign[4] /*PACKED*/;   // Contains the characters 'fmt'
0101   int formatlength PACKED;      // Length of the data in the format chunk
0102   uint16 waveformat PACKED;     // Wave Format
0103   uint16 channels PACKED;       // Number of channels (1=mono, 2=stereo)
0104   uint16 samplespersec PACKED;  // Playback Frequency
0105   uint16 averagebytes PACKED;   // average number of bytes a second
0106   uint16 blockalign PACKED;     // block alignment of the data
0107   uint16 formatspecific PACKED; // Format specific data area
0108 } WAVCHUNK;
0109 
0110 typedef struct
0111 {
0112   char sign[4] /*PACKED*/;      // Contains the characters 'data'
0113   int length PACKED;            // Data length
0114 } DATACHUNK;
0115 
0116 
0117 typedef struct
0118 {
0119   uint16 min_mono_8;            // Min mono sample for 8 bits
0120   uint16 max_mono_8;            // Max mono sample for 8 bits
0121   uint16 min_stereo_8;          // Min stereo sample for 8 bits
0122   uint16 max_stereo_8;          // Max stereo sample for 8 bits
0123   uint16 min_mono_16;           // Min mono sample for 16 bits
0124   uint16 max_mono_16;           // Max mono sample for 16 bits
0125   uint16 min_stereo_16;         // Min stereo sample for 16 bits
0126   uint16 max_stereo_16;         // Max stereo sample for 16 bits
0127   bool auto_dma;                // Can use auto dma
0128   bool stereo;                  // Can use stereo mode
0129   bool _16_bit;                 // Can use 16-bit
0130 } SB_CAPABILITY;
0131 
0132 // Capabilities of the Sound Blaster cards
0133 // Sound Blaster 1.0/1.5: no A/I DMA, no High Speed, no stereo
0134 PRIVATE SB_CAPABILITY capability_sb_10 = {
0135 min_mono_8:4000,
0136 max_mono_8:22222,
0137 min_stereo_8:0,
0138 max_stereo_8:0,
0139 min_mono_16:0,
0140 max_mono_16:0,
0141 min_stereo_16:0,
0142 max_stereo_16:0,
0143 auto_dma:FALSE,
0144 stereo:FALSE,
0145 _16_bit:FALSE
0146 };
0147 
0148 // Sound Blaster 2.0: support A/I DMA, High Speed. No stereo
0149 PRIVATE SB_CAPABILITY capability_sb_20 = {
0150 min_mono_8:4000,
0151 max_mono_8:45454,
0152 min_stereo_8:0,
0153 max_stereo_8:0,
0154 min_mono_16:0,
0155 max_mono_16:0,
0156 min_stereo_16:0,
0157 max_stereo_16:0,
0158 auto_dma:TRUE,
0159 stereo:FALSE,
0160 _16_bit:FALSE
0161 };
0162 
0163 // Sound Blaster Pro: support A/I DMA, High Speed, Stereo
0164 PRIVATE SB_CAPABILITY capability_sb_pro = {
0165 min_mono_8:4000,
0166 max_mono_8:45454,
0167 min_stereo_8:4000,
0168 max_stereo_8:22727,
0169 min_mono_16:0,
0170 max_mono_16:0,
0171 min_stereo_16:0,
0172 max_stereo_16:0,
0173 auto_dma:TRUE,
0174 stereo:TRUE,
0175 _16_bit:FALSE
0176 };
0177 
0178 // Sound Blaster 16: support A/I DMA, High Speed, Stereo, 16 bit
0179 PRIVATE SB_CAPABILITY capability_sb_16 = {
0180 min_mono_8:4000,
0181 max_mono_8:45454,
0182 min_stereo_8:4000,
0183 max_stereo_8:45454,
0184 min_mono_16:4000,
0185 max_mono_16:45454,
0186 min_stereo_16:4000,
0187 max_stereo_16:45454,
0188 auto_dma:TRUE,
0189 stereo:TRUE,
0190 _16_bit:TRUE
0191 };
0192 
0193 // Sound Blaster AWE32: support A/I DMA, High Speed, Stereo, 16 bit
0194 PRIVATE SB_CAPABILITY capability_sb_awe32 = {
0195 min_mono_8:5000,
0196 max_mono_8:45454,
0197 min_stereo_8:5000,
0198 max_stereo_8:45454,
0199 min_mono_16:5000,
0200 max_mono_16:45454,
0201 min_stereo_16:5000,
0202 max_stereo_16:45454,
0203 auto_dma:TRUE,
0204 stereo:TRUE,
0205 _16_bit:TRUE
0206 };
0207 
0208 #define SAMPLE_uint8     uint8
0209 #define SAMPLE_CLIP_MIN 0
0210 #define SAMPLE_CLIP_MAX 255
0211 
0212 typedef struct
0213 {
0214   int size;                     // Size of the sound data
0215   SAMPLE_uint8 *data;           // Data memory area
0216   bool stereo;                  // Mono or stereo sample data
0217 } SAMPLE;
0218 
0219 bool sb_dsp_reset (uint16 base_address);
0220 bool sb_dsp_write (uint8 value);
0221 bool sb_dsp_read (uint8 * value);
0222 bool sb_speaker_on (void);
0223 bool sb_speaker_off (void);
0224 bool sb_dsp_get_version (uint16 * version);
0225 bool sb_get_model_name (char *name);
0226 bool sb_dsp_detect_base_address (uint16 * base_address);
0227 bool sb_dsp_detect_irq_number (uint16 base_address, uint8 * irq_number);
0228 bool sb_dsp_detect_dma (uint16 base_address, uint8 * dma8, uint8 * dma16);
0229 bool sb_play_sample (SAMPLE * sample);
0230 bool sb_mixer_register_set (uint8 index, uint8 value);
0231 bool sb_mixer_register_get (uint8 index, uint8 * value);
0232 bool sb_install_driver (uint16 frequency, bool use_stereo);
0233 // bool sb_read_raw (char *filename, SAMPLE *sample);
0234 #endif
0235 
0236 /* 
0237  * Local Variables:
0238  * indent-tabs-mode: nil
0239  * mode: C
0240  * c-file-style: "gnu"
0241  * c-basic-offset: 2
0242  * End: 
0243  */
0244 
0245 /* vi: set et sw=2 sts=2: */