1 /************************************************************************ 2 * beat.c - cheap little metronome to run in the background and use 3 * system beep so as not to tie up /dev/sequencer. 4 * 5 * This code was written by by Nathan Laredo (laredo@gnu.ai.mit.edu) 6 * Source code may be freely distributed in unmodified form. 7 *************************************************************************/ 8 #include <stdio.h> 9 #include <unistd.h> 10 #include <stdlib.h> 11 12 int main(argc, argv) 13 int argc; 14 char **argv; 15 { 16 unsigned long i, j; 17 18 if (argc != 2) { 19 fprintf(stderr, "usage: %s tempo in beats per minute\n", argv[0]); 20 exit(1); 21 } 22 i = atoi(argv[1]); 23 if (i < 48 || i > 384) { 24 fprintf(stderr, "error: tempo should be between 48 and 384 bpm\n"); 25 exit(-1); 26 } 27 j = 60000000 / i; /* get usec per beat */ 28 while (fprintf(stderr, "\7")) 29 usleep(j); 30 exit(0); 31 } 32