mirror of
https://github.com/ssb22/midi-beeper.git
synced 2023-05-28 08:03:23 +00:00
141 lines
4.9 KiB
Diff
141 lines
4.9 KiB
Diff
--- /home/silasbrown/Downloads/beep(1).c 2021-04-02 09:46:29.695286944 +0100
|
|
+++ beep.c 2021-04-02 09:14:11.486246016 +0100
|
|
@@ -1,3 +1,5 @@
|
|
+/* Modified by ssb22 for NSLU2 / Debian 5 */
|
|
+
|
|
/* beep - just what it sounds like, makes the console beep - but with
|
|
* precision control. See the man page for details.
|
|
*
|
|
@@ -13,7 +15,8 @@
|
|
* warranties of merchantability or fitness for a particular use or ability to
|
|
* breed pandas in captivity, it just can't be done.
|
|
*
|
|
- * Bug me, I like it: http://johnath.com/ or johnath@johnath.com
|
|
+ * Original author's contact: http://johnath.com/ or johnath@johnath.com
|
|
+ * but note that this version was modified for NSLU2 / Debian 5
|
|
*/
|
|
|
|
#include <fcntl.h>
|
|
@@ -44,7 +47,11 @@
|
|
result of this is a tone at approximately the desired frequency. :)
|
|
*/
|
|
#ifndef CLOCK_TICK_RATE
|
|
-#define CLOCK_TICK_RATE 1193180
|
|
+//#define CLOCK_TICK_RATE 1193180
|
|
+#define CLOCK_TICK_RATE 64000000 // nslu2
|
|
+/* (SSB: do the NSLU2 alteration HERE, not
|
|
+ * by opening an event device, because that
|
|
+ * introduces extra delays in Debian 5) */
|
|
#endif
|
|
|
|
#define VERSION_STRING "beep-1.2.2"
|
|
@@ -110,7 +117,7 @@
|
|
/* print usage and exit */
|
|
void usage_bail(const char *executable_name) {
|
|
printf("Usage:\n%s [-f freq] [-l length] [-r reps] [-d delay] "
|
|
- "[-D delay] [-s] [-c]\n",
|
|
+ "[-D delay] [-s] [-c] [-e device (ignored)]\n",
|
|
executable_name);
|
|
printf("%s [Options...] [-n] [--new] [Options...] ... \n", executable_name);
|
|
printf("%s [-h] [--help]\n", executable_name);
|
|
@@ -145,7 +152,7 @@
|
|
{"version", 0, NULL, 'V'},
|
|
{"new", 0, NULL, 'n'},
|
|
{0,0,0,0}};
|
|
- while((c = getopt_long(argc, argv, "f:l:r:d:D:schvVn", opt_list, NULL))
|
|
+ while((c = getopt_long(argc, argv, "f:l:r:d:D:schvVne:", opt_list, NULL))
|
|
!= EOF) {
|
|
int argval = -1; /* handle parsed numbers for various arguments */
|
|
float argfreq = -1;
|
|
@@ -197,8 +204,10 @@
|
|
exit(0);
|
|
break;
|
|
case 'n' : /* also --new - create another beep */
|
|
+ if (result->freq == 0)
|
|
+ result->freq = DEFAULT_FREQ;
|
|
result->next = (beep_parms_t *)malloc(sizeof(beep_parms_t));
|
|
- result->next->freq = DEFAULT_FREQ;
|
|
+ result->next->freq = 0;
|
|
result->next->length = DEFAULT_LENGTH;
|
|
result->next->reps = DEFAULT_REPS;
|
|
result->next->delay = DEFAULT_DELAY;
|
|
@@ -207,26 +216,20 @@
|
|
result->next->next = NULL;
|
|
result = result->next; /* yes, I meant to do that. */
|
|
break;
|
|
+ case 'e' : /* also --device */
|
|
+ break;
|
|
case 'h' : /* notice that this is also --help */
|
|
default :
|
|
usage_bail(argv[0]);
|
|
}
|
|
}
|
|
+ if (result->freq == 0)
|
|
+ result->freq = DEFAULT_FREQ;
|
|
}
|
|
|
|
void play_beep(beep_parms_t parms) {
|
|
int i; /* loop counter */
|
|
|
|
- /* try to snag the console */
|
|
- if((console_fd = open("/dev/tty0", O_WRONLY)) == -1) {
|
|
- if((console_fd = open("/dev/vc/0", O_WRONLY)) == -1) {
|
|
- fprintf(stderr, "Could not open /dev/tty0 or /dev/vc/0 for writing.\n");
|
|
- printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
|
|
- perror("open");
|
|
- exit(1);
|
|
- }
|
|
- }
|
|
-
|
|
/* Beep */
|
|
for (i = 0; i < parms.reps; i++) { /* start beep */
|
|
if(ioctl(console_fd, KIOCSOUND, (int)(CLOCK_TICK_RATE/parms.freq)) < 0) {
|
|
@@ -236,20 +239,16 @@
|
|
/* Look ma, I'm not ansi C compatible! */
|
|
usleep(1000*parms.length); /* wait... */
|
|
ioctl(console_fd, KIOCSOUND, 0); /* stop beep */
|
|
- if(parms.end_delay || (i+1 < parms.reps))
|
|
+ if((parms.end_delay || (i+1 < parms.reps)) && /*parms.delay*/ 1)
|
|
usleep(1000*parms.delay); /* wait... */
|
|
} /* repeat. */
|
|
-
|
|
- close(console_fd);
|
|
}
|
|
|
|
-
|
|
-
|
|
int main(int argc, char **argv) {
|
|
char sin[4096], *ptr;
|
|
|
|
beep_parms_t *parms = (beep_parms_t *)malloc(sizeof(beep_parms_t));
|
|
- parms->freq = DEFAULT_FREQ;
|
|
+ parms->freq = 0;
|
|
parms->length = DEFAULT_LENGTH;
|
|
parms->reps = DEFAULT_REPS;
|
|
parms->delay = DEFAULT_DELAY;
|
|
@@ -260,6 +259,17 @@
|
|
signal(SIGINT, handle_signal);
|
|
parse_command_line(argc, argv, parms);
|
|
|
|
+
|
|
+ /* try to snag the console */
|
|
+ /* (SSB: do this at TOP level, NOT on every beep
|
|
+ * which may increase the probability of NSLU2 crash) */
|
|
+ if((console_fd = open("/dev/tty0", O_WRONLY)) == -1) {
|
|
+ fprintf(stderr, "Could not open console device for writing.\n");
|
|
+ printf("\a"); /* Output the only beep we can, in an effort to fall back on usefulness */
|
|
+ perror("open");
|
|
+ exit(1);
|
|
+ }
|
|
+
|
|
/* this outermost while loop handles the possibility that -n/--new has been
|
|
used, i.e. that we have multiple beeps specified. Each iteration will
|
|
play, then free() one parms instance. */
|
|
@@ -297,5 +307,6 @@
|
|
parms = next;
|
|
}
|
|
|
|
+ close(console_fd);
|
|
return EXIT_SUCCESS;
|
|
}
|