Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************
- * Author: Un1XX388 *
- * Date: 7/13/2016 *
- * Purpose: Play a beat. *
- ********************************/
- /****************************/
- /** System Include(s) **/
- /****************************/
- #include <stdio.h>
- #include <time.h>
- /********************/
- /** Constant(s) **/
- /********************/
- // Beats per second (BPS)
- #define BPS 8
- // How many beats the riff lasts for.
- #define RIFF_LEN 48
- /****************/
- /** Main **/
- /****************/
- int main(int argc, char *argv[]){
- /***************/
- /* Variable(s) */
- /***************/
- // Used to keep track of the beat.
- struct timespec tim, tim2;
- // 1/8 sec beat.
- tim.tv_sec = 0, tim.tv_nsec = 1000000000L/BPS;
- // Used for iteration.
- int i;
- // Brief error checking.
- if(argc > 1)
- printf("Command line arguments not supported. Extra input ignored.\n");
- // Determines how long beat plays.
- for(i=7; i<RIFF_LEN; i++){
- // Each case has two print statements in order to make screen and audio output line up.
- switch(i%10){
- case 8:
- printf("\a\n");
- printf("1");
- break;
- case 0:
- printf("\a\n");
- printf("2");
- break;
- case 2:
- printf("\a\n");
- printf("3");
- break;
- case 4:
- printf("\a\n");
- printf("4.1");
- break;
- case 5:
- printf("\a\n");
- printf("4.2");
- break;
- case 6:
- printf("\a\n");
- printf("4.3");
- break;
- case 7:
- printf("\n****");
- break;
- default:
- printf("...\n");
- }
- // Waits for amount of time set of top of main.
- nanosleep(&tim, &tim2);
- }
- // My lazy way of fixing formatting problem.
- printf("\n");
- return 0; // Return
- }// End of main() function.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement