home *** CD-ROM | disk | FTP | other *** search
/ Audio Version 4.94 / audioversion4.94knowledgemediaresourcelibraryoctober1994.iso / amiga / utils / atools / audiodem.c < prev    next >
C/C++ Source or Header  |  1988-03-23  |  3KB  |  110 lines

  1. /* auDEMO.C  */
  2.  
  3. #define DEBUG 1 
  4.  
  5. #include "exec/types.h" 
  6. #include "exec/memory.h" 
  7. #include "devices/audio.h" 
  8. #include "ram:audiotools2.c" 
  9.  
  10. main() 
  11.    LONG i, channel, error, note; 
  12.  
  13.    struct MsgPort *myport;   /* CHANGE from article */ 
  14.  
  15.    myport = InitAudio();   /* now returns address of message port */ 
  16.    if(myport == 0)  
  17.    { 
  18.         printf("Problem in InitAudio!"); 
  19.         FinishAudio(myport); 
  20.    } 
  21.    for(i=0; i<4; i++)  
  22.    {    
  23.       channel = GetChannel(-1); 
  24.       if(channel == -1) 
  25.       { 
  26.            printf("cannot get a channel!\n"); 
  27.            FinishAudio(myport); 
  28.       } 
  29.  
  30.       error = StopChannel(channel); 
  31.       if(error)  
  32.       {   
  33.          printf("error in stopping channel = %ld\n",error); 
  34.          FinishAudio(myport); 
  35.       } 
  36.    } 
  37.    /*  (channel, note, waveform, vol, duration, priority,messageport, id) */ 
  38.  
  39.    for(i=0; i<49; i++) 
  40.    { 
  41.       /* frequency of "zero" is not useful */ 
  42.  
  43.       PlayFreq(0, (i+1)*10, w1, 32, 125, 0, 0, 0); /* all notes, 1/8 sec. */ 
  44.       PlayNote(1, 95-i,     w2, 32, 125, 0, 0, 0);  
  45.    } 
  46.  
  47.    /* SMACK IN THE MIDDLE HERE, INSTALL TEST OF MESSAGING */ 
  48.    /* cause it to flash the screen when this note begins to play */ 
  49.    /* Make the note distinctive so we can tell for sure */ 
  50.  
  51.    PlayNote(1, 3,           w3, 63, 500, 0, myport, 3);  /* very LOUD and low */ 
  52.     
  53.    for(i=50; i<95; i++) 
  54.    { 
  55.       PlayFreq(0, (i+1)*10, w1, 32, 125, 0, 0, 0); /* all notes, 1/8 sec. */ 
  56.       PlayNote(1, 95-i,     w2, 32, 125, 0, 0, 0);  
  57.    } 
  58.  
  59.    for(i=0; i<4; i++) 
  60.    {    
  61.         error = StartChannel(i); 
  62.         if(error)   
  63.         { 
  64.                 printf("error starting channel = %ld\n",error); 
  65.                 FinishAudio(myport); 
  66.         }
  67.  
  68.    } 
  69.  
  70.    /* Now SLEEP while waiting for that note to play */ 
  71.  
  72.    printf("Going to sleep now - the prioritized note will wake me up\n"); 
  73.  
  74.    note = MayGetNote(myport, TRUE);     /* FALSE means don't sleep */ 
  75.  
  76.    printf("\n\n\n****************************************************\n"); 
  77.    printf("Hey!  Note I identified as: %ld just started to play\n",note); 
  78.    printf("\n****************************************************\n\n\n"); 
  79.  
  80.    /* When we hit the PlayNote, it calls GetIOB, which in turn 
  81.     * begins to remove iob's from the reply port, freeing them 
  82.     * for future use.  You might consider changing the ReEmployIOB 
  83.     * routine to simply free 1 or 10 or whatever number, just so  
  84.     * you could begin to play another note before ALL of the already 
  85.     * played note's iob's had been freed.  But when DEBUG is turned 
  86.     * off, the freeing goes a lot faster. 
  87.     */ 
  88.  
  89.    Delay(250);  /* waits 5 seconds so that all of these synchronize */ 
  90.  
  91.    PlayNote(0, 23, w1, 32, 2000, 0, 0); 
  92.    PlayNote(1, 27, w2, 32, 2300, 0, 0); 
  93.    PlayNote(2, 30, w3, 32, 2600, 0, 0); 
  94.    PlayNote(3, 35, w1, 32, 2900, 0, 0); 
  95.  
  96.    Delay(150);  /* Waits 3 seconds after letting the last note begin 
  97.                  * (because last note is 2900/1000ths long). 
  98.                  * If you take out this delay, you'll see that 
  99.                  * FinishAudio means FINISH AUDIO... it cuts off 
  100.                  * the notes right in the middle if necessary! 
  101.                  */ 
  102.    FinishAudio(myport);   /* NEW parameter for FinishAudio */ 
  103.  
  104.    printf("Done!\n"); 
  105.    return(0); 
  106. }         /* end of main() */ 
  107.  
  108.  
  109.