home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cmsunit.zip / CMSVOICE.TXT < prev    next >
Text File  |  1992-03-26  |  20KB  |  536 lines

  1. Greetings,
  2.  
  3. Here is a first run at some documentation for the optional CMS Music chips
  4. available for the Soundblaster 1.5 and 2.0.  (Previous versions of the 
  5. Soundblaster included these CMS chips).
  6.  
  7. Please let me know if you have any problems or additions to this.  If my
  8. network administrator will ever quit having fun in redefining our internet
  9. addresses, I may actually receive the mail!
  10.  
  11. This document is done in the style of the document by Jeffrey S. Lee which
  12. documented the Adlib FM Music Chips.  Hopefully, future documents will stick
  13. to this format.
  14.  
  15. +----------------------------------------------------------------------+
  16. | Jerry Joplin  | joplin@mcode.amdahl.com | All these worlds are yours |
  17. | Sunnyvale, CA | Compu$erve: 70441,2627  | except California.         |
  18. +---------------+-------------------------+----------------------------+
  19.  
  20. -------------------------------------------------------------------------------
  21.  
  22.                       Programming the Soundblaster
  23.                             CMS Music Chips
  24.                         Version 1.0 (6 Mar 1992)
  25.  
  26.                 Copyright (c) 1991, 1992 by Jerry Joplin
  27.                         joplin@mcode.amdahl.com
  28.  
  29.  
  30.  
  31.       Format and much of the text of this document was taken from:
  32.  
  33.                   Programming the AdLib/Sound Blaster
  34.                              FM Music Chips
  35.                        Version 2.0 (24 Feb 1992)
  36.  
  37.                Copyright (c) 1991, 1992 by Jeffrey S. Lee
  38.  
  39.                             jlee@smylex.uucp
  40.  
  41.  
  42.  
  43.  
  44.                      Warranty and Copyright Policy
  45.  
  46. This document is provided on an "as-is" basis, and its author makes no
  47. warranty or representation, express or implied, with respect to its
  48. quality performance or fitness for a particular purpose.  In no event
  49. will the author of this document be liable for direct, indirect,
  50. special, incidental, or consequential damages arising out of the use or
  51. inability to use the information contained within.  Use of this document
  52. is at your own risk.
  53.  
  54. This file may be used and copied freely so long as the applicable
  55. copyright notices are retained, and no modifications are made to the
  56. text of the document.  No money shall be charged for its distribution
  57. beyond reasonable shipping, handling and duplication costs, nor shall
  58. proprietary changes be made to this document so that it cannot be
  59. distributed freely.  This document may not be included in published
  60. material or commercial packages without the written consent of its
  61. author.
  62.  
  63.  
  64.  
  65.                                 Overview
  66.  
  67. Two of the most popular sound cards for the IBM-PC, the AdLib and the
  68. Sound Blaster, suffer from a real dearth of clear documentation for
  69. programmers.  AdLib Inc. and Creative Labs, Inc. both sell developers'
  70. kits for their sound cards, but these are expensive, and (in the case of
  71. the Sound Blaster developers' kit) can be extremely cryptic.
  72.  
  73. This document is submitted to the Soundblaster Freedom Project and is
  74. intended to provide programmers with a FREE source of information about
  75. the programming of these sound cards.
  76.  
  77. The information contained in this document is a combination of
  78. information found in the Sound Blaster Software Developer's Kit, and
  79. that learned by painful experience.  This document only applies to the
  80. optional CMS Music chips available for the Sound Blaster 1.5 and 2.0.
  81. All previous versions of the Soundblaster included these CMS chips.
  82.  
  83. Please note that numbers will be given in hexadecimal, unless otherwise
  84. indicated.  If a number is written out longhand (sixteen instead of 16)
  85. it is in decimal.
  86.  
  87.  
  88.                        Chapter One - CMS Chip I/O
  89.  
  90. CMS chips provide the Sound Blaster with an additional twelve stereo
  91. voices, and four noise generators.  A programmable sound generator is
  92. used to create amplitude modulated sound on each voice.
  93.  
  94. The chips are programmed by sending data to a voice's internal registers
  95. via its two I/O ports:
  96.  
  97.     Voice 1 - Voice 6                 Voice 7 - Voice C
  98.  
  99.     02?1 (hex) - register address     02?3 (hex) - register address
  100.     02?0 (hex) - data to register     02?2 (hex) - data to register
  101.  
  102. The ports given are relative to the base I/O address.  Using the default
  103. base I/O address of 0220 (hex):
  104.  
  105.     Voice 1 - Voice 6                 Voice 7 - Voice C
  106.  
  107.     0221 (hex) - register address     0223 (hex) - register address
  108.     0220 (hex) - data to register     0222 (hex) - data to register
  109.  
  110. The CMS chips possess an array of thirty two registers; to write to a
  111. voice's particular register, send the register number (00-1F) to the
  112. address port, followed by the desired value to the data port.
  113.  
  114.  
  115.  
  116.                       Chapter Two - The Registers
  117.  
  118. The following table shows the function of each CMS chip register.
  119. Registers will be explained in detail after the table.  Registers not
  120. listed are unused.
  121.  
  122.    Address      Function
  123.    -------      ----------------------------------------------------
  124.      00         Right and Left Channel Amplitude for Voice 1/ Voice 7
  125.      01         Right and Left Channel Amplitude for Voice 2/ Voice 8
  126.      02         Right and Left Channel Amplitude for Voice 3/ Voice 9
  127.      03         Right and Left Channel Amplitude for Voice 4/ Voice A
  128.      04         Right and Left Channel Amplitude for Voice 5/ Voice B
  129.      05         Right and Left Channel Amplitude for Voice 6/ Voice C
  130.  
  131.      08         Tone Frequency for Voice 1/ Voice 7
  132.      09         Tone Frequency for Voice 2/ Voice 8
  133.      0A         Tone Frequency for Voice 3/ Voice 9
  134.      0B         Tone Frequency for Voice 4/ Voice A
  135.      0C         Tone Frequency for Voice 5/ Voice B
  136.      0D         Tone Frequency for Voice 6/ Voice C
  137.  
  138.      10         Octave for Voice 2/8, Octave for Voice 1/7
  139.      11         Octave for Voice 4/A, Octave for Voice 3/9
  140.      12         Octave for Voice 6/C, Octave for Voice 5/B
  141.  
  142.      14         Frequency enable bits
  143.      15         Noise enable bits
  144.      16         Noise frequency select bits
  145.  
  146.      1C         Frequency Reset/Sound enable
  147.  
  148.  
  149.  
  150.                        Explanations of Registers
  151.  
  152. Registers 00 through 05
  153.  
  154.         - These registers are used to set the Right and Left
  155.           channel amplitude control.  The 4 bits of amplitude
  156.           control are defined as:
  157.  
  158.           0000   minimum amplitude, off
  159.           1111   maximum amplitude
  160.  
  161.         - Register 00
  162.  
  163.              7     6     5     4     3     2     1     0
  164.           +-----+-----+-----+-----+-----+-----+-----+-----+
  165.           |right amp. Voice 1/7   | left amp. Voice 1/7   |
  166.           +-----+-----+-----+-----+-----+-----+-----+-----+
  167.  
  168.         - Register 01
  169.  
  170.              7     6     5     4     3     2     1     0
  171.           +-----+-----+-----+-----+-----+-----+-----+-----+
  172.           |right amp. Voice 2/8   | left amp. Voice 2/8   |
  173.           +-----+-----+-----+-----+-----+-----+-----+-----+
  174.  
  175.         - Register 02
  176.  
  177.              7     6     5     4     3     2     1     0
  178.           +-----+-----+-----+-----+-----+-----+-----+-----+
  179.           |right amp. Voice 3/9   | left amp. Voice 3/9   |
  180.           +-----+-----+-----+-----+-----+-----+-----+-----+
  181.  
  182.         - Register 03
  183.  
  184.              7     6     5     4     3     2     1     0
  185.           +-----+-----+-----+-----+-----+-----+-----+-----+
  186.           |right amp. Voice 4/A   | left amp. Voice 4/A   |
  187.           +-----+-----+-----+-----+-----+-----+-----+-----+
  188.  
  189.         - Register 04
  190.  
  191.              7     6     5     4     3     2     1     0
  192.           +-----+-----+-----+-----+-----+-----+-----+-----+
  193.           |right amp. Voice 5/B   | left amp. Voice 5/B   |
  194.           +-----+-----+-----+-----+-----+-----+-----+-----+
  195.  
  196.         - Register 05
  197.  
  198.              7     6     5     4     3     2     1     0
  199.           +-----+-----+-----+-----+-----+-----+-----+-----+
  200.           |right amp. Voice 6/C   | left amp. Voice 6/C   |
  201.           +-----+-----+-----+-----+-----+-----+-----+-----+
  202.  
  203.  
  204. Registers 08 through 0D
  205.  
  206.         - These registers are used to set the tone frequency.  The
  207.           frequency is combined with the octave value for the voice
  208.           to determine the frequency of the sound generated.
  209.  
  210.         - Register 08
  211.  
  212.              7     6     5     4     3     2     1     0
  213.           +-----+-----+-----+-----+-----+-----+-----+-----+
  214.           |            tone frequency Voice 1/7           |
  215.           +-----+-----+-----+-----+-----+-----+-----+-----+
  216.  
  217.         - Register 09
  218.  
  219.              7     6     5     4     3     2     1     0
  220.           +-----+-----+-----+-----+-----+-----+-----+-----+
  221.           |            tone frequency Voice 2/8           |
  222.           +-----+-----+-----+-----+-----+-----+-----+-----+
  223.  
  224.         - Register 0A
  225.  
  226.              7     6     5     4     3     2     1     0
  227.           +-----+-----+-----+-----+-----+-----+-----+-----+
  228.           |            tone frequency Voice 3/9           |
  229.           +-----+-----+-----+-----+-----+-----+-----+-----+
  230.  
  231.         - Register 0B
  232.  
  233.              7     6     5     4     3     2     1     0
  234.           +-----+-----+-----+-----+-----+-----+-----+-----+
  235.           |            tone frequency Voice 4/A           |
  236.           +-----+-----+-----+-----+-----+-----+-----+-----+
  237.  
  238.         - Register 0C
  239.  
  240.              7     6     5     4     3     2     1     0
  241.           +-----+-----+-----+-----+-----+-----+-----+-----+
  242.           |            tone frequency Voice 5/B           |
  243.           +-----+-----+-----+-----+-----+-----+-----+-----+
  244.  
  245.         - Register 0D
  246.  
  247.              7     6     5     4     3     2     1     0
  248.           +-----+-----+-----+-----+-----+-----+-----+-----+
  249.           |            tone frequency Voice 6/C           |
  250.           +-----+-----+-----+-----+-----+-----+-----+-----+
  251.  
  252.  
  253. Registers 10 through 12
  254.  
  255.         - These registers are used to set the octave value.  The 3
  256.           bits of octave control are defined as:
  257.  
  258.           000   minimum octave     (28 Hz to 55 Hz)
  259.           001                      (55 Hz to 109 Hz)
  260.           010                      (109 Hz to 218 Hz)
  261.           011                      (218 Hz to 437 Hz)
  262.           100                      (437 Hz to 875 Hz)
  263.           101                      (875 Hz to 1.75 kHz)
  264.           110                      (1.75 kHz to 3.50 kHz)
  265.           111   maximum octave     (3.50 kHz to 6.99 kHz)
  266.  
  267.           To produce a note, set the octave to a value of 0 through
  268.           7, then set the tone frequency for the desired note within
  269.           the octave.
  270.  
  271.           Note              Tone frequency value
  272.           A                        03
  273.           A#                       1F
  274.           B                        3A
  275.           C                        53
  276.           C#                       6B
  277.           D                        82
  278.           D#                       97
  279.           E                        AC
  280.           F                        BF
  281.           F#                       D1
  282.           G                        E2
  283.           G#                       F2
  284.  
  285.  
  286.         - Register 10
  287.  
  288.              7     6     5     4     3     2     1     0
  289.           +-----+-----+-----+-----+-----+-----+-----+-----+
  290.           |     |    Octave 2/8   |     |    Octave 1/7   |
  291.           +-----+-----+-----+-----+-----+-----+-----+-----+
  292.  
  293.         - Register 11
  294.  
  295.              7     6     5     4     3     2     1     0
  296.           +-----+-----+-----+-----+-----+-----+-----+-----+
  297.           |     |    Octave 4/A   |     |    Octave 3/9   |
  298.           +-----+-----+-----+-----+-----+-----+-----+-----+
  299.  
  300.         - Register 12
  301.  
  302.              7     6     5     4     3     2     1     0
  303.           +-----+-----+-----+-----+-----+-----+-----+-----+
  304.           |     |    Octave 6/C   |     |    Octave 5/B   |
  305.           +-----+-----+-----+-----+-----+-----+-----+-----+
  306.  
  307.  
  308. Register 14
  309.  
  310.         - This register contains the frequency enable bits for all
  311.           voices.  Setting the enable bit for the voice allows sound
  312.           generation for the programmed frequency.  Turning off the
  313.           bit turns the frequency off.
  314.  
  315.              7     6     5     4     3     2     1     0
  316.           +-----+-----+-----+-----+-----+-----+-----+-----+
  317.           |     |     | 6/C | 5/B | 4/A | 3/9 | 2/8 | 1/7 |
  318.           +-----+-----+-----+-----+-----+-----+-----+-----+
  319.  
  320.  
  321. Register 15
  322.  
  323.         - This register contains the noise enable bits for all voices.
  324.           Setting the enable bit for the voice allows noise generation,
  325.           turning off the bit turns noise generation off.
  326.  
  327.              7     6     5     4     3     2     1     0
  328.           +-----+-----+-----+-----+-----+-----+-----+-----+
  329.           |     |     | 6/C | 5/B | 4/A | 3/9 | 2/8 | 1/7 |
  330.           +-----+-----+-----+-----+-----+-----+-----+-----+
  331.  
  332.  
  333. Register 16
  334.  
  335.         - This register is used to set the noise generation frequency.
  336.           There are four noise generators.  Each generator is dedicated
  337.           to three voices:
  338.  
  339.           Noise generator 1, voice 1 through voice 3
  340.           Noise generator 2, voice 4 through voice 6
  341.           Noise generator 3, voice 7 through voice 9
  342.           Noise generator 4, voice A through voice C
  343.  
  344.           The 2 bits of noise generator control are defined as:
  345.  
  346.           00                       (clock frequency)
  347.           01                       (28.0 Hz)
  348.           10                       (14.0 Hz)
  349.           11                       (6.8 Hz)
  350.  
  351.              7     6     5     4     3     2     1     0
  352.           +-----+-----+-----+-----+-----+-----+-----+-----+
  353.           |     |     | gen. 2/4  |     |     | gen. 1/3  |
  354.           +-----+-----+-----+-----+-----+-----+-----+-----+
  355.  
  356. Register 1C
  357.  
  358.         - This register contains a sound enable bit for all voices and
  359.           a requency reset signal bit.
  360.  
  361.           The sound enable bit (SE) is defined as
  362.  
  363.           0                        (all channels disabled)
  364.           1                        (all channels enabled)
  365.  
  366.           The reset bit (RST) is used to send a Reset signal to all
  367.           frequency generators.
  368.  
  369.           0                        (all generators disabled)
  370.           1                        (all generators reset and synchronized)
  371.  
  372.  
  373.  
  374.                           Detecting CMS Chips
  375.  
  376. Hmmmm,  Anybody know of a good way to detect CMS Chips?
  377.  
  378.  
  379.  
  380.                              Making a Sound
  381.  
  382. The CMS chips are very easy to program.  The following code written in
  383. Turbo C provides a good start on mastering the CMS chips.  The global
  384. variable SbIOaddr should be set to the base I/O address of the Sound
  385. Blaster.
  386.  
  387.     extern unsigned SbIOaddr;
  388.  
  389.     /*****************************************************************/
  390.     /* Function to set a register to a specified value using a       */
  391.     /* given register address port.                                  */
  392.     /*****************************************************************/
  393.  
  394.     void CmsSetReg(unsigned regAddr, unsigned reg, unsigned val)
  395.     {
  396.       outportb(regAddr, reg);     /* Select the register */
  397.       regAddr--;                  /* Get data to register port */
  398.       outportb(regAddr, val);     /* Set the value of the register */
  399.     }
  400.  
  401.  
  402.     /*****************************************************************/
  403.     /* Function to initialize the Music chip by setting all internal */
  404.     /* registers to zero.                                            */
  405.     /*****************************************************************/
  406.  
  407.     void CmsInit() {
  408.       unsigned reg;
  409.       unsigned port;
  410.  
  411.       port = SbIOaddr + 1;            /* Voice 1-6 registers */
  412.       for (reg=0; reg < 0x20; reg++)  /* Loop through all registers */
  413.         CmsSetReg(port,reg,0x0);      /*  Zero the register */
  414.       CmsSetReg(port,0x1C,0x2);       /* Set the Reset bit (RST) */
  415.  
  416.       port = SbIOaddr + 3;            /* Voice 7-C registers */
  417.       for (reg=0; reg < 0x20; reg++)  /* Loop through all registers */
  418.         CmsSetReg(port,reg,0x0);      /*  Zero the register */
  419.       CmsSetReg(port,0x1C,0x2);       /* Set the Reset bit (RST) */
  420.     }
  421.  
  422.  
  423.     /*****************************************************************/
  424.     /* Function to set the left and right channel amplitudes of a    */
  425.     /* voice to specified values.                                    */
  426.     /*****************************************************************/
  427.  
  428.     void CmsSetAmp(int voice, unsigned rAmp, unsigned lAmp) {
  429.       unsigned regAddr;
  430.  
  431.       if (voice < 7)              /* Select the correct register */
  432.         regAddr = SbIOaddr + 1;   /*  address for the voice      */
  433.       else
  434.         regAddr = SbIOaddr + 3;
  435.  
  436.       /* Set the voice right and left amplitude */
  437.       CmsSetReg(regAddr, voice-1, (rAmp << 4) + lAmp);
  438.     }
  439.  
  440.  
  441.     /*****************************************************************/
  442.     /* Function to set the tone frequency for a specified voice      */
  443.     /*****************************************************************/
  444.  
  445.     void CmsSetFreq(int voice, unsigned freq) {
  446.       unsigned regAddr;
  447.  
  448.       if (voice < 7)              /* Select the correct register */
  449.         regAddr = SbIOaddr + 1;   /*  address for the voice      */
  450.       else
  451.         regAddr = SbIOaddr + 3;
  452.  
  453.       /* Set the voice tone frequency */
  454.       CmsSetReg(regAddr, 0x8 + voice-1, freq);
  455.     }
  456.  
  457.  
  458.     /*****************************************************************/
  459.     /* Function to set the octave for a specified voice              */
  460.     /*****************************************************************/
  461.  
  462.     void CmsSetOctave(int voice, unsigned octave) {
  463.       unsigned regAddr;
  464.       unsigned reg;
  465.       unsigned val;
  466.  
  467.       if (voice < 7)              /* Select the correct register */
  468.         regAddr = SbIOaddr + 1;   /*  address for the voice      */
  469.       else
  470.         regAddr = SbIOaddr + 3;
  471.  
  472.       /* Compute the register and value to send to CmsSetReg */
  473.       val = (voice & 0x1 ? octave : octave << 4);
  474.       switch (voice) {
  475.         case 1:
  476.         case 2:
  477.         case 7:
  478.         case 8:
  479.           reg = 0x10;
  480.           break;
  481.  
  482.         case 3:
  483.         case 4:
  484.         case 9:
  485.         case 10:
  486.           reg = 0x11;
  487.           break;
  488.  
  489.         case 5:
  490.         case 6:
  491.         case 11:
  492.         case 12:
  493.           reg = 0x12;
  494.           break;
  495.       }
  496.  
  497.       CmsSetReg(regAddr, reg, val);
  498.     }
  499.  
  500.  
  501.     /*****************************************************************/
  502.     /* Function to enable sound frequency for a voice.               */
  503.     /*****************************************************************/
  504.  
  505.     void CmsEnableVoice(int voice) {
  506.       unsigned regAddr;
  507.       unsigned val;
  508.  
  509.       if (voice < 7)              /* Select the correct register */
  510.         regAddr = SbIOaddr + 1;   /*  address for the voice      */
  511.       else
  512.         regAddr = SbIOaddr + 3;
  513.  
  514.       val = 0x40;                 /* Compute the value to send   */
  515.       if (voice < 7)              /* to CmsSetReg                */
  516.         val >>= 7 - voice;
  517.       else
  518.         val >>= 13 - voice;
  519.  
  520.       CmsSetReg(regAddr, 0x14, val); /* Set the voice enable bit */
  521.       CmsSetReg(regAddr, 0x1C, 0x1); /* Set the sound enable bit */
  522.     }
  523.  
  524.  
  525.                             Acknowledgements
  526.  
  527. Thanks are due to the following people:
  528.  
  529. Jeffrey S. Lee (jlee@smylex.uucp) for writing the original document
  530. on Programming the AdLib/Sound Blaster.  This is a must read for anyone
  531. trying to hack their way through the AdLib programming interface.
  532.  
  533. Mike Kretzer (tanith@csd4.csd.uwm.edu) for providing information on the
  534. availability of CMS chips on the Sound Blaster.
  535.  
  536.