home *** CD-ROM | disk | FTP | other *** search
/ Dave Lowe: The Developer …nd Blaster Series Disk 1 / Lowe_TheDeveloperKitForSoundBlasterSeriesDisk1.img / C / MSC / MUSIC / DEMOFM.C < prev   
Encoding:
C/C++ Source or Header  |  1991-11-27  |  5.3 KB  |  134 lines

  1. /* ------------------------------------------------------------------------ */
  2. /*  @@ Source Documentation                        *** MSC/TC Version ***   */
  3. /*                                                                          */
  4. /*  Copyright (c) Creative Technology Pte Ltd, 1991. All rights reserved.   */
  5. /*                                                                          */
  6. /*   TITLE       : DEMOFM.C                                                 */
  7. /*                                                                          */
  8. /*   DESCRIPTION :                                                          */
  9. /*       This program demonstrates how to call the SBFM low level functions */
  10. /*       to play a 'C major scale' using each of the 10 instruments         */
  11. /*       defined.                                                           */
  12. /*                                                                          */
  13. /*       The program is responsible for the timing between notes.           */
  14. /*                                                                          */
  15. /*       The program checks the BLASTER environment for the Card settings.  */
  16. /*       It also performs a test based on the BLASTER environment settings  */
  17. /*       to ensure they tally with the hardware settings on the Card.       */
  18. /*                                                                          */
  19. /* ------------------------------------------------------------------------ */
  20.  
  21. #include <sbc.h>
  22. #include <stdio.h>
  23. #include <sbcmusic.h>
  24. #include <bios.h>
  25.  
  26.  
  27. /* instrument table */
  28. char      inst[128][16] =
  29.     {
  30.            /* instrument1 */
  31.         {   0x021,0x011,0x04C,0x000,0x0F1,0x0F2,0x063,0x072,
  32.             0x000,0x000,0x004,0x000,0x000,0x000,0x000,0x000 },
  33.  
  34.         {   0x0A5,0x0B1,0x0D2,0x080,0x081,0x0F1,0x003,0x005,
  35.             0x000,0x000,0x002,0x000,0x000,0x000,0x000,0x000 },
  36.  
  37.         {   0x072,0x062,0x01C,0x005,0x051,0x052,0x003,0x013,
  38.             0x000,0x000,0x00E,0x000,0x000,0x000,0x000,0x000 },
  39.  
  40.         {   0x011,0x001,0x08A,0x040,0x0F1,0x0F1,0x011,0x0B3,
  41.             0x000,0x000,0x006,0x000,0x000,0x000,0x000,0x000 },
  42.  
  43.         {   0x021,0x011,0x011,0x000,0x0A3,0x0C4,0x043,0x022,
  44.             0x002,0x000,0x00D,0x000,0x000,0x000,0x000,0x000 },
  45.  
  46.            /* instrument6 */
  47.         {   0x031,0x0A1,0x01C,0x080,0x041,0x092,0x00B,0x03B,
  48.             0x000,0x000,0x00E,0x000,0x000,0x000,0x000,0x000 },
  49.  
  50.         {   0x071,0x062,0x0C5,0x005,0x06E,0x08B,0x017,0x00E,
  51.             0x000,0x000,0x002,0x000,0x000,0x000,0x000,0x000 },
  52.  
  53.         {   0x041,0x091,0x083,0x000,0x065,0x032,0x005,0x074,
  54.             0x000,0x000,0x00A,0x000,0x000,0x000,0x000,0x000 },
  55.  
  56.         {   0x032,0x016,0x087,0x080,0x0A1,0x07D,0x010,0x033,
  57.             0x000,0x000,0x008,0x000,0x000,0x000,0x000,0x000 },
  58.  
  59.         {   0x001,0x013,0x08D,0x000,0x051,0x052,0x053,0x07C,
  60.             0x001,0x000,0x00C,0x000,0x000,0x000,0x000,0x000 }
  61.     } ;
  62.  
  63.       /* Only first 10 instruments are defined here */
  64.  
  65.  
  66. main ()
  67. {
  68.     /* Retrieve the BLASTER environment settings */
  69.     if ( ! GetEnvSetting() )
  70.     {
  71.         if (sbc_check_card() & 2)
  72.         {
  73.             sbfd_init () ;
  74.  
  75.             sbfd_instrument ( (char far *) inst ) ;
  76.  
  77.             PlayScale () ;
  78.  
  79.             sbfd_reset () ;
  80.         }
  81.         else
  82.             printf("FM music not available or wrong I/O settings.\n") ;
  83.     }
  84.     else
  85.         printf("BLASTER environment not set or incomplete or invalid.\n");
  86.  
  87. }
  88.  
  89.  
  90. /* ------------------------------------------------------------------------ */
  91. /*  @@ Usage                                                                */
  92. /*                                                                          */
  93. /*   PlayScale (void)                                                       */
  94. /*                                                                          */
  95. /*   DESCRIPTION:                                                           */
  96. /*       Play a 'major scale' for each of the 10 instruments defined.       */
  97. /*                                                                          */
  98. /*   ENTRY:                                                                 */
  99. /*       None                                                               */
  100. /*                                                                          */
  101. /*   EXIT:                                                                  */
  102. /*       None                                                               */
  103. /*                                                                          */
  104. /* ------------------------------------------------------------------------ */
  105.  
  106. #pragma loop_opt(off)
  107. PlayScale (void)
  108. {
  109.     unsigned int   i, j ;
  110.     int        inst ;
  111.     int        note ;
  112.  
  113.  
  114.     /* Look up table for the MIDI value of a 'scale' that starts from 'middle C' */
  115.     static char     note_num[] = { 60, 62, 64, 65, 67, 69, 71, 72 } ;
  116.  
  117.     for ( inst= 0; inst < 10; inst++ )
  118.     {
  119.         sbfd_program_change ( 0, (char)inst ) ;
  120.  
  121.         for ( note=0; note < 8; note++ )
  122.         {
  123.             sbfd_note_on ( 0, note_num[note], 0x40 ) ;
  124.  
  125.             /* delay between notes */
  126.             for (i=0; i<100; i++)
  127.                 for (j=0; j < 1000; j++) ;
  128.  
  129.             sbfd_note_off ( 0, note_num[note], 0x40 ) ;
  130.         }
  131.     }
  132. }
  133. #pragma loop_opt()
  134.