home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.2 / Audio / RELEASE.3 / au2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.9 KB  |  252 lines

  1. /* auToolDemo1.c */
  2.  
  3. /* #define DEBUG 1 */
  4.  
  5. #include "types.h"
  6. #include "memory.h"
  7. #include "audio.h"
  8. #include "vdk:atools.c"
  9.  
  10.  
  11. /* 32 samples shown here... sample rate is 9956 samples per second. */
  12.  
  13. WORD tap[] = {
  14.     87,27,226,21,247,60,34,194,7,25,2,41,6,213,
  15.     41,63,12,236,27,251,44,23,-1,+1,-1,+1,
  16.     -1,+1,-1,+1,-1,+1
  17. };
  18.  
  19. char *ramtap;
  20.  
  21. WORD song[] = {
  22.     24, 200, 32,
  23.     17, 400, 32,
  24.     1,  400,  0,
  25.     19, 200, 32,
  26.     21, 400, 32,
  27.     1,  400,  0,
  28.     17, 200, 32,
  29.     19, 200, 32,
  30.     21, 200, 32,
  31.     19, 200, 32,
  32.     18, 200, 32,
  33.     19, 200, 32,
  34.     24, 400, 32,
  35.     1,  600,  0,
  36.     24, 200, 32,
  37.     17, 400, 32,
  38.     19, 200, 32,
  39.     21, 400, 32,
  40.      1, 600,  0,
  41.     17, 200, 32,
  42.     19, 200, 32,
  43.     21, 200, 32,
  44.     19, 200, 32,
  45.     18, 200, 32,
  46.     19, 200, 32,
  47.     24, 400, 32,
  48.      1, 600,  0,
  49.     
  50.     26, 200, 32,
  51.     24, 400, 32,
  52.     1,  400,  0,
  53.     26, 200, 32,
  54.     23, 400, 32,
  55.     1,  400,  0,
  56.     26, 200, 32,
  57.     22, 400, 32,
  58.     1,  400,  0,
  59.     26, 200, 32,
  60.     21, 400, 32,
  61.      1, 600,  0,
  62.     
  63.     14, 200, 32,
  64.     19, 200, 32,
  65.     21, 200, 32,
  66.     19, 200, 32,
  67.     17, 200, 32,
  68.     14, 200, 32,
  69.     19, 200, 32,
  70.     21, 200, 32,
  71.     19, 200, 32,
  72.     17, 200, 32,
  73.     14, 200, 32,
  74.     19, 600, 32,
  75.     24, 400, 32,
  76.      1, 400,  0,
  77.  
  78.     24, 200, 32,
  79.     17, 400, 32,
  80.     1,  400,  0,
  81.     19, 200, 32,
  82.     21, 400, 32,
  83.     1,  400,  0,
  84.     17, 200, 32,
  85.     19, 200, 32,
  86.     21, 200, 32,
  87.     19, 200, 32,
  88.     18, 200, 32,
  89.     19, 200, 32,
  90.     24, 400, 32,
  91.     1,  600,  0,
  92.     24, 200, 32,
  93.     17, 400, 32,
  94.     19, 200, 32,
  95.     21, 400, 32,
  96.      1, 600,  0,
  97.     17, 200, 32,
  98.     19, 200, 32,
  99.     21, 200, 32,
  100.     19, 200, 32,
  101.     18, 200, 32,
  102.     19, 200, 32,
  103.     24, 400, 32,
  104.      1, 600,  0,
  105.     
  106.     26, 200, 32,
  107.     24, 400, 32,
  108.     1,  400,  0,
  109.     26, 200, 32,
  110.     23, 400, 32,
  111.     1,  400,  0,
  112.     26, 200, 32,
  113.     22, 400, 32,
  114.     1,  400,  0,
  115.     26, 200, 32,
  116.     21, 400, 32,
  117.      1, 600,  0,
  118.     
  119.     14, 200, 32,
  120.     19, 200, 32,
  121.     21, 200, 32,
  122.     19, 200, 32,
  123.     17, 200, 32,
  124.     14, 200, 32,
  125.     19, 200, 32,
  126.     21, 200, 32,
  127.     19, 200, 32,
  128.     17, 200, 32,
  129.     14, 200, 32,
  130.     19, 600, 32,
  131.     17, 200, 32,
  132.     99 };
  133.  
  134. main()
  135. {
  136.    LONG i,j,k, channel, offset, error;
  137.    LONG mynote;
  138.  
  139.    struct MsgPort *myport;   /* CHANGE from article */
  140.    char *tapcopy;
  141.  
  142.    myport = InitAudio();   /* now returns address of message port */
  143.    if(myport == 0) 
  144.    {
  145.     printf("Problem in InitAudio!");
  146.     FinishAudio(myport);
  147.     exit(20);
  148.    }
  149.  
  150.    ramtap = (char *)AllocMem(32, MEMF_CHIP);
  151.    if (ramtap == NULL)
  152.    {
  153.     /* SAMPLED SOUND must be in chip ram. */
  154.  
  155.     printf("No chip mem for tap sound!");
  156.     FinishAudio(myport);
  157.     exit(20);
  158.    }
  159.  
  160.    /* copy the tap sound to chip ram. */
  161.  
  162.    tapcopy = ramtap;
  163.    for(i=0; i<32; i++);
  164.    {
  165.     *tapcopy = tap[i];
  166.     tapcopy++;
  167.    }
  168.  
  169.    for(i=0; i<4; i++) 
  170.    {   
  171.       channel = GetChannel(-1);
  172.       if(channel == -1)
  173.       {
  174.        printf("cannot get a channel!\n");
  175.        FinishAudio(myport);
  176.          exit(20);
  177.       }
  178.    }
  179.  
  180.    offset = 0;    /* for tuning the song */
  181.  
  182.    /* song array has notenum, duration, volume times number of songs */
  183.  
  184. /* KEVIN - here is the main music loop...
  185.  *         channel 0 gets one tap sound per note in
  186.  *         the song[] array.
  187.  *         channel 1 gets the song note number, duration, and volume.
  188.  *
  189.  * To sync your graphics to the notes, simply insert a call to draw
  190.  * your next image immediately before the call to MayGetNote, since
  191.  * this puts THIS loop to sleep until the note stops playing.
  192.  */
  193.  
  194.  
  195.    i=0;
  196.    for(;;)
  197.    {
  198.    /*  (channel, note, waveform, vol, duration, priority,messageport, id) */
  199.  
  200.       if(song[i] == 99) 
  201.       {
  202.     PlayNote(1, (long)0, w2, 0, 1, 0, myport, 99 );
  203.     break;
  204.       }
  205.  
  206.       j = i+2;  k = i+1;
  207.  
  208.       error = PlaySamp(0, 357, ramtap, 62, 1, 0, 0, 0, 32);
  209.  
  210.       error = PlayNote(1, (long)(offset + song[i]), 
  211.         w2,  (long)song[j], (long)song[k], (long)0, myport, (long)0);
  212.  
  213.       /* The above two calls QUEUE up a note for each channel independently.
  214.        * The call to PlaySamp is written to be an independent queue.  
  215.        * It returns nothing.
  216.        * 
  217.        * The call to PlayNote includes the "myport" parameter to guarantee
  218.        * that there will be something there for MayGetNote to wait for.
  219.        * When the associated parameter below is FALSE, it does NOT sleep.
  220.        * Since is it true, it sleeps waiting for a note and returns the
  221.        * identifier (id) value.  I don't care what value, just want to sleep.
  222.        */
  223.  
  224.       /* INSERT call to DoNextGraphics() HERE */
  225.  
  226.       mynote = MayGetNote(myport, TRUE);  /* GO TO SLEEP, 
  227.                        wait for note to BEGIN to play */
  228.  
  229.       /* OR ... INSERT call to DoNextGraphics() HERE, whichever works best */
  230.         
  231.       i = i+3;
  232.    }
  233.  
  234.    mynote = MayGetNote(myport, TRUE);  /* YES, wait for it to begin to play! */
  235.  
  236.  
  237.    FinishAudio(myport);   /* NEW parameter for FinishAudio */
  238.  
  239.    if(ramtap) FreeMem(ramtap, 32);
  240.  
  241.    return(0);
  242. }         /* end of main() */
  243.  
  244. /* NOTE - memory allocation for audiotools checked ok last time.  Not
  245.  * checked this time but SHOULD exit cleanly as per BADGE rules.  Hope
  246.  * you have good luck with it.   Regards,  Rob Peck.
  247.  *
  248.  * P.S. You may want to adjust the timing on the notes a little bit;
  249.  * can't help the sour one in the middle, don't know how to fix it.
  250.  * If more time, can certainly find a way.  
  251.  */
  252.