Advertisement
Un1XX388

beat_test.c

Jul 13th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.74 KB | None | 0 0
  1. /********************************
  2.  *  Author:     Un1XX388         *
  3.  *  Date:       7/13/2016        *
  4.  *  Purpose:    Play a beat.     *
  5.  ********************************/
  6.  
  7.   /****************************/
  8.  /**    System Include(s)   **/
  9. /****************************/
  10. #include <stdio.h>
  11. #include <time.h>
  12.  
  13.   /********************/
  14.  /**    Constant(s) **/
  15. /********************/
  16. // Beats per second (BPS)
  17. #define BPS 8
  18. // How many beats the riff lasts for.
  19. #define RIFF_LEN 48
  20.  
  21.   /****************/
  22.  /**    Main    **/
  23. /****************/
  24. int main(int argc, char *argv[]){
  25.       /***************/
  26.      /* Variable(s) */
  27.     /***************/
  28.     // Used to keep track of the beat.
  29.     struct timespec tim, tim2;
  30.     // 1/8 sec beat.
  31.     tim.tv_sec = 0, tim.tv_nsec = 1000000000L/BPS;
  32.     // Used for iteration.
  33.     int i;
  34.  
  35.     // Brief error checking.
  36.     if(argc > 1)
  37.         printf("Command line arguments not supported. Extra input ignored.\n");
  38.  
  39.     // Determines how long beat plays.
  40.     for(i=7; i<RIFF_LEN; i++){
  41.         // Each case has two print statements in order to make screen and audio output line up.
  42.         switch(i%10){
  43.             case 8:
  44.                 printf("\a\n");
  45.                 printf("1");
  46.                 break;
  47.             case 0:
  48.                 printf("\a\n");
  49.                 printf("2");
  50.                 break;
  51.             case 2:
  52.                 printf("\a\n");
  53.                 printf("3");
  54.                 break;
  55.             case 4:
  56.                 printf("\a\n");
  57.                 printf("4.1");
  58.                 break;
  59.             case 5:
  60.                 printf("\a\n");
  61.                 printf("4.2");
  62.                 break;
  63.             case 6:
  64.                 printf("\a\n");
  65.                 printf("4.3");
  66.                 break;
  67.             case 7:
  68.                 printf("\n****");
  69.                 break;
  70.             default:
  71.                 printf("...\n");
  72.         }
  73.  
  74.         // Waits for amount of time set of top of main.
  75.         nanosleep(&tim, &tim2);
  76.     }
  77.    
  78.     // My lazy way of fixing formatting problem.
  79.     printf("\n");
  80.  
  81.     return 0;                                       // Return
  82. }// End of main() function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement